[12177] | 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 <iostream> |
---|
| 46 | #include <fstream> |
---|
| 47 | #include "core/class/OrxonoxInterface.h" |
---|
| 48 | |
---|
| 49 | namespace orxonox // tolua_export |
---|
| 50 | { // tolua_export |
---|
| 51 | |
---|
| 52 | /** |
---|
| 53 | @brief |
---|
| 54 | The LevelInfoItem class stores information regarding a @ref orxonox::Level "Level" and makes that information accessible through the @ref orxonox::LevelManager "LevelManager". |
---|
| 55 | A LevelInfoItem object is commonly created from a @ref orxonox::LevelInfo "LevelInfo" object, using its <code>copy()</code> method. |
---|
| 56 | |
---|
| 57 | @author |
---|
| 58 | Damian 'Mozork' Frick |
---|
| 59 | |
---|
| 60 | @ingroup Orxonox |
---|
| 61 | */ |
---|
| 62 | class _OrxonoxExport LevelInfoItem // tolua_export |
---|
| 63 | : virtual public OrxonoxInterface |
---|
| 64 | { // tolua_export |
---|
| 65 | public: |
---|
| 66 | LevelInfoItem(); //!< Default constructor. |
---|
| 67 | LevelInfoItem(const std::string& name, const std::string filename); //!< Constructor. Initializes the object. |
---|
| 68 | virtual ~LevelInfoItem(); //!< Destructor. |
---|
| 69 | |
---|
| 70 | /** |
---|
| 71 | @brief Set the name of the Level. |
---|
| 72 | @param name The name to be set. |
---|
| 73 | */ |
---|
| 74 | inline void setName(const std::string& name) |
---|
| 75 | { this->name_ = std::string(name); } |
---|
| 76 | /** |
---|
| 77 | @brief Get the name of the Level. |
---|
| 78 | @return Returns the name of the Level. |
---|
| 79 | */ |
---|
| 80 | inline const std::string& getName(void) const { return this->name_; } // tolua_export |
---|
| 81 | |
---|
| 82 | /** |
---|
| 83 | @brief Set the screenshot of the Level. |
---|
| 84 | @param screenshot The screenshot to be set. |
---|
| 85 | */ |
---|
| 86 | inline void setScreenshot(const std::string& screenshot) { this->screenshot_ = std::string(screenshot); } |
---|
| 87 | /** |
---|
| 88 | @brief Get the screenshot of the Level. |
---|
| 89 | @return Returns the screenshot of the Level. |
---|
| 90 | */ |
---|
| 91 | inline const std::string& getScreenshot() const { return this->screenshot_; } // tolua_export |
---|
| 92 | |
---|
| 93 | /** |
---|
| 94 | @brief Set the description of the Level. |
---|
| 95 | @param description The description to be set. |
---|
| 96 | */ |
---|
| 97 | inline void setDescription(const std::string& description) |
---|
| 98 | { this->description_ = std::string(description); } |
---|
| 99 | /** |
---|
| 100 | @brief Get the description of the Level. |
---|
| 101 | @return Returns the description of the Level. |
---|
| 102 | */ |
---|
| 103 | inline const std::string& getDescription() const { return this->description_; } // tolua_export |
---|
| 104 | |
---|
| 105 | void setTags(const std::string& tags); //!< Set the tags the Level is tagged with. |
---|
| 106 | bool addTag(const std::string& tag, bool update = true); //!< Add a tag to the set of tags the Level is tagged with. |
---|
| 107 | /** |
---|
| 108 | @brief Get the lis of the tags the Level is tagged with. |
---|
| 109 | @return Returns a comma-seperated string of all the tags the Level is tagged with. |
---|
| 110 | */ |
---|
| 111 | inline const std::string& getTags(void) const |
---|
| 112 | { return this->tagsString_; } |
---|
| 113 | /** |
---|
| 114 | @brief Get whether the Level has a specific tag. |
---|
| 115 | @param tag The tag for which is checked. |
---|
| 116 | @return Returns true if the Level is tagged with the input tag. |
---|
| 117 | */ |
---|
| 118 | inline bool hasTag(const std::string& tag) const { return this->tags_.find(tag) != this->tags_.end(); } // tolua_export |
---|
| 119 | |
---|
| 120 | void setStartingShips(const std::string& ships); //!< Set the starting ship models of the level |
---|
| 121 | bool addStartingShip(const std::string& ship, bool update = true); //!< Add a model to shipselection |
---|
| 122 | /** |
---|
| 123 | @brief Get the set of starting ship models the Level allows |
---|
| 124 | @return Returns a comma-seperated string of all the allowed ship models for the shipselection. |
---|
| 125 | */ |
---|
| 126 | inline const std::string& getStartingShips(void) const |
---|
| 127 | { return this->startingShipsString_; } |
---|
| 128 | /** |
---|
| 129 | @brief Get whether the Level allows a specific starting ship model |
---|
| 130 | @param ship The ship model for which is checked. |
---|
| 131 | @return Returns true if the Level allows the input ship model |
---|
| 132 | */ |
---|
| 133 | inline bool hasStartingShip(const std::string& ship) const { return this->startingShips_.find(ship) != this->startingShips_.end(); } // tolua_export |
---|
| 134 | inline void selectStartingShip(const std::string& ship) { this->changeStartingShip(ship); } // tolua_export |
---|
| 135 | inline void selectSOBlevel(const std::string& ship) { this->changeStartingLevel(ship); } // tolua_export |
---|
| 136 | /** |
---|
| 137 | @brief Get the XML-filename of the Level. |
---|
| 138 | @return Returns the XML-filename (including *.oxw extension) of the Level. |
---|
| 139 | */ |
---|
| 140 | inline const std::string& getXMLFilename(void) const { return this->xmlfilename_; } // tolua_export |
---|
| 141 | |
---|
| 142 | |
---|
| 143 | protected: |
---|
| 144 | /** |
---|
| 145 | @brief Set the XML-filename of the Level. |
---|
| 146 | @param filename The XML-filename to be set. |
---|
| 147 | */ |
---|
| 148 | inline void setXMLFilename(const std::string& filename) |
---|
| 149 | { this->xmlfilename_ = std::string(filename); } |
---|
| 150 | |
---|
| 151 | std::string xmlfilename_; //!< The XML-filename of the Level. |
---|
| 152 | |
---|
| 153 | private: |
---|
| 154 | void changeStartingShip (const std::string& model); |
---|
| 155 | void changeStartingLevel (const std::string& model); |
---|
| 156 | void startingshipsUpdated(void); //!< Updates the comma-seperated string of all possible starting ships. |
---|
| 157 | void tagsUpdated(void); //!< Updates the comma-seperated string of all tags, if the set of tags has changed. |
---|
| 158 | static void initializeTags(void); //!< Initialize the set of allowed tags. |
---|
| 159 | /** |
---|
| 160 | @brief Check whether an input tag is allowed. |
---|
| 161 | @param tag The tag to check. |
---|
| 162 | @return Returns true if the input tag is allowed, false if not. |
---|
| 163 | */ |
---|
| 164 | static bool validateTag(const std::string& tag) |
---|
| 165 | { LevelInfoItem::initializeTags(); return LevelInfoItem::possibleTags_s.find(tag) != LevelInfoItem::possibleTags_s.end(); } |
---|
| 166 | |
---|
| 167 | static std::set<std::string> possibleTags_s; //!< The set of allowed tags. |
---|
| 168 | static const bool initialized_s = false; //!< Whether the set of allowed tags has been inizialized. |
---|
| 169 | |
---|
| 170 | std::string name_; //!< The name of the Level. |
---|
| 171 | std::string description_; //!< The description of the Level. |
---|
| 172 | std::string screenshot_; //!< The screenshot of the Level. |
---|
| 173 | std::set<std::string> tags_; //!< The set of tags the Level is tagged with. |
---|
| 174 | std::string tagsString_; //!< The comma-seperated string of all the tags the Level is tagged with. |
---|
| 175 | std::set<std::string> startingShips_; //!< The set of starting ship models the Level allows. |
---|
| 176 | std::string startingShipsString_; //!< The comma-seperated string of all the allowed ship models for the shipselection. |
---|
| 177 | }; // tolua_export |
---|
| 178 | |
---|
| 179 | /** |
---|
| 180 | @brief |
---|
| 181 | The LevelInfo class can be used to store information regarding a @ref orxonox::Level "Level" in its level file. |
---|
| 182 | The following parameters can be specified: |
---|
| 183 | - @b name The name of the level. |
---|
| 184 | - @b description The description of the level. |
---|
| 185 | - @b screenshot The screenshot of the level. |
---|
| 186 | - @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>. |
---|
| 187 | - @b (optional) startingships The comma-seperated string of starting ship models |
---|
| 188 | An example would be: |
---|
| 189 | @code |
---|
| 190 | <LevelInfo |
---|
| 191 | name = "Levelname"lhs->compare(rhs) < 0 |
---|
| 192 | description = "This is just some awesome level." |
---|
| 193 | screenshot = "Screenshot.png" |
---|
| 194 | tags = "test, awesome" |
---|
| 195 | /> |
---|
| 196 | @endcode |
---|
| 197 | The LevelInfo is best located at the top of the level file. |
---|
| 198 | |
---|
| 199 | @author |
---|
| 200 | Damian 'Mozork' Frick |
---|
| 201 | Matthias Hutter |
---|
| 202 | @ingroup Orxonox |
---|
| 203 | */ |
---|
| 204 | class _OrxonoxExport LevelInfo : public BaseObject, public LevelInfoItem |
---|
| 205 | { |
---|
| 206 | public: |
---|
| 207 | LevelInfo(Context* context); |
---|
| 208 | virtual ~LevelInfo(); |
---|
| 209 | |
---|
| 210 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override; //!< Creates a LevelInfo object through XML. |
---|
| 211 | |
---|
| 212 | /** |
---|
| 213 | @brief Set the screenshot of the Level. |
---|
| 214 | @param screenshot The screenshot to be set. |
---|
| 215 | */ |
---|
| 216 | inline void setScreenshot(const std::string& screenshot) { this->LevelInfoItem::setScreenshot(screenshot); } |
---|
| 217 | /** |
---|
| 218 | @brief Get the screenshot of the Level. |
---|
| 219 | @return Returns the screenshot of the Level. |
---|
| 220 | */ |
---|
| 221 | inline const std::string& getScreenshot() const { return this->LevelInfoItem::getScreenshot(); } |
---|
| 222 | |
---|
| 223 | /** |
---|
| 224 | @brief Set the description of the Level. |
---|
| 225 | @param description The description to be set. |
---|
| 226 | */ |
---|
| 227 | inline void setDescription(const std::string& description) |
---|
| 228 | { this->LevelInfoItem::setDescription(description); } |
---|
| 229 | /** |
---|
| 230 | @brief Get the description of the Level. |
---|
| 231 | @return Returns the description of the Level. |
---|
| 232 | */ |
---|
| 233 | inline const std::string& getDescription() const |
---|
| 234 | { return this->LevelInfoItem::getDescription(); } |
---|
| 235 | |
---|
| 236 | /** |
---|
| 237 | @brief Set the tags the Level is tagged with. |
---|
| 238 | @param tags A comma-seperated string of all the tags to be set. |
---|
| 239 | */ |
---|
| 240 | inline void setTags(const std::string& tags) |
---|
| 241 | { this->LevelInfoItem::setTags(tags); } |
---|
| 242 | /** |
---|
| 243 | @brief Get the lis of the tags the Level is tagged with. |
---|
| 244 | @return Returns a comma-seperated string of all the tags the Level is tagged with. |
---|
| 245 | */ |
---|
| 246 | inline const std::string& getTags(void) const |
---|
| 247 | { return this->LevelInfoItem::getTags(); } |
---|
| 248 | /** |
---|
| 249 | @brief Set the starting ship models of the level |
---|
| 250 | @param ships A comma-seperated string of all the allowed ship models for the shipselection. |
---|
| 251 | */ |
---|
| 252 | inline void setStartingShips(const std::string& ships) |
---|
| 253 | { this->LevelInfoItem::setStartingShips(ships); } |
---|
| 254 | /** |
---|
| 255 | @brief Get the starting ship models of the level |
---|
| 256 | @return Returns a comma-seperated string of all the allowed ship models for the shipselection. |
---|
| 257 | */ |
---|
| 258 | inline const std::string& getStartingShips(void) const |
---|
| 259 | { return this->LevelInfoItem::getStartingShips(); } |
---|
| 260 | |
---|
| 261 | LevelInfoItem* copy(void); //!< Copies the contents of this LevelInfo object to a new LevelInfoItem object. |
---|
| 262 | }; |
---|
| 263 | |
---|
| 264 | /** |
---|
| 265 | @brief |
---|
| 266 | Struct that overloads the compare operation between two @ref orxonox::LevelInfoItem "LevelInfoItem" pointers. |
---|
| 267 | |
---|
| 268 | @ingroup Orxonox |
---|
| 269 | */ |
---|
| 270 | struct LevelInfoCompare |
---|
| 271 | { |
---|
| 272 | bool operator() (const LevelInfoItem* lhs, const LevelInfoItem* rhs) const |
---|
| 273 | { |
---|
| 274 | if(getLowercase(lhs->getName()).compare(getLowercase(rhs->getName())) == 0) |
---|
| 275 | return getLowercase(lhs->getXMLFilename()).compare(getLowercase(rhs->getXMLFilename())) < 0; |
---|
| 276 | return getLowercase(lhs->getName()).compare(getLowercase(rhs->getName())) < 0; |
---|
| 277 | } |
---|
| 278 | }; |
---|
| 279 | |
---|
| 280 | } // tolua_export |
---|
| 281 | |
---|
| 282 | #endif /* _LevelInfo_H__ */ |
---|