X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Flevel.cpp;h=5ad193c33c744f8192de4e8fdaf4d55df739b6d6;hb=b524515944583916655a9f2cf1a667e55e7ed4ce;hp=94c98b34c235bdebbe36ba70d2be8a7894dc748a;hpb=d5f3984577afe481c7e0596d3a01f86c8ae83945;p=supertux.git diff --git a/src/level.cpp b/src/level.cpp index 94c98b34c..5ad193c33 100644 --- a/src/level.cpp +++ b/src/level.cpp @@ -50,9 +50,31 @@ Level::Level() } void +Level::create(const std::string& filename) +{ + Level level; + const size_t width = 25; + const size_t height = 19; + level.add_sector(Sector::create("main", width, height)); + level.save(filename); +} + +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 +124,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"); @@ -158,18 +184,6 @@ Level::get_sector(const std::string& name) return i->second; } -const std::string& -Level::get_sector_name(const Sector* sector) -{ - for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i) - { - if(i->second == sector) - return i->first; - } - std::cerr << "Warning: Sector not found on level\n"; - return ""; -} - Sector* Level::get_next_sector(const Sector* sector) {