- [NEW] Ficades les habitacions amb el nou format YAML
- [NEW] Afegit el fkYAML de una capçalera - [NEW] El treeview ja funciona com deu mana - [NEW] En el treeview ja funciona el scroll amb el mouse sheel - [NEW] El treeview ja mostra les habitacions i els enemics (falten items)
This commit is contained in:
@@ -4,15 +4,51 @@
|
||||
#include "menu.h"
|
||||
#include "toolbar.h"
|
||||
#include "treeview.h"
|
||||
#include "fkYAML/node.hpp"
|
||||
#include <filesystem>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
bool loop();
|
||||
|
||||
std::map<std::string, std::string> 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);
|
||||
//fkyaml::node name_node = room["room"]["name"];
|
||||
//printf("%s\n", name_node.get_value<std::string>().c_str());
|
||||
}
|
||||
|
||||
void game::init()
|
||||
{
|
||||
draw::init("DILEMMAKER v0.1", 800, 600);
|
||||
game::setState(loop);
|
||||
font::load("font/8bithud");
|
||||
draw::cls(0x00000000);
|
||||
|
||||
std::vector<std::string> 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<std::string>();
|
||||
}
|
||||
}
|
||||
|
||||
bool loop()
|
||||
@@ -42,17 +78,19 @@ bool loop()
|
||||
toolbar::start();
|
||||
|
||||
treeview::start();
|
||||
if (treeview::option("room01", 0)) {
|
||||
treeview::option("abad", 1);
|
||||
treeview::option("Jailer", 1);
|
||||
}
|
||||
if (treeview::option("room02", 0)) {
|
||||
treeview::option("abad", 1);
|
||||
treeview::option("Jailer", 1);
|
||||
}
|
||||
if (treeview::option("room03", 0)) {
|
||||
treeview::option("abad", 1);
|
||||
treeview::option("Jailer", 1);
|
||||
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();
|
||||
for (auto enemy : enemies) {
|
||||
treeview::option(enemy["animation"].get_value<std::string>().c_str(), 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
treeview::end();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user