Hacked together basic support for Levelset saving
[supertux.git] / src / supertux / levelset_screen.cpp
1 //  SuperTux
2 //  Copyright (C) 2014 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/levelset_screen.hpp"
18
19 #include "supertux/game_session.hpp"
20 #include "supertux/globals.hpp"
21 #include "supertux/savegame.hpp"
22 #include "supertux/screen_fade.hpp"
23 #include "supertux/screen_manager.hpp"
24 #include "util/file_system.hpp"
25
26 LevelsetScreen::LevelsetScreen(const std::string& basedir, const std::string& level_filename,
27                                Savegame& savegame) :
28   m_basedir(basedir),
29   m_level_filename(level_filename),
30   m_savegame(savegame),
31   m_level_started(false),
32   m_solved(false)
33 {
34   LevelsetState state = m_savegame.get_levelset_state(basedir);
35   LevelState level_state = state.get_level_state(level_filename);
36   m_solved = level_state.solved;
37 }
38
39 LevelsetScreen::~LevelsetScreen()
40 {
41 }
42
43 void
44 LevelsetScreen::draw(DrawingContext&)
45 {
46 }
47
48 void
49 LevelsetScreen::update(float elapsed_time)
50 {
51 }
52
53 void
54 LevelsetScreen::finished_level(bool win)
55 {
56   m_solved = m_solved || win;
57 }
58
59 void
60 LevelsetScreen::setup()
61 {
62   if (m_level_started)
63   {
64     log_info << "Saving Levelset state" << std::endl;
65     // this gets called when the GameSession is done and we return back to the
66     m_savegame.set_levelset_state(m_basedir, m_level_filename, m_solved);
67     m_savegame.save();
68     g_screen_manager->pop_screen();
69   }
70   else
71   {
72     m_level_started = true;
73
74     std::unique_ptr<Screen> screen(new GameSession(FileSystem::join(m_basedir, m_level_filename),
75                                                    m_savegame));
76     g_screen_manager->push_screen(std::move(screen));
77   }
78 }
79
80 void
81 LevelsetScreen::leave()
82 {
83 }
84
85 /* EOF */