// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
+#include <algorithm>
+
#include "lisp/parser.hpp"
#include "lisp/writer.hpp"
#include "physfs/ifile_stream.hpp"
world_thread(),
title(),
description(),
+ player_status(),
hide_from_contribs(),
is_levelset()
{
+ player_status.reset(new PlayerStatus());
+
is_levelset = true;
hide_from_contribs = false;
sq_resetobject(&world_thread);
// 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 << "': " <<PHYSFS_getLastError();
info->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
}
}
PHYSFS_freeList(files);
+
+ std::sort(levels.begin(), levels.end(), StringUtil::numeric_less);
}
void
} catch(std::exception& ) {
// fallback: try to load worldmap worldmap.stwm
using namespace worldmap;
- g_screen_manager->push_screen(new WorldMap(basedir + "worldmap.stwm"));
+ g_screen_manager->push_screen(new WorldMap(basedir + "worldmap.stwm", get_player_status()));
}
}
{
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;
+ }
}
}