- No se, estic netejant i estos canvis no estaven comitats...

This commit is contained in:
2026-02-06 11:03:27 +01:00
parent 19441c5289
commit 157ad97ef0
4 changed files with 571 additions and 14766 deletions

View File

@@ -6,9 +6,10 @@
#include "treeview.h"
#include "propertygrid.h"
#include "tilemap.h"
#include "fkYAML/node.hpp"
#include "yamal.hpp"
#include <filesystem>
#include <iostream>
#include <map>
#include "misc.h"
namespace fs = std::filesystem;
@@ -17,32 +18,30 @@ bool loop();
std::map<std::string, std::string> rooms;
fkyaml::node room;
yamal root;
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));
root.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 row : root["tilemap"].vec_data)
{
for (auto t : row.as_seq())
for (auto t : row.vec_data)
{
tiles[i] = t.get_value<int>();
tiles[i] = t.asInt();
i++;
}
}
tilemap::set(tiles);
tilemap::setBackground(misc::getColorByName(room["room"]["bgColor"].get_value<std::string>()));
tilemap::setBorder(misc::getColorByName(room["room"]["border"].get_value<std::string>()));
//fkyaml::node name_node = room["room"]["name"];
//printf("%s\n", name_node.get_value<std::string>().c_str());
tilemap::setBackground(misc::getColorByName(root["room"]["bgColor"]));
tilemap::setBorder(misc::getColorByName(root["room"]["border"]));
}
void game::init()
@@ -66,7 +65,8 @@ void game::init()
for (auto& entry : room_names) {
loadRoom(entry);
rooms[entry] = room["room"]["name"].get_value<std::string>();
std::string peiv = root["room"]["name"];
rooms[entry] = root["room"]["name"];
}
}
@@ -104,12 +104,12 @@ bool loop()
if (current_room != r) {
loadRoom(r);
} else {
auto enemies = room.at("enemies").as_seq();
auto& enemies = root["enemies"].vec_data;
if (!enemies.empty()) treeview::option("ENEMIES:", 1);
for (auto enemy : enemies) {
treeview::option(enemy["animation"].get_value<std::string>().c_str(), 2);
for (auto& enemy : enemies) {
treeview::option(enemy["animation"].value.c_str(), 2);
}
auto items = room.at("items").as_seq();
auto& items = root["items"].vec_data;
if (!items.empty()) treeview::option("ITEMS:", 1);
char tmp[5];
for (int i=0; i<items.size(); ++i) {
@@ -122,42 +122,44 @@ bool loop()
tilemap::start();
tilemap::draw();
char tmp[256];
propertygrid::start();
if (treeview::getSelected(0) > -1) {
if (treeview::getSelected(2) == -1) {
propertygrid::sectionProperty("ROOM:");
if (propertygrid::stringProperty("NAME", room["room"]["name"].get_value<std::string>())) room["room"]["name"] = propertygrid::getStringPropertyResult();
propertygrid::stringProperty("BGCOLOR", room["room"]["bgColor"].get_value<std::string>());
propertygrid::stringProperty("BORDER", room["room"]["border"].get_value<std::string>());
propertygrid::stringProperty("TILESET", room["room"]["tileSetFile"].get_value<std::string>());
propertygrid::stringProperty("ITEMCOL1", room["room"]["itemColor1"].get_value<std::string>());
propertygrid::stringProperty("ITEMCOL2", room["room"]["itemColor2"].get_value<std::string>());
propertygrid::stringProperty("CONVEYOR", room["room"]["conveyorBelt"].get_value<std::string>());
if (propertygrid::stringProperty("NAME", root["room"]["name"])) root["room"]["name"] = propertygrid::getStringPropertyResult();
propertygrid::stringProperty("BGCOLOR", root["room"]["bgColor"]);
propertygrid::stringProperty("BORDER", root["room"]["border"]);
propertygrid::stringProperty("TILESET", root["room"]["tileSetFile"]);
propertygrid::stringProperty("ITEMCOL1", root["room"]["itemColor1"]);
propertygrid::stringProperty("ITEMCOL2", root["room"]["itemColor2"]);
propertygrid::stringProperty("CONVEYOR", root["room"]["conveyorBelt"]);
propertygrid::sectionProperty("CONNECTIONS:");
propertygrid::stringProperty("UP", room["room"]["connections"]["up"].is_null()?"null":room["room"]["connections"]["up"].get_value<std::string>().substr(0,2)+": "+rooms[room["room"]["connections"]["up"].get_value<std::string>().substr(0,2)]);
propertygrid::stringProperty("DOWN", room["room"]["connections"]["down"].is_null()?"null":room["room"]["connections"]["down"].get_value<std::string>().substr(0,2)+": "+rooms[room["room"]["connections"]["down"].get_value<std::string>().substr(0,2)]);
propertygrid::stringProperty("LEFT", room["room"]["connections"]["left"].is_null()?"null":room["room"]["connections"]["left"].get_value<std::string>().substr(0,2)+": "+rooms[room["room"]["connections"]["left"].get_value<std::string>().substr(0,2)]);
propertygrid::stringProperty("RIGHT", room["room"]["connections"]["right"].is_null()?"null":room["room"]["connections"]["right"].get_value<std::string>().substr(0,2)+": "+rooms[room["room"]["connections"]["right"].get_value<std::string>().substr(0,2)]);
propertygrid::stringProperty("UP", root["room"]["connections"]["up" ].value=="null"?"null":root["room"]["connections"]["up"].value.substr(0,2)+": "+rooms[root["room"]["connections"]["up"].value.substr(0,2)]);
propertygrid::stringProperty("DOWN", root["room"]["connections"]["down" ].value=="null"?"null":root["room"]["connections"]["down"].value.substr(0,2)+": "+rooms[root["room"]["connections"]["down"].value.substr(0,2)]);
propertygrid::stringProperty("LEFT", root["room"]["connections"]["left" ].value=="null"?"null":root["room"]["connections"]["left"].value.substr(0,2)+": "+rooms[root["room"]["connections"]["left"].value.substr(0,2)]);
propertygrid::stringProperty("RIGHT", root["room"]["connections"]["right"].value=="null"?"null":root["room"]["connections"]["right"].value.substr(0,2)+": "+rooms[root["room"]["connections"]["right"].value.substr(0,2)]);
} else {
const int num_enemies = room.at("enemies").as_seq().size();
const int num_enemies = root["enemies"].vec_data.size();
if (treeview::getSelected(2) < num_enemies) {
auto enemy = room.at("enemies").as_seq()[treeview::getSelected(2)];
auto& enemy = root["enemies"][treeview::getSelected(2)];
propertygrid::sectionProperty("ENEMY:");
propertygrid::stringProperty("ANIMATION", enemy["animation"].get_value<std::string>());
propertygrid::stringProperty("POSITION", std::to_string(enemy["position"]["x"].get_value<int>())+std::string(", ")+std::to_string(enemy["position"]["y"].get_value<int>()));
propertygrid::stringProperty("VELOCITY", misc::floatToString(enemy["velocity"]["x"].get_value<float>())+std::string(", ")+misc::floatToString(enemy["velocity"]["y"].get_value<float>()));
propertygrid::stringProperty("COLOR", enemy["color"].get_value<std::string>());
propertygrid::stringProperty("ANIMATION", enemy["animation"]);
propertygrid::stringProperty("POSITION", enemy["position"]["x"].value+", "+enemy["position"]["y"].value);
propertygrid::stringProperty("VELOCITY", enemy["velocity"]["x"].value+", "+enemy["velocity"]["y"].value);
propertygrid::stringProperty("COLOR", enemy["color"]);
propertygrid::sectionProperty("BOUNDARIES:");
propertygrid::stringProperty("START", std::to_string(enemy["boundaries"]["position1"]["x"].get_value<int>())+std::string(", ")+std::to_string(enemy["boundaries"]["position1"]["y"].get_value<int>()));
propertygrid::stringProperty("END", std::to_string(enemy["boundaries"]["position2"]["x"].get_value<int>())+std::string(", ")+std::to_string(enemy["boundaries"]["position2"]["y"].get_value<int>()));
propertygrid::stringProperty("START", enemy["boundaries"]["position1"]["x"].value+", "+enemy["boundaries"]["position1"]["y"].value);
propertygrid::stringProperty("END", enemy["boundaries"]["position2"]["x"].value+", "+enemy["boundaries"]["position2"]["y"].value);
} else {
auto item = room.at("items").as_seq()[treeview::getSelected(2)-num_enemies];
auto& item = root["items"][treeview::getSelected(2)-num_enemies];
propertygrid::sectionProperty("ITEM:");
propertygrid::stringProperty("TILESET", item["tileSetFile"].get_value<std::string>());
propertygrid::stringProperty("TILE", std::to_string(item["tile"].get_value<int>()));
propertygrid::stringProperty("POSITION", std::to_string(item["position"]["x"].get_value<int>())+std::string(", ")+std::to_string(item["position"]["y"].get_value<int>()));
propertygrid::stringProperty("COUNTER", std::to_string(item["counter"].get_value<int>()));
propertygrid::stringProperty("TILESET", item["tileSetFile"]);
propertygrid::stringProperty("TILE", item["tile"]);
propertygrid::stringProperty("POSITION", item["position"]["x"].value+", "+item["position"]["y"].value);
propertygrid::stringProperty("COUNTER", item["counter"]);
}
}
}