#include "Morault_Map.h" #include "Morault_EngineInfo.h" #include #include #include #include #include Morault::Maps::Map::Map() { } Morault::Maps::Map::Map(std::string path) { } void Morault::Maps::Map::LoadMap(std::string path) { MapTriangles.clear(); pugi::xml_document doc; pugi::xml_parse_result result = doc.load_file(path.c_str()); if (result) { pugi::xml_node root = doc.child("shuman"); for (const auto& triangle : root.children("triangle")) { MapTriangle newTri; newTri.a.x = std::stof(triangle.child("a").child("x").child_value()); newTri.a.y = std::stof(triangle.child("a").child("y").child_value()); newTri.b.x = std::stof(triangle.child("b").child("x").child_value()); newTri.b.y = std::stof(triangle.child("b").child("y").child_value()); newTri.c.x = std::stof(triangle.child("c").child("x").child_value()); newTri.c.y = std::stof(triangle.child("c").child("y").child_value()); newTri.wallAB = triangle.child("wallab").child_value(); newTri.wallBC = triangle.child("wallbc").child_value(); newTri.wallCA = triangle.child("wallca").child_value(); newTri.ceilingTexture = triangle.child("ceiling").child_value(); newTri.floorTexture = triangle.child("floor").child_value(); newTri.heightCeiling = std::stoi(triangle.child("ceilingheight").child_value()); newTri.heightFloor = std::stoi(triangle.child("floorheight").child_value()); MapTriangles.push_back(newTri); } } else { throw std::runtime_error("can't open file " + path + "!\n"); } } void Morault::Maps::Map::SaveMap(std::string path) { std::ofstream out(path); out << "\n\n"; out << "\n"; out << " \n"; out << "" << MORAULT_ENGINE_VERSION << "\n"; out << "" << MORAULT_ENGINE_COMPILER << "\n"; out << "\n"; for (int i = 0; i < MapTriangles.size(); i++) { out << "\n"; out << "" << MapTriangles[i].a.x << "" << MapTriangles[i].a.y << "\n"; out << "" << MapTriangles[i].b.x << "" << MapTriangles[i].b.y << "\n"; out << "" << MapTriangles[i].c.x << "" << MapTriangles[i].c.y << "\n"; out << "" << MapTriangles[i].wallAB << "\n"; out << "" << MapTriangles[i].wallBC << "\n"; out << "" << MapTriangles[i].wallCA << "\n"; out << "" << MapTriangles[i].ceilingTexture << "\n"; out << "" << MapTriangles[i].floorTexture << "\n"; out << "" << MapTriangles[i].heightCeiling << "\n"; out << "" << MapTriangles[i].heightFloor << "\n"; out << "\n"; } out << ""; out.close(); } Morault::Maps::Map::~Map() { }