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 #include <simplesquirrel/table.hpp>
26 
27 class PlayerStatus;
28 class Profile;
29 
30 struct LevelState
31 {
32 public:
33  LevelState() :
34  filename(),
35  solved(false),
36  perfect(false)
37  {}
38 
39  std::string filename;
40  bool solved;
41  bool perfect;
42 };
43 
45 {
46 public:
47  LevelsetState() :
48  directory(),
49  level_states()
50  {}
51  std::string directory;
52  std::vector<LevelState> level_states;
53 
54  LevelState get_level_state(const std::string& filename) const;
55  void store_level_state(const LevelState& state);
56 };
57 
59 {
60 public:
61  WorldmapState() :
62  filename(),
63  level_states()
64  {}
65  std::string filename;
66  std::vector<LevelState> level_states;
67 };
68 
69 class Savegame final
70 {
71 public:
72  static std::unique_ptr<Savegame> from_profile(int profile, const std::string& world_name, bool base_data = false);
73  static std::unique_ptr<Savegame> from_current_profile(const std::string& world_name, bool base_data = false);
74 
75 public:
76  Savegame(Profile& profile, const std::string& world_name);
77 
78  Profile& get_profile() const { return m_profile; }
79  std::string get_filename() const;
80 
82  PlayerStatus& get_player_status() const { return *m_player_status; }
83 
84  std::string get_title() const;
85 
86  std::vector<std::string> get_levelsets();
87  LevelsetState get_levelset_state(const std::string& name);
88  void set_levelset_state(const std::string& basedir,
89  const std::string& level_filename,
90  bool solved);
91 
92  std::vector<std::string> get_worldmaps();
93  WorldmapState get_worldmap_state(const std::string& name);
94 
95  void save();
96 
97  bool is_title_screen() const;
98 
99 private:
100  void load(bool base_data = false);
101  void clear_state_table();
102 
103 private:
104  Profile& m_profile;
105  std::string m_world_name;
106  std::unique_ptr<PlayerStatus> m_player_status;
107  ssq::Table m_state_table;
108 
109 private:
110  Savegame(const Savegame&) = delete;
111  Savegame& operator=(const Savegame&) = delete;
112 };
113 
114 #endif
115 
116 /* EOF */
This class keeps player status between different game sessions (for example when switching maps in th...
Definition: player_status.hpp:39
PlayerStatus & get_player_status() const
Returns content of (tux ...) entry.
Definition: savegame.hpp:82
Definition: savegame.hpp:30
Definition: savegame.hpp:44
Definition: savegame.hpp:69
Definition: savegame.hpp:58
Contains general data about a profile, which preserves savegames.
Definition: profile.hpp:26