{
m_world = std::move(world);
- std::unique_ptr<Screen> screen(new GameSession(m_world->get_level_filename(index),
+ std::unique_ptr<Screen> screen(new GameSession(m_world->get_level_filename(index),
m_world->get_player_status()));
g_screen_manager->push_screen(std::move(screen));
}
MenuManager::instance().clear_menu_stack();
- std::string basename = m_world->get_basedir();
- basename = basename.substr(0, basename.length()-1);
- std::string worlddirname = FileSystem::basename(basename);
- std::ostringstream stream;
- stream << "profile" << g_config->profile << "/" << worlddirname << ".stsg";
- std::string slotfile = stream.str();
-
try
{
- m_world->set_savegame_filename(slotfile);
m_world->run();
}
catch(std::exception& e)
{
try
{
- std::unique_ptr<World> world = World::load(*it + "/info");
+ std::unique_ptr<World> world = World::load(*it);
if (!world->hide_from_contribs())
{
- { // FIXME: yuck, this should be easier
- std::ostringstream stream;
- std::string worlddirname = FileSystem::basename(*it);
- stream << "profile" << g_config->profile << "/" << worlddirname << ".stsg";
- std::string slotfile = stream.str();
- world->set_savegame_filename(stream.str());
- world->load_state();
- }
+ world->load_state();
std::ostringstream title;
title << world->get_title() << " (" << world->get_num_solved_levels() << "/" << world->get_num_levels() << ")";
// so it might be ok
GameManager::current()->start_game(std::move(m_contrib_worlds[index]));
}
- else
+ else
{
MenuManager::instance().push_menu(std::unique_ptr<Menu>(new ContribWorldMenu(std::move(m_contrib_worlds[index]))));
}
#include "physfs/ifile_streambuf.hpp"
#include "scripting/serialize.hpp"
#include "scripting/squirrel_util.hpp"
+#include "supertux/gameconfig.hpp"
#include "supertux/globals.hpp"
+#include "supertux/player_status.hpp"
#include "supertux/screen_fade.hpp"
#include "supertux/screen_manager.hpp"
-#include "supertux/player_status.hpp"
#include "supertux/world.hpp"
#include "util/file_system.hpp"
#include "util/reader.hpp"
#include "worldmap/worldmap.hpp"
std::unique_ptr<World>
-World::load(const std::string& filename)
+World::load(const std::string& directory)
{
std::unique_ptr<World> world(new World);
- world->load_(filename);
+
+ world->load_(directory + "/info");
+
+ { // generate savegame filename
+ std::string worlddirname = FileSystem::basename(directory);
+ std::ostringstream stream;
+ stream << "profile" << g_config->profile << "/" << worlddirname << ".stsg";
+ std::string slotfile = stream.str();
+ world->m_savegame_filename = stream.str();
+ }
+
return std::move(world);
}
}
void
-World::set_savegame_filename(const std::string& filename)
-{
- m_savegame_filename = 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())) {
- std::ostringstream msg;
- msg << "Couldn't create directory for savegames '"
- << dirname << "': " <<PHYSFS_getLastError();
- throw std::runtime_error(msg.str());
- }
- }
-
- if(!PHYSFS_isDirectory(dirname.c_str())) {
- std::ostringstream msg;
- msg << "Savegame path '" << dirname << "' is not a directory";
- throw std::runtime_error(msg.str());
- }
-}
-
-void
World::load_(const std::string& filename)
{
m_basedir = FileSystem::dirname(filename);
void
World::save_state()
{
+ { // make sure the savegame directory exists
+ std::string dirname = FileSystem::dirname(m_savegame_filename);
+ if(!PHYSFS_exists(dirname.c_str()))
+ {
+ if(!PHYSFS_mkdir(dirname.c_str()))
+ {
+ std::ostringstream msg;
+ msg << "Couldn't create directory for savegames '"
+ << dirname << "': " <<PHYSFS_getLastError();
+ throw std::runtime_error(msg.str());
+ }
+ }
+
+ if(!PHYSFS_isDirectory(dirname.c_str()))
+ {
+ std::ostringstream msg;
+ msg << "Savegame path '" << dirname << "' is not a directory";
+ throw std::runtime_error(msg.str());
+ }
+ }
+
HSQUIRRELVM vm = scripting::global_vm;
lisp::Writer writer(m_savegame_filename);