diff --git a/src/sago/SagoMisc.cpp b/src/sago/SagoMisc.cpp index da58bd8..d91f6e8 100644 --- a/src/sago/SagoMisc.cpp +++ b/src/sago/SagoMisc.cpp @@ -71,7 +71,18 @@ std::string GetFileContent(const char* filename) { return ret; } +void CreatePathToFile(const std::string& path) { + size_t end_of_path = path.find_last_of("/"); + if (end_of_path == std::string::npos) { + //No path + return; + } + std::string path2dir = path.substr(0, end_of_path); + PHYSFS_mkdir(path2dir.c_str()); +} + void WriteFileContent(const char* filename, const std::string& content) { + CreatePathToFile(filename); PHYSFS_file* myfile = PHYSFS_openWrite(filename); if (!myfile) { cerr << "Failed to open file for writing, " << PHYSFS_getLastError() << "\n"; diff --git a/src/saland/Game.cpp b/src/saland/Game.cpp index 45ec732..d1623f3 100644 --- a/src/saland/Game.cpp +++ b/src/saland/Game.cpp @@ -61,6 +61,8 @@ Game::Game() { } Game::~Game() { + std::string data2save = sago::tiled::tilemap2string(data->tm); + sago::WriteFileContent("maps/sample1.tmx", data2save); } bool Game::IsActive() {