Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/hudimprovements/src/orxonox/LevelInfo.h @ 8365

Last change on this file since 8365 was 7804, checked in by dafrick, 14 years ago

Some more minor changes in documentation.

  • Property svn:eol-style set to native
File size: 8.5 KB
Line 
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
47namespace 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 description of the Level.
82            @param description The description to be set.
83            */
84            inline void setDescription(const std::string& description)
85                { this->description_ = std::string(description); }
86            /**
87            @brief Get the description of the Level.
88            @return Returns the description of the Level.
89            */
90            inline const std::string& getDescription() const { return this->description_; } // tolua_export
91
92            void setTags(const std::string& tags); //!< Set the tags the Level is tagged with.
93            bool addTag(const std::string& tag, bool update = true); //!< Add a tag to the set of tags the Level is tagged with.
94            /**
95            @brief Get the lis of the tags the Level is tagged with.
96            @return Returns a comma-seperated string of all the tags the Level is tagged with.
97            */
98            inline const std::string& getTags(void) const
99                { return this->tagsString_; }
100            /**
101            @brief Get whether the Level has a specific tag.
102            @param tag The tag for which is checked.
103            @return Returns true if the Level is tagged with the input tag.
104            */
105            inline bool hasTag(const std::string& tag) const { return this->tags_.find(tag) != this->tags_.end(); } // tolua_export
106
107            /**
108            @brief Get the XML-filename of the Level.
109            @return Returns the XML-filename (including *.oxw extension) of the Level.
110            */
111            inline const std::string& getXMLFilename(void) { return this->xmlfilename_; } // tolua_export
112
113        protected:
114            /**
115            @brief Set the XML-filename of the Level.
116            @param filename The XML-filename to be set.
117            */
118            inline void setXMLFilename(const std::string& filename)
119                { this->xmlfilename_ = std::string(filename); }
120
121            std::string xmlfilename_; //!< The XML-filename of the Level.
122
123        private:
124            void tagsUpdated(void); //!< Updates the comma-seperated string of all tags, if the set of tags has changed.
125
126            static void initializeTags(void); //!< Initialize the set of allowed tags.
127            /**
128            @brief Check whether an input tag is allowed.
129            @param tag The tag to check.
130            @return Returns true if the input tag is allowed, false if not.
131            */
132            static bool validateTag(const std::string& tag)
133                { LevelInfoItem::initializeTags(); return LevelInfoItem::possibleTags_s.find(tag) != LevelInfoItem::possibleTags_s.end(); }
134
135            static std::set<std::string> possibleTags_s; //!< The set of allowed tags.
136            static const bool initialized_s = false; //!< Whether the set of allowed tags has been inizialized.
137
138            std::string name_; //!< The name of the Level.
139            std::string description_; //!< The description of the Level.
140            std::set<std::string> tags_; //!< The set of tags the Level is tagged with.
141            std::string tagsString_; //!< The comma-seperated string of all the tags the Level is tagged with.
142    }; // tolua_export
143
144    /**
145    @brief
146        The LevelInfo class can be used to store information regarding a @ref orxonox::Level "Level" in its level file.
147        The following parameters can be specified:
148        - @b name The name of the level.
149        - @b description The description of the level.
150        - @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>.
151
152        An example would be:
153        @code
154        <LevelInfo
155            name = "Levelname"lhs->compare(rhs) < 0
156            description = "This is just some awesome level."
157            tags = "test, awesome"
158        />
159        @endcode
160        The LevelInfo is best located at the top of the level file.
161
162    @author
163        Damian 'Mozork' Frick
164
165    @ingroup Orxonox
166    */
167    class _OrxonoxExport LevelInfo : public BaseObject, public LevelInfoItem
168    {
169        public:
170            LevelInfo(BaseObject* creator);
171            virtual ~LevelInfo();
172
173            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates a LevelInfo object through XML.
174
175            /**
176            @brief Set the description of the Level.
177            @param description The description to be set.
178            */
179            inline void setDescription(const std::string& description)
180                { this->LevelInfoItem::setDescription(description); }
181            /**
182            @brief Get the description of the Level.
183            @return Returns the description of the Level.
184            */
185            inline const std::string& getDescription() const
186                { return this->LevelInfoItem::getDescription(); }
187
188            /**
189            @brief Set the tags the Level is tagged with.
190            @param tags A comma-seperated string of all the tags to be set.
191            */
192            inline void setTags(const std::string& tags)
193                { this->LevelInfoItem::setTags(tags); }
194            /**
195            @brief Get the lis of the tags the Level is tagged with.
196            @return Returns a comma-seperated string of all the tags the Level is tagged with.
197            */
198            inline const std::string& getTags(void) const
199                { return this->LevelInfoItem::getTags(); }
200
201            LevelInfoItem* copy(void); //!< Copies the contents of this LevelInfo object to a new LevelInfoItem object.
202
203    };
204
205    /**
206    @brief
207        Struct that overloads the compare operation between two @ref orxonox::LevelInfoItem "LevelInfoItem" pointers.
208
209    @ingroup Orxonox
210    */
211    struct LevelInfoCompare
212    {
213        bool operator() (const LevelInfoItem* lhs, const LevelInfoItem* rhs) const
214            { return getLowercase(lhs->getName()).compare(getLowercase(rhs->getName())) < 0; }
215    };
216   
217} // tolua_export
218
219#endif /* _LevelInfo_H__ */
Note: See TracBrowser for help on using the repository browser.