#include "japi/draw.h" #include "japi/game.h" #include "japi/font.h" #include "menu.h" #include "toolbar.h" #include "treeview.h" #include "propertygrid.h" #include "tilemap.h" #include "fkYAML/node.hpp" #include #include #include "aux.h" namespace fs = std::filesystem; bool loop(); std::map rooms; fkyaml::node room; std::string current_room = ""; void loadRoom(std::string room_file) { int filesize; char *f = file::getFileBuffer(std::string("room/"+room_file+".yaml").c_str(), filesize, true); room = fkyaml::node::deserialize(std::string(f)); current_room = room_file; free(f); uint16_t tiles[32*16]; int i=0; for(auto row : room.at("tilemap").as_seq()) { for (auto t : row.as_seq()) { tiles[i] = t.get_value(); i++; } } tilemap::set(tiles); tilemap::setBackground(aux::getColorByName(room["room"]["bgColor"].get_value())); //fkyaml::node name_node = room["room"]["name"]; //printf("%s\n", name_node.get_value().c_str()); } void game::init() { draw::init("DILEMMAKER v0.1", 800, 600); game::setState(loop); font::load("font/8bithud"); draw::cls(0x00000000); tilemap::init(); std::vector room_names; for (const auto& entry : fs::directory_iterator("./data/room")) { if (entry.is_regular_file() && entry.path().extension() == ".yaml") { room_names.emplace_back(entry.path().stem()); } } std::sort(room_names.begin(), room_names.end(), [](const fs::path& a, const fs::path& b) { return a.filename().string() < b.filename().string(); }); for (auto& entry : room_names) { loadRoom(entry); rooms[entry] = room["room"]["name"].get_value(); } } bool loop() { menu::start(); if (menu::option("FILE")) { menu::popup::start(); menu::popup::option("New..."); menu::popup::option("Load..."); menu::popup::option("Save..."); menu::popup::end(); } if (menu::option("EDIT")) { menu::popup::start(); menu::popup::end(); } if (menu::option("SELECTION")) { menu::popup::start(); menu::popup::end(); } if (menu::option("VIEW")) { menu::popup::start(); menu::popup::end(); } if (menu::end()) { draw::render(); return true; } toolbar::start(); treeview::start(); for (auto p : rooms) { const char *r = p.first.c_str(); //std::string room_label = r + if (treeview::option(std::string(p.first + ": " + p.second).c_str(), 0)) { if (current_room != r) { loadRoom(r); } else { auto enemies = room.at("enemies").as_seq(); if (!enemies.empty()) treeview::option("ENEMIES:", 1); for (auto enemy : enemies) { treeview::option(enemy["animation"].get_value().c_str(), 2); } auto items = room.at("items").as_seq(); if (!items.empty()) treeview::option("ITEMS:", 1); char tmp[5]; for (int i=0; i