From: Ingo Ruhnke Date: Sun, 10 Aug 2014 20:52:49 +0000 (+0200) Subject: Moved World loading into a factory method World::load() X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=34ecdaa447b070429c97d1f1d26aa5abd925f95e;p=supertux.git Moved World loading into a factory method World::load() --- diff --git a/src/supertux/menu/contrib_menu.cpp b/src/supertux/menu/contrib_menu.cpp index adeaa4233..d957e1e1a 100644 --- a/src/supertux/menu/contrib_menu.cpp +++ b/src/supertux/menu/contrib_menu.cpp @@ -50,9 +50,7 @@ ContribMenu::ContribMenu() : { try { - std::unique_ptr world (new World); - - world->load(*it + "/info"); + std::unique_ptr world = World::load(*it + "/info"); if (!world->hide_from_contribs()) { diff --git a/src/supertux/menu/main_menu.cpp b/src/supertux/menu/main_menu.cpp index 61c54fe78..65ed61dc3 100644 --- a/src/supertux/menu/main_menu.cpp +++ b/src/supertux/menu/main_menu.cpp @@ -57,8 +57,7 @@ MainMenu::check_menu() { case MNID_STARTGAME: { - std::unique_ptr world(new World); - world->load("levels/world1/info"); + std::unique_ptr world = World::load("levels/world1/info"); GameManager::current()->start_game(std::move(world)); } break; diff --git a/src/supertux/world.cpp b/src/supertux/world.cpp index fbfe809b5..794f8ae56 100644 --- a/src/supertux/world.cpp +++ b/src/supertux/world.cpp @@ -31,6 +31,14 @@ #include "util/string_util.hpp" #include "worldmap/worldmap.hpp" +std::unique_ptr +World::load(const std::string& filename) +{ + std::unique_ptr world(new World); + world->load_(filename); + return std::move(world); +} + World::World() : m_worldmap_filename(), m_levels(), @@ -74,7 +82,7 @@ World::set_savegame_filename(const std::string& filename) } void -World::load(const std::string& filename) +World::load_(const std::string& filename) { m_basedir = FileSystem::dirname(filename); m_worldmap_filename = m_basedir + "worldmap.stwm"; diff --git a/src/supertux/world.hpp b/src/supertux/world.hpp index a7ffd2757..5d305bc91 100644 --- a/src/supertux/world.hpp +++ b/src/supertux/world.hpp @@ -17,6 +17,7 @@ #ifndef HEADER_SUPERTUX_SUPERTUX_WORLD_HPP #define HEADER_SUPERTUX_SUPERTUX_WORLD_HPP +#include #include #include #include @@ -27,12 +28,18 @@ class PlayerStatus; class World : public Currenton { -public: +private: World(); + + void load_(const std::string& filename); + +public: + static std::unique_ptr load(const std::string& filename); + +public: ~World(); void set_savegame_filename(const std::string& filename); - void load(const std::string& filename); void save_state(); void load_state();