Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Moved TitleScreen::get_level_name() into GameManager, not a great pla…
…ce either, but a little better
  • Loading branch information
Grumbel committed Aug 11, 2014
1 parent bc5213c commit 7824178
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 26 deletions.
26 changes: 26 additions & 0 deletions src/supertux/game_manager.cpp
Expand Up @@ -19,6 +19,8 @@
#include <sstream>

#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"
Expand Down Expand Up @@ -65,4 +67,28 @@ GameManager::start_game(std::unique_ptr<World> 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 */
2 changes: 2 additions & 0 deletions src/supertux/game_manager.hpp
Expand Up @@ -35,6 +35,8 @@ class GameManager : public Currenton<GameManager>
void start_game(std::unique_ptr<World> world);
void start_level(std::unique_ptr<World> world, int index);

std::string get_level_name(const std::string& levelfile) const;

private:
GameManager(const GameManager&) = delete;
GameManager& operator=(const GameManager&) = delete;
Expand Down
4 changes: 2 additions & 2 deletions src/supertux/menu/contrib_world_menu.cpp
Expand Up @@ -32,11 +32,11 @@ ContribWorldMenu::ContribWorldMenu(std::unique_ptr<World> 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);
}

Expand Down
21 changes: 0 additions & 21 deletions src/supertux/title_screen.cpp
Expand Up @@ -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()
{
Expand Down
3 changes: 0 additions & 3 deletions src/supertux/title_screen.hpp
Expand Up @@ -33,9 +33,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();
Expand Down

0 comments on commit 7824178

Please sign in to comment.