- Serialitzador acabat
This commit is contained in:
60
main.cpp
60
main.cpp
@@ -1,30 +1,46 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include "yamal.hpp"
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
/*if (argc < 2) {
|
||||
std::cerr << "Usage: " << argv[0] << " <yaml_file>\n";
|
||||
return 1;
|
||||
}*/
|
||||
|
||||
std::ifstream file("data/room/01.yaml"); //argv[1]);
|
||||
if (!file) {
|
||||
std::cerr << "Error: Could not open file " << argv[1] << "\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::ostringstream buffer;
|
||||
buffer << file.rdbuf();
|
||||
std::string yamlText = buffer.str();
|
||||
|
||||
yamal_ns::yamal root;
|
||||
root.deserialize(yamlText);
|
||||
|
||||
//for (auto &att : root.attributes())
|
||||
// std::cout << att.first << ": " << att.second.asString() << std::endl;
|
||||
yamal root;
|
||||
root["room"]["name"] = "THE JAIL";
|
||||
root["room"]["name"].setQuoted(true);
|
||||
root["room"]["bgColor"] = "bright_blue";
|
||||
root["room"]["connections"]["up"] = "null";
|
||||
root["room"]["connections"]["down"] = "null";
|
||||
root["room"]["connections"]["left"] = "null";
|
||||
root["room"]["connections"]["right"] = "02.yaml";
|
||||
root["room"]["itemColor1"] = "yellow";
|
||||
root["tilemap"][0][0] = 00;
|
||||
root["tilemap"][0][1] = 01;
|
||||
root["tilemap"][1][0] = 10;
|
||||
root["tilemap"][1][1] = 11;
|
||||
root["tilemap"][0].setInline(true);
|
||||
root["tilemap"][1].setInline(true);
|
||||
root["enemies"][0]["animation"] = "jailer_1.yaml";
|
||||
root["enemies"][0]["position"]["x"] = 1;
|
||||
root["enemies"][0]["position"]["y"] = 13;
|
||||
root["enemies"][0]["position"].setInline(true);
|
||||
root["enemies"][0]["boundaries"]["position1"]["x"] = 1;
|
||||
root["enemies"][0]["boundaries"]["position1"]["y"] = 1;
|
||||
root["enemies"][0]["boundaries"]["position1"].setInline(true);
|
||||
root["enemies"][0]["color"]= "white";
|
||||
root["enemies"][1]["animation"] = "jailer_2.yaml";
|
||||
root["enemies"][1]["position"]["x"] = 2;
|
||||
root["enemies"][1]["position"]["y"] = 23;
|
||||
root["enemies"][1]["position"].setInline(true);
|
||||
root["enemies"][1]["boundaries"]["position1"]["x"] = 2;
|
||||
root["enemies"][1]["boundaries"]["position1"]["y"] = 2;
|
||||
root["enemies"][1]["boundaries"]["position1"].setInline(true);
|
||||
root["enemies"][1]["color"]= "black";
|
||||
root["items"].clearToVector();
|
||||
root["items"].setInline(true);
|
||||
|
||||
root["room"].setComment("THE JAIL");
|
||||
root["room"].setBlankLine(false);
|
||||
root["tilemap"].setComment("Tilemap: 16 filas x 32 columnas (256x192 píxeles @ 8px/tile)");
|
||||
root["tilemap"].appendComment("Índices de tiles (-1 = vacío)");
|
||||
root["room"]["bgColor"].setInlineComment("Azul oscuro");
|
||||
std::cout << root.serialize() << std::endl;
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user