Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7802 was 7802, checked in by dafrick, 13 years ago

Making the level list in the LevelManager (and as consequence the level list displayed by the GUI) alphabetically sorted. Also some cleanup and documented LevelManager.

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