From: Ingo Ruhnke Date: Mon, 11 Aug 2014 03:08:50 +0000 (+0200) Subject: Moved TitleScreen::get_level_name() into GameManager, not a great place either, but... X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=7824178a3691f70975f01a5dd46da9c40c6269f4;p=supertux.git Moved TitleScreen::get_level_name() into GameManager, not a great place either, but a little better --- diff --git a/src/supertux/game_manager.cpp b/src/supertux/game_manager.cpp index ba5e72f8d..1d201844c 100644 --- a/src/supertux/game_manager.cpp +++ b/src/supertux/game_manager.cpp @@ -19,6 +19,8 @@ #include #include "gui/menu_manager.hpp" +#include "lisp/lisp.hpp" +#include "lisp/parser.hpp" #include "supertux/game_session.hpp" #include "supertux/gameconfig.hpp" #include "supertux/globals.hpp" @@ -65,4 +67,28 @@ GameManager::start_game(std::unique_ptr world) } } +std::string +GameManager::get_level_name(const std::string& filename) const +{ + try + { + lisp::Parser parser; + const lisp::Lisp* root = parser.parse(filename); + + const lisp::Lisp* level = root->get_lisp("supertux-level"); + if(!level) + return ""; + + std::string name; + level->get("name", name); + return name; + } + catch(const std::exception& e) + { + log_warning << "Problem getting name of '" << filename << "': " + << e.what() << std::endl; + return ""; + } +} + /* EOF */ diff --git a/src/supertux/game_manager.hpp b/src/supertux/game_manager.hpp index 2e87896a5..f349032e2 100644 --- a/src/supertux/game_manager.hpp +++ b/src/supertux/game_manager.hpp @@ -35,6 +35,8 @@ public: void start_game(std::unique_ptr world); void start_level(std::unique_ptr world, int index); + std::string get_level_name(const std::string& levelfile) const; + private: GameManager(const GameManager&) = delete; GameManager& operator=(const GameManager&) = delete; diff --git a/src/supertux/menu/contrib_world_menu.cpp b/src/supertux/menu/contrib_world_menu.cpp index c03c543e2..799e410e9 100644 --- a/src/supertux/menu/contrib_world_menu.cpp +++ b/src/supertux/menu/contrib_world_menu.cpp @@ -32,11 +32,11 @@ ContribWorldMenu::ContribWorldMenu(std::unique_ptr world) : add_label(m_world->get_title()); add_hl(); - for (unsigned int i = 0; i < m_world->get_num_levels(); ++i) + for (int i = 0; i < m_world->get_num_levels(); ++i) { /** get level's title */ std::string filename = m_world->get_level_filename(i); - std::string title = TitleScreen::get_level_name(filename); + std::string title = GameManager::current()->get_level_name(filename); add_entry(i, title); } diff --git a/src/supertux/title_screen.cpp b/src/supertux/title_screen.cpp index 62d810e58..7b687b1ef 100644 --- a/src/supertux/title_screen.cpp +++ b/src/supertux/title_screen.cpp @@ -61,27 +61,6 @@ TitleScreen::TitleScreen(PlayerStatus* player_status) : ); } -std::string -TitleScreen::get_level_name(const std::string& filename) -{ - try { - lisp::Parser parser; - const lisp::Lisp* root = parser.parse(filename); - - const lisp::Lisp* level = root->get_lisp("supertux-level"); - if(!level) - return ""; - - std::string name; - level->get("name", name); - return name; - } catch(std::exception& e) { - log_warning << "Problem getting name of '" << filename << "': " - << e.what() << std::endl; - return ""; - } -} - void TitleScreen::make_tux_jump() { diff --git a/src/supertux/title_screen.hpp b/src/supertux/title_screen.hpp index 69354c1e2..a749791fb 100644 --- a/src/supertux/title_screen.hpp +++ b/src/supertux/title_screen.hpp @@ -34,9 +34,6 @@ class World; class TitleScreen : public Screen { public: - static std::string get_level_name(const std::string& levelfile); - -public: TitleScreen(PlayerStatus* player_status); virtual ~TitleScreen();