Removed obsolete comment
[supertux.git] / src / supertux / game_manager.cpp
1 //  SuperTux
2 //  Copyright (C) 2013 Ingo Ruhnke <grumbel@gmail.com>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #include "supertux/game_manager.hpp"
18
19 #include <sstream>
20
21 #include "gui/menu_manager.hpp"
22 #include "lisp/lisp.hpp"
23 #include "lisp/parser.hpp"
24 #include "supertux/game_session.hpp"
25 #include "supertux/gameconfig.hpp"
26 #include "supertux/globals.hpp"
27 #include "supertux/levelset_screen.hpp"
28 #include "supertux/savegame.hpp"
29 #include "supertux/screen.hpp"
30 #include "supertux/screen_fade.hpp"
31 #include "supertux/screen_manager.hpp"
32 #include "supertux/world.hpp"
33 #include "util/file_system.hpp"
34 #include "util/log.hpp"
35 #include "worldmap/worldmap.hpp"
36
37 GameManager::GameManager() :
38   m_world(),
39   m_savegame()
40 {
41 }
42
43 GameManager::~GameManager()
44 {
45 }
46
47 void
48 GameManager::start_level(std::unique_ptr<World> world, const std::string& level_filename)
49 {
50   m_world = std::move(world);
51   m_savegame.reset(new Savegame(m_world->get_savegame_filename()));
52   m_savegame->load();
53
54   std::unique_ptr<Screen> screen(new LevelsetScreen(m_world->get_basedir(),
55                                                     level_filename,
56                                                     *m_savegame));
57   ScreenManager::current()->push_screen(std::move(screen));
58 }
59
60 void
61 GameManager::start_worldmap(std::unique_ptr<World> world)
62 {
63   try
64   {
65     m_world = std::move(world);
66     m_savegame.reset(new Savegame(m_world->get_savegame_filename()));
67     m_savegame->load();
68
69     ScreenManager::current()->push_screen(std::unique_ptr<Screen>(
70                                     new worldmap::WorldMap(m_world->get_worldmap_filename(),
71                                                            *m_savegame)));
72   }
73   catch(std::exception& e)
74   {
75     log_fatal << "Couldn't start world: " << e.what() << std::endl;
76   }
77 }
78
79 std::string
80 GameManager::get_level_name(const std::string& filename) const
81 {
82   try
83   {
84     lisp::Parser parser;
85     const lisp::Lisp* root = parser.parse(filename);
86
87     const lisp::Lisp* level = root->get_lisp("supertux-level");
88     if(!level)
89       return "";
90
91     std::string name;
92     level->get("name", name);
93     return name;
94   }
95   catch(const std::exception& e)
96   {
97     log_warning << "Problem getting name of '" << filename << "': "
98                 << e.what() << std::endl;
99     return "";
100   }
101 }
102
103 /* EOF */