1 | // SuperTux |
2 | // Copyright (C) 2006 Matthias Braun <matze@braunis.de> |
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 | #ifndef HEADER_SUPERTUX_SUPERTUX_LEVEL_HPP |
18 | #define |
19 | |
20 | #include "supertux/statistics.hpp" |
21 | |
22 | class ReaderMapping; |
23 | class Sector; |
24 | class Writer; |
25 | |
26 | /** Represents a collection of Sectors running in a single GameSession. |
27 | |
28 | Each Sector in turn contains GameObjects, e.g. Badguys and Players. */ |
29 | class Level final |
30 | { |
31 | friend class LevelParser; |
32 | |
33 | public: |
34 | static Level* current() { return s_current; } |
35 | |
36 | private: |
37 | static Level* s_current; |
38 | |
39 | public: |
40 | Level(bool m_is_worldmap); |
41 | ~Level(); |
42 | |
43 | // saves to a levelfile |
44 | void save(const std::string& filename, bool retry = false); |
45 | void save(std::ostream& stream); |
46 | |
47 | void add_sector(std::unique_ptr<Sector> sector); |
48 | const std::string& get_name() const { return m_name; } |
49 | const std::string& get_author() const { return m_author; } |
50 | |
51 | Sector* get_sector(const std::string& name) const; |
52 | |
53 | size_t get_sector_count() const; |
54 | Sector* get_sector(size_t num) const; |
55 | |
56 | std::string get_tileset() const { return m_tileset; } |
57 | |
58 | int get_total_coins() const; |
59 | int get_total_badguys() const; |
60 | int get_total_secrets() const; |
61 | |
62 | void reactivate(); |
63 | |
64 | bool is_worldmap() const { return m_is_worldmap; } |
65 | |
66 | private: |
67 | void save(Writer& writer); |
68 | void load_old_format(const ReaderMapping& reader); |
69 | |
70 | public: |
71 | bool m_is_worldmap; |
72 | std::string m_name; |
73 | std::string m_author; |
74 | std::string m_contact; |
75 | std::string m_license; |
76 | std::string m_filename; |
77 | std::vector<std::unique_ptr<Sector> > m_sectors; |
78 | Statistics m_stats; |
79 | float m_target_time; |
80 | std::string m_tileset; |
81 | |
82 | private: |
83 | Level(const Level&) = delete; |
84 | Level& operator=(const Level&) = delete; |
85 | }; |
86 | |
87 | #endif |
88 | |
89 | /* EOF */ |
90 | |