supertux
savegame.hpp
1 // SuperTux
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 // 2014 Ingo Ruhnke <grumbel@gmail.com>
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 #ifndef HEADER_SUPERTUX_SUPERTUX_SAVEGAME_HPP
19 #define HEADER_SUPERTUX_SUPERTUX_SAVEGAME_HPP
20 
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 class PlayerStatus;
26 
27 struct LevelState
28 {
29 public:
30  LevelState() :
31  filename(),
32  solved(false),
33  perfect(false)
34  {}
35 
36  std::string filename;
37  bool solved;
38  bool perfect;
39 };
40 
42 {
43 public:
44  LevelsetState() :
45  directory(),
46  level_states()
47  {}
48  std::string directory;
49  std::vector<LevelState> level_states;
50 
51  LevelState get_level_state(const std::string& filename) const;
52  void store_level_state(const LevelState& state);
53 };
54 
56 {
57 public:
58  WorldmapState() :
59  filename(),
60  level_states()
61  {}
62  std::string filename;
63  std::vector<LevelState> level_states;
64 };
65 
66 class Savegame final
67 {
68 public:
69  static std::unique_ptr<Savegame> from_file(const std::string& filename);
70 
71 public:
72  Savegame(const std::string& filename);
73 
75  PlayerStatus& get_player_status() const { return *m_player_status; }
76 
77  std::string get_title() const;
78 
79  std::vector<std::string> get_levelsets();
80  LevelsetState get_levelset_state(const std::string& name);
81  void set_levelset_state(const std::string& basedir,
82  const std::string& level_filename,
83  bool solved);
84 
85  std::vector<std::string> get_worldmaps();
86  WorldmapState get_worldmap_state(const std::string& name);
87 
88  void save();
89 
90  bool is_title_screen() const;
91 
92 private:
93  void load();
94  void clear_state_table();
95 
96 private:
97  std::string m_filename;
98  std::unique_ptr<PlayerStatus> m_player_status;
99 
100 private:
101  Savegame(const Savegame&) = delete;
102  Savegame& operator=(const Savegame&) = delete;
103 };
104 
105 #endif
106 
107 /* EOF */
This class keeps player status between different game sessions (for example when switching maps in th...
Definition: player_status.hpp:38
PlayerStatus & get_player_status() const
Returns content of (tux ...) entry.
Definition: savegame.hpp:75
Definition: savegame.hpp:27
Definition: savegame.hpp:41
Definition: savegame.hpp:66
Definition: savegame.hpp:55