Updated email address, grumbel@gmx.de -> grumbel@gmail.com
[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 "supertux/game_session.hpp"
23 #include "supertux/gameconfig.hpp"
24 #include "supertux/globals.hpp"
25 #include "supertux/screen.hpp"
26 #include "supertux/screen_fade.hpp"
27 #include "supertux/screen_manager.hpp"
28 #include "supertux/world.hpp"
29 #include "util/file_system.hpp"
30 #include "util/log.hpp"
31
32 GameManager::GameManager() :
33   m_world()
34 {
35 }
36
37 GameManager::~GameManager()
38 {
39 }
40
41 void
42 GameManager::start_level(std::unique_ptr<World> world, int index)
43 {
44   m_world = std::move(world);
45
46   std::unique_ptr<Screen> screen(new GameSession(m_world->get_level_filename(index), 
47                                                  m_world->get_player_status()));
48   g_screen_manager->push_screen(std::move(screen));
49 }
50
51 void
52 GameManager::start_game(std::unique_ptr<World> world)
53 {
54   m_world = std::move(world);
55
56   MenuManager::instance().clear_menu_stack();
57
58   std::string basename = m_world->get_basedir();
59   basename = basename.substr(0, basename.length()-1);
60   std::string worlddirname = FileSystem::basename(basename);
61   std::ostringstream stream;
62   stream << "profile" << g_config->profile << "/" << worlddirname << ".stsg";
63   std::string slotfile = stream.str();
64
65   try
66   {
67     m_world->set_savegame_filename(slotfile);
68     m_world->run();
69   }
70   catch(std::exception& e)
71   {
72     log_fatal << "Couldn't start world: " << e.what() << std::endl;
73   }
74 }
75
76 /* EOF */