X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsupertux%2Fworld.cpp;h=f821dd4a4fdbdfa1a3cd0f87ba321e20c7f96a43;hb=b9c8dcafba33cd26afb49fe7ed1e98c10e5cb28f;hp=399816cec5d1a74e200ccf589ccecddb9fd67a19;hpb=42de210bd2cb0e773ce0b7bd6af7bb3f456030bc;p=supertux.git diff --git a/src/supertux/world.cpp b/src/supertux/world.cpp index 399816cec..f821dd4a4 100644 --- a/src/supertux/world.cpp +++ b/src/supertux/world.cpp @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include + #include "lisp/parser.hpp" #include "lisp/writer.hpp" #include "physfs/ifile_stream.hpp" @@ -63,7 +65,7 @@ World::set_savegame_filename(const std::string& filename) // make sure the savegame directory exists std::string dirname = FileSystem::dirname(filename); if(!PHYSFS_exists(dirname.c_str())) { - if(PHYSFS_mkdir(dirname.c_str())) { + if(!PHYSFS_mkdir(dirname.c_str())) { std::ostringstream msg; msg << "Couldn't create directory for savegames '" << dirname << "': " <get("title", title); info->get("description", description); info->get("levelset", is_levelset); - info->get("levels", levels); info->get("hide-from-contribs", hide_from_contribs); // Level info file doesn't define any levels, so read the @@ -117,6 +118,8 @@ World::load(const std::string& filename) } } PHYSFS_freeList(files); + + std::sort(levels.begin(), levels.end(), StringUtil::numeric_less); } void @@ -194,41 +197,43 @@ World::load_state() { using namespace scripting; - try { - lisp::Parser parser; - const lisp::Lisp* root = parser.parse(savegame_filename); - - const lisp::Lisp* lisp = root->get_lisp("supertux-savegame"); - if(lisp == NULL) - throw std::runtime_error("file is not a supertux-savegame file"); - - int version = 1; - lisp->get("version", version); - if(version != 1) - throw std::runtime_error("incompatible savegame version"); - - const lisp::Lisp* tux = lisp->get_lisp("tux"); - if(tux == NULL) - throw std::runtime_error("No tux section in savegame"); - player_status->read(*tux); - - const lisp::Lisp* state = lisp->get_lisp("state"); - if(state == NULL) - throw std::runtime_error("No state section in savegame"); - - sq_pushroottable(global_vm); - sq_pushstring(global_vm, "state", -1); - if(SQ_FAILED(sq_deleteslot(global_vm, -2, SQFalse))) + if(PHYSFS_exists(savegame_filename.c_str())) { + try { + lisp::Parser parser; + const lisp::Lisp* root = parser.parse(savegame_filename); + + const lisp::Lisp* lisp = root->get_lisp("supertux-savegame"); + if(lisp == NULL) + throw std::runtime_error("file is not a supertux-savegame file"); + + int version = 1; + lisp->get("version", version); + if(version != 1) + throw std::runtime_error("incompatible savegame version"); + + const lisp::Lisp* tux = lisp->get_lisp("tux"); + if(tux == NULL) + throw std::runtime_error("No tux section in savegame"); + player_status->read(*tux); + + const lisp::Lisp* state = lisp->get_lisp("state"); + if(state == NULL) + throw std::runtime_error("No state section in savegame"); + + sq_pushroottable(global_vm); + sq_pushstring(global_vm, "state", -1); + if(SQ_FAILED(sq_deleteslot(global_vm, -2, SQFalse))) + sq_pop(global_vm, 1); + + sq_pushstring(global_vm, "state", -1); + sq_newtable(global_vm); + load_squirrel_table(global_vm, -1, *state); + if(SQ_FAILED(sq_createslot(global_vm, -3))) + throw std::runtime_error("Couldn't create state table"); sq_pop(global_vm, 1); - - sq_pushstring(global_vm, "state", -1); - sq_newtable(global_vm); - load_squirrel_table(global_vm, -1, *state); - if(SQ_FAILED(sq_createslot(global_vm, -3))) - throw std::runtime_error("Couldn't create state table"); - sq_pop(global_vm, 1); - } catch(std::exception& e) { - log_debug << "Couldn't load savegame: " << e.what() << std::endl; + } catch(std::exception& e) { + log_fatal << "Couldn't load savegame: " << e.what() << std::endl; + } } }