1 | /* |
---|
2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
3 | * > www.orxonox.net < |
---|
4 | * |
---|
5 | * |
---|
6 | * License notice: |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or |
---|
9 | * modify it under the terms of the GNU General Public License |
---|
10 | * as published by the Free Software Foundation; either version 2 |
---|
11 | * of the License, or (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
21 | * |
---|
22 | * Author: |
---|
23 | * Damian 'Mozork' Frick |
---|
24 | * Co-authors: |
---|
25 | * ... |
---|
26 | * |
---|
27 | */ |
---|
28 | |
---|
29 | /** |
---|
30 | @file LevelInfo.h |
---|
31 | @brief Definition of the LevelInfo and LevelInfoItem class. |
---|
32 | @ingroup Orxonox |
---|
33 | */ |
---|
34 | |
---|
35 | #ifndef _LevelInfo_H__ |
---|
36 | #define _LevelInfo_H__ |
---|
37 | |
---|
38 | #include "OrxonoxPrereqs.h" |
---|
39 | |
---|
40 | #include <set> |
---|
41 | #include <string> |
---|
42 | #include "util/StringUtils.h" |
---|
43 | |
---|
44 | #include "core/BaseObject.h" |
---|
45 | #include "core/OrxonoxClass.h" |
---|
46 | |
---|
47 | namespace orxonox // tolua_export |
---|
48 | { // tolua_export |
---|
49 | |
---|
50 | /** |
---|
51 | @brief |
---|
52 | The LevelInfoItem class stores information regarding a @ref orxonox::Level "Level" and makes that information accessible through the @ref orxonox::LevelManager "LevelManager". |
---|
53 | A LevelInfoItem object is commonly created from a @ref orxonox::LevelInfo "LevelInfo" object, using its <code>copy()</code> method. |
---|
54 | |
---|
55 | @author |
---|
56 | Damian 'Mozork' Frick |
---|
57 | |
---|
58 | @ingroup Orxonox |
---|
59 | */ |
---|
60 | class _OrxonoxExport LevelInfoItem // tolua_export |
---|
61 | : virtual public OrxonoxClass |
---|
62 | { // tolua_export |
---|
63 | public: |
---|
64 | LevelInfoItem(); //!< Default constructor. |
---|
65 | LevelInfoItem(const std::string& name, const std::string filename); //!< Constructor. Initializes the object. |
---|
66 | virtual ~LevelInfoItem(); //!< Destructor. |
---|
67 | |
---|
68 | /** |
---|
69 | @brief Set the name of the Level. |
---|
70 | @param name The name to be set. |
---|
71 | */ |
---|
72 | inline void setName(const std::string& name) |
---|
73 | { this->name_ = std::string(name); } |
---|
74 | /** |
---|
75 | @brief Get the name of the Level. |
---|
76 | @return Returns the name of the Level. |
---|
77 | */ |
---|
78 | inline const std::string& getName(void) const { return this->name_; } // tolua_export |
---|
79 | |
---|
80 | /** |
---|
81 | @brief Set the screenshot of the Level. |
---|
82 | @param screenshot The screenshot to be set. |
---|
83 | */ |
---|
84 | inline void setScreenshot(const std::string& screenshot) { this->screenshot_ = std::string(screenshot); } |
---|
85 | /** |
---|
86 | @brief Get the screenshot of the Level. |
---|
87 | @return Returns the screenshot of the Level. |
---|
88 | */ |
---|
89 | inline const std::string& getScreenshot() const { return this->screenshot_; } // tolua_export |
---|
90 | |
---|
91 | /** |
---|
92 | @brief Set the description of the Level. |
---|
93 | @param description The description to be set. |
---|
94 | */ |
---|
95 | inline void setDescription(const std::string& description) |
---|
96 | { this->description_ = std::string(description); } |
---|
97 | /** |
---|
98 | @brief Get the description of the Level. |
---|
99 | @return Returns the description of the Level. |
---|
100 | */ |
---|
101 | inline const std::string& getDescription() const { return this->description_; } // tolua_export |
---|
102 | |
---|
103 | void setTags(const std::string& tags); //!< Set the tags the Level is tagged with. |
---|
104 | bool addTag(const std::string& tag, bool update = true); //!< Add a tag to the set of tags the Level is tagged with. |
---|
105 | /** |
---|
106 | @brief Get the lis of the tags the Level is tagged with. |
---|
107 | @return Returns a comma-seperated string of all the tags the Level is tagged with. |
---|
108 | */ |
---|
109 | inline const std::string& getTags(void) const |
---|
110 | { return this->tagsString_; } |
---|
111 | /** |
---|
112 | @brief Get whether the Level has a specific tag. |
---|
113 | @param tag The tag for which is checked. |
---|
114 | @return Returns true if the Level is tagged with the input tag. |
---|
115 | */ |
---|
116 | inline bool hasTag(const std::string& tag) const { return this->tags_.find(tag) != this->tags_.end(); } // tolua_export |
---|
117 | |
---|
118 | void setShips(const std::string& ships); //!< Set the starting ship models of the level |
---|
119 | bool addShip(const std::string& ship, bool update = true); //!< Add a model to shipselection |
---|
120 | /** |
---|
121 | @brief Get the set of starting ship models the Level allows |
---|
122 | @return Returns a comma-seperated string of all the allowed ship models for the shipselection. |
---|
123 | */ |
---|
124 | inline const std::string& getShips(void) const |
---|
125 | { return this->startingShipsString_; } |
---|
126 | /** |
---|
127 | @brief Get whether the Level allows a specific starting ship model |
---|
128 | @param ship The ship model for which is checked. |
---|
129 | @return Returns true if the Level allows the input ship model |
---|
130 | */ |
---|
131 | inline bool hasShip(const std::string& ship) const { return this->ships_.find(ship) != this->ships_.end(); } // tolua_export |
---|
132 | /** |
---|
133 | @brief Get the XML-filename of the Level. |
---|
134 | @return Returns the XML-filename (including *.oxw extension) of the Level. |
---|
135 | */ |
---|
136 | |
---|
137 | inline const std::string& getXMLFilename(void) const { return this->xmlfilename_; } // tolua_export |
---|
138 | |
---|
139 | protected: |
---|
140 | /** |
---|
141 | @brief Set the XML-filename of the Level. |
---|
142 | @param filename The XML-filename to be set. |
---|
143 | */ |
---|
144 | inline void setXMLFilename(const std::string& filename) |
---|
145 | { this->xmlfilename_ = std::string(filename); } |
---|
146 | |
---|
147 | std::string xmlfilename_; //!< The XML-filename of the Level. |
---|
148 | |
---|
149 | private: |
---|
150 | void tagsUpdated(void); //!< Updates the comma-seperated string of all tags, if the set of tags has changed. |
---|
151 | void shipsUpdated(void); //!< Updates the comma-seperated string of all tags, if the set of tags has changed. |
---|
152 | static void initializeTags(void); //!< Initialize the set of allowed tags. |
---|
153 | /** |
---|
154 | @brief Check whether an input tag is allowed. |
---|
155 | @param tag The tag to check. |
---|
156 | @return Returns true if the input tag is allowed, false if not. |
---|
157 | */ |
---|
158 | static bool validateTag(const std::string& tag) |
---|
159 | { LevelInfoItem::initializeTags(); return LevelInfoItem::possibleTags_s.find(tag) != LevelInfoItem::possibleTags_s.end(); } |
---|
160 | |
---|
161 | static std::set<std::string> possibleTags_s; //!< The set of allowed tags. |
---|
162 | static const bool initialized_s = false; //!< Whether the set of allowed tags has been inizialized. |
---|
163 | |
---|
164 | std::string name_; //!< The name of the Level. |
---|
165 | std::string description_; //!< The description of the Level. |
---|
166 | std::string screenshot_; //!< The screenshot of the Level. |
---|
167 | std::set<std::string> tags_; //!< The set of tags the Level is tagged with. |
---|
168 | std::string tagsString_; //!< The comma-seperated string of all the tags the Level is tagged with. |
---|
169 | std::set<std::string> ships_; //!< The set of starting ship models the Level allows. |
---|
170 | std::string startingShipsString_; //!< The comma-seperated string of all the allowed ship models for the shipselection. |
---|
171 | }; // tolua_export |
---|
172 | |
---|
173 | /** |
---|
174 | @brief |
---|
175 | The LevelInfo class can be used to store information regarding a @ref orxonox::Level "Level" in its level file. |
---|
176 | The following parameters can be specified: |
---|
177 | - @b name The name of the level. |
---|
178 | - @b description The description of the level. |
---|
179 | - @b screenshot The screenshot of the level. |
---|
180 | - @b tags A comma-seperated string of tags. Allowed tags are: <em>test</em>, <em>singleplayer</em>, <em>multiplayer</em>, <em>showcase</em>, <em>tutorial</em>, <em>presentation</em>, <em>shipselection</em>. |
---|
181 | - @b (optional) startingships The comma-seperated string of starting ship models |
---|
182 | An example would be: |
---|
183 | @code |
---|
184 | <LevelInfo |
---|
185 | name = "Levelname"lhs->compare(rhs) < 0 |
---|
186 | description = "This is just some awesome level." |
---|
187 | screenshot = "Screenshot.png" |
---|
188 | tags = "test, awesome" |
---|
189 | /> |
---|
190 | @endcode |
---|
191 | The LevelInfo is best located at the top of the level file. |
---|
192 | |
---|
193 | @author |
---|
194 | Damian 'Mozork' Frick |
---|
195 | @edit |
---|
196 | Matthias Hutter |
---|
197 | @ingroup Orxonox |
---|
198 | */ |
---|
199 | class _OrxonoxExport LevelInfo : public BaseObject, public LevelInfoItem |
---|
200 | { |
---|
201 | public: |
---|
202 | LevelInfo(BaseObject* creator); |
---|
203 | virtual ~LevelInfo(); |
---|
204 | |
---|
205 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates a LevelInfo object through XML. |
---|
206 | |
---|
207 | /** |
---|
208 | @brief Set the screenshot of the Level. |
---|
209 | @param screenshot The screenshot to be set. |
---|
210 | */ |
---|
211 | inline void setScreenshot(const std::string& screenshot) { this->LevelInfoItem::setScreenshot(screenshot); } |
---|
212 | /** |
---|
213 | @brief Get the screenshot of the Level. |
---|
214 | @return Returns the screenshot of the Level. |
---|
215 | */ |
---|
216 | inline const std::string& getScreenshot() const { return this->LevelInfoItem::getScreenshot(); } |
---|
217 | |
---|
218 | /** |
---|
219 | @brief Set the description of the Level. |
---|
220 | @param description The description to be set. |
---|
221 | */ |
---|
222 | inline void setDescription(const std::string& description) |
---|
223 | { this->LevelInfoItem::setDescription(description); } |
---|
224 | /** |
---|
225 | @brief Get the description of the Level. |
---|
226 | @return Returns the description of the Level. |
---|
227 | */ |
---|
228 | inline const std::string& getDescription() const |
---|
229 | { return this->LevelInfoItem::getDescription(); } |
---|
230 | |
---|
231 | /** |
---|
232 | @brief Set the tags the Level is tagged with. |
---|
233 | @param tags A comma-seperated string of all the tags to be set. |
---|
234 | */ |
---|
235 | inline void setTags(const std::string& tags) |
---|
236 | { this->LevelInfoItem::setTags(tags); } |
---|
237 | /** |
---|
238 | @brief Get the lis of the tags the Level is tagged with. |
---|
239 | @return Returns a comma-seperated string of all the tags the Level is tagged with. |
---|
240 | */ |
---|
241 | inline const std::string& getTags(void) const |
---|
242 | { return this->LevelInfoItem::getTags(); } |
---|
243 | /** |
---|
244 | @brief Set the starting ship models of the level |
---|
245 | @param A comma-seperated string of all the allowed ship models for the shipselection. |
---|
246 | */ |
---|
247 | inline void setShips(const std::string& ships) |
---|
248 | { this->LevelInfoItem::setShips(ships); } |
---|
249 | /** |
---|
250 | @brief Get the starting ship models of the level |
---|
251 | @return Returns a comma-seperated string of all the allowed ship models for the shipselection. |
---|
252 | */ |
---|
253 | inline const std::string& getShips(void) const |
---|
254 | { return this->LevelInfoItem::getShips(); } |
---|
255 | LevelInfoItem* copy(void); //!< Copies the contents of this LevelInfo object to a new LevelInfoItem object. |
---|
256 | }; |
---|
257 | |
---|
258 | /** |
---|
259 | @brief |
---|
260 | Struct that overloads the compare operation between two @ref orxonox::LevelInfoItem "LevelInfoItem" pointers. |
---|
261 | |
---|
262 | @ingroup Orxonox |
---|
263 | */ |
---|
264 | struct LevelInfoCompare |
---|
265 | { |
---|
266 | bool operator() (const LevelInfoItem* lhs, const LevelInfoItem* rhs) const |
---|
267 | { |
---|
268 | if(getLowercase(lhs->getName()).compare(getLowercase(rhs->getName())) == 0) |
---|
269 | return getLowercase(lhs->getXMLFilename()).compare(getLowercase(rhs->getXMLFilename())) < 0; |
---|
270 | return getLowercase(lhs->getName()).compare(getLowercase(rhs->getName())) < 0; |
---|
271 | } |
---|
272 | }; |
---|
273 | |
---|
274 | } // tolua_export |
---|
275 | |
---|
276 | #endif /* _LevelInfo_H__ */ |
---|