X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Flevel.cpp;h=21069c7fd72f956bd4a14f854036fce6d7f57ca4;hb=35fa5542fadf1848919363620c7a76b04150c283;hp=f7906aba758d64979aca679611f6b73da3da66bd;hpb=083eeaf363c0b527b398e9257a6474c1054884ce;p=supertux.git diff --git a/src/level.cpp b/src/level.cpp index f7906aba7..21069c7fd 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -52,7 +52,19 @@ Level::Level() void Level::load(const std::string& filename) { - LispReader* level = LispReader::load(filename, "supertux-level"); + std::string filepath; + filepath = st_dir + "/levels/" + filename; + if (access(filepath.c_str(), R_OK) != 0) + { + filepath = datadir + "/levels/" + filename; + if (access(filepath.c_str(), R_OK) != 0) + { + std::cerr << "Error: Level: couldn't find level: " << filename << std::endl; + return; + } + } + + LispReader* level = LispReader::load(filepath, "supertux-level"); int version = 1; level->read_int("version", version); @@ -102,7 +114,11 @@ Level::load_old_format(LispReader& reader) void Level::save(const std::string& filename) { - ofstream file(filename.c_str(), ios::out); + std::string filepath = "levels/" + filename; + int last_slash = filepath.find_last_of('/'); + FileSystem::fcreatedir(filepath.substr(0,last_slash).c_str()); + filepath = st_dir + "/" + filepath; + ofstream file(filepath.c_str(), ios::out); LispWriter* writer = new LispWriter(file); writer->write_comment("Level made using SuperTux's built-in Level Editor");