72 lines
2.9 KiB
C++
72 lines
2.9 KiB
C++
#include <iostream>
|
|
#include "yamal.hpp"
|
|
|
|
std::string readFileToString(const std::string& filename) {
|
|
std::ifstream ifs(filename);
|
|
if (!ifs) {
|
|
throw std::runtime_error("Cannot open file: " + filename);
|
|
}
|
|
std::ostringstream oss;
|
|
oss << ifs.rdbuf(); // dump the whole stream buffer into oss
|
|
return oss.str();
|
|
}
|
|
|
|
int main(int argc, char* argv[]) {
|
|
if (argc<2) { printf("ERROR: Falta un arxiu YAML com a paràmetre, meló.\n"); exit(-1); }
|
|
|
|
// Amb aquest codi es llig un YAML desde arxiu
|
|
// ===========================================
|
|
yamal root;
|
|
root.deserialize(readFileToString(argv[1]));
|
|
|
|
// Amb aquest codi es crearia desde cero un YAML com el de test.yaml
|
|
// =================================================================
|
|
/*
|
|
yamal root;
|
|
root["room"].setComment("THE JAIL");
|
|
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"].appendComment(""); // Linia en blanc
|
|
root["tilemap"].appendComment("Tilemap: 16 filas x 32 columnas (256x192 píxeles @ 8px/tile)");
|
|
root["tilemap"].appendComment("Índices de tiles (-1 = vacío)");
|
|
root["tilemap"][0][0] = 0;
|
|
root["tilemap"][0][1] = 1;
|
|
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].appendComment(""); // Linia en blanc
|
|
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["items"].appendComment(""); // Linia en blanc
|
|
*/
|
|
|
|
// Amb aquest codi es guarda a un std::string el YAML que hi ha en 'root'
|
|
// (i, en aquest cas, el tire a la consola)
|
|
// ======================================================================
|
|
std::cout << root.serialize() << std::endl;
|
|
|
|
return 0;
|
|
} |