savegame.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. #ifndef HEADER_SUPERTUX_SUPERTUX_SAVEGAME_HPP
  18. #define HEADER_SUPERTUX_SUPERTUX_SAVEGAME_HPP
  19. #include <memory>
  20. #include <string>
  21. #include <vector>
  22. class PlayerStatus;
  23. class Profile;
  24. struct LevelState
  25. {
  26. public:
  27. LevelState() :
  28. filename(),
  29. solved(false),
  30. perfect(false)
  31. {}
  32. std::string filename;
  33. bool solved;
  34. bool perfect;
  35. };
  36. struct LevelsetState
  37. {
  38. public:
  39. LevelsetState() :
  40. directory(),
  41. level_states()
  42. {}
  43. std::string directory;
  44. std::vector<LevelState> level_states;
  45. LevelState get_level_state(const std::string& filename) const;
  46. void store_level_state(const LevelState& state);
  47. };
  48. struct WorldmapState
  49. {
  50. public:
  51. WorldmapState() :
  52. filename(),
  53. level_states()
  54. {}
  55. std::string filename;
  56. std::vector<LevelState> level_states;
  57. };
  58. class Savegame final
  59. {
  60. public:
  61. static std::unique_ptr<Savegame> from_profile(int profile, const std::string& world_name, bool base_data = false);
  62. static std::unique_ptr<Savegame> from_current_profile(const std::string& world_name, bool base_data = false);
  63. public:
  64. Savegame(Profile& profile, const std::string& world_name);
  65. Profile& get_profile() const { return m_profile; }
  66. std::string get_filename() const;
  67. /** Returns content of (tux ...) entry */
  68. PlayerStatus& get_player_status() const { return *m_player_status; }
  69. std::string get_title() const;
  70. std::vector<std::string> get_levelsets();
  71. LevelsetState get_levelset_state(const std::string& name);
  72. void set_levelset_state(const std::string& basedir,
  73. const std::string& level_filename,
  74. bool solved);
  75. std::vector<std::string> get_worldmaps();
  76. WorldmapState get_worldmap_state(const std::string& name);
  77. void save();
  78. bool is_title_screen() const;
  79. private:
  80. void load(bool base_data = false);
  81. void clear_state_table();
  82. private:
  83. Profile& m_profile;
  84. std::string m_world_name;
  85. std::unique_ptr<PlayerStatus> m_player_status;
  86. private:
  87. Savegame(const Savegame&) = delete;
  88. Savegame& operator=(const Savegame&) = delete;
  89. };
  90. #endif
  91. /* EOF */