Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/LevelInfo.h @ 9268

Last change on this file since 9268 was 9016, checked in by jo, 13 years ago

Merging presentation2011 branch to trunk. Please check for possible bugs.

  • Property svn:eol-style set to native
File size: 9.9 KB
RevLine 
[7614]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
[7625]29/**
30    @file LevelInfo.h
31    @brief Definition of the LevelInfo and LevelInfoItem class.
32    @ingroup Orxonox
33*/
34
[7614]35#ifndef _LevelInfo_H__
36#define _LevelInfo_H__
37
38#include "OrxonoxPrereqs.h"
39
40#include <set>
41#include <string>
[7802]42#include "util/StringUtils.h"
[7625]43
[7614]44#include "core/BaseObject.h"
[7625]45#include "core/OrxonoxClass.h"
[7614]46
[7626]47namespace orxonox // tolua_export
48{ // tolua_export
[7625]49
50    /**
51    @brief
[7804]52        The LevelInfoItem class stores information regarding a @ref orxonox::Level "Level" and makes that information accessible through the @ref orxonox::LevelManager "LevelManager".
[7625]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
[7804]57
58    @ingroup Orxonox
[7625]59    */
[7626]60    class _OrxonoxExport LevelInfoItem // tolua_export
61        : virtual public OrxonoxClass
62    { // tolua_export
[7614]63        public:
[7625]64            LevelInfoItem(); //!< Default constructor.
65            LevelInfoItem(const std::string& name, const std::string filename); //!< Constructor. Initializes the object.
66            virtual ~LevelInfoItem(); //!< Destructor.
[7614]67
[7625]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            */
[7802]78            inline const std::string& getName(void) const { return this->name_; } // tolua_export
[9016]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
[7625]90
91            /**
92            @brief Set the description of the Level.
93            @param description The description to be set.
94            */
[7614]95            inline void setDescription(const std::string& description)
[7625]96                { this->description_ = std::string(description); }
97            /**
98            @brief Get the description of the Level.
99            @return Returns the description of the Level.
100            */
[7626]101            inline const std::string& getDescription() const { return this->description_; } // tolua_export
[7625]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            */
[7614]109            inline const std::string& getTags(void) const
110                { return this->tagsString_; }
[7625]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            */
[7626]116            inline bool hasTag(const std::string& tag) const { return this->tags_.find(tag) != this->tags_.end(); } // tolua_export
[7625]117
118            /**
119            @brief Get the XML-filename of the Level.
120            @return Returns the XML-filename (including *.oxw extension) of the Level.
121            */
[8079]122            inline const std::string& getXMLFilename(void) const { return this->xmlfilename_; } // tolua_export
[7625]123
124        protected:
125            /**
126            @brief Set the XML-filename of the Level.
127            @param filename The XML-filename to be set.
128            */
129            inline void setXMLFilename(const std::string& filename)
130                { this->xmlfilename_ = std::string(filename); }
131
132            std::string xmlfilename_; //!< The XML-filename of the Level.
133
[7614]134        private:
[7625]135            void tagsUpdated(void); //!< Updates the comma-seperated string of all tags, if the set of tags has changed.
[7614]136
[7645]137            static void initializeTags(void); //!< Initialize the set of allowed tags.
138            /**
139            @brief Check whether an input tag is allowed.
140            @param tag The tag to check.
141            @return Returns true if the input tag is allowed, false if not.
142            */
143            static bool validateTag(const std::string& tag)
144                { LevelInfoItem::initializeTags(); return LevelInfoItem::possibleTags_s.find(tag) != LevelInfoItem::possibleTags_s.end(); }
145
146            static std::set<std::string> possibleTags_s; //!< The set of allowed tags.
147            static const bool initialized_s = false; //!< Whether the set of allowed tags has been inizialized.
148
[7625]149            std::string name_; //!< The name of the Level.
150            std::string description_; //!< The description of the Level.
[9016]151            std::string screenshot_; //!< The screenshot of the Level.
[7625]152            std::set<std::string> tags_; //!< The set of tags the Level is tagged with.
153            std::string tagsString_; //!< The comma-seperated string of all the tags the Level is tagged with.
[7626]154    }; // tolua_export
[7625]155
156    /**
157    @brief
158        The LevelInfo class can be used to store information regarding a @ref orxonox::Level "Level" in its level file.
159        The following parameters can be specified:
160        - @b name The name of the level.
161        - @b description The description of the level.
[9016]162        - @b screenshot The screenshot of the level.
[7645]163        - @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>.
[7625]164
165        An example would be:
166        @code
167        <LevelInfo
[7802]168            name = "Levelname"lhs->compare(rhs) < 0
[7625]169            description = "This is just some awesome level."
[9016]170            screenshot = "Screenshot.png"
[7625]171            tags = "test, awesome"
172        />
173        @endcode
174        The LevelInfo is best located at the top of the level file.
175
176    @author
177        Damian 'Mozork' Frick
[7804]178
179    @ingroup Orxonox
[7625]180    */
181    class _OrxonoxExport LevelInfo : public BaseObject, public LevelInfoItem
182    {
183        public:
184            LevelInfo(BaseObject* creator);
185            virtual ~LevelInfo();
186
187            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates a LevelInfo object through XML.
[9016]188       
189            /**
190            @brief Set the screenshot of the Level.
191            @param screenshot The screenshot to be set.
192            */
193            inline void setScreenshot(const std::string& screenshot) { this->LevelInfoItem::setScreenshot(screenshot); }
194            /**
195            @brief Get the screenshot of the Level.
196            @return Returns the screenshot of the Level.
197            */
198            inline const std::string& getScreenshot() const { return this->LevelInfoItem::getScreenshot(); }
[7625]199
200            /**
201            @brief Set the description of the Level.
202            @param description The description to be set.
203            */
204            inline void setDescription(const std::string& description)
205                { this->LevelInfoItem::setDescription(description); }
206            /**
207            @brief Get the description of the Level.
208            @return Returns the description of the Level.
209            */
210            inline const std::string& getDescription() const
211                { return this->LevelInfoItem::getDescription(); }
212
213            /**
214            @brief Set the tags the Level is tagged with.
215            @param tags A comma-seperated string of all the tags to be set.
216            */
217            inline void setTags(const std::string& tags)
218                { this->LevelInfoItem::setTags(tags); }
219            /**
220            @brief Get the lis of the tags the Level is tagged with.
221            @return Returns a comma-seperated string of all the tags the Level is tagged with.
222            */
223            inline const std::string& getTags(void) const
224                { return this->LevelInfoItem::getTags(); }
225
226            LevelInfoItem* copy(void); //!< Copies the contents of this LevelInfo object to a new LevelInfoItem object.
227
228    };
[7802]229
230    /**
231    @brief
232        Struct that overloads the compare operation between two @ref orxonox::LevelInfoItem "LevelInfoItem" pointers.
[7804]233
234    @ingroup Orxonox
[7802]235    */
236    struct LevelInfoCompare
237    {
238        bool operator() (const LevelInfoItem* lhs, const LevelInfoItem* rhs) const
[8079]239            {
240                if(getLowercase(lhs->getName()).compare(getLowercase(rhs->getName())) == 0)
241                    return getLowercase(lhs->getXMLFilename()).compare(getLowercase(rhs->getXMLFilename())) < 0;
242                return getLowercase(lhs->getName()).compare(getLowercase(rhs->getName())) < 0;
243            }
[7802]244    };
245   
[7626]246} // tolua_export
[7625]247
248#endif /* _LevelInfo_H__ */
Note: See TracBrowser for help on using the repository browser.