Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2011/src/orxonox/LevelInfo.h @ 9045

Last change on this file since 9045 was 8977, checked in by smerkli, 13 years ago

Merged menue

  • Property svn:eol-style set to native
File size: 9.9 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 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            /**
119            @brief Get the XML-filename of the Level.
120            @return Returns the XML-filename (including *.oxw extension) of the Level.
121            */
122            inline const std::string& getXMLFilename(void) const { return this->xmlfilename_; } // tolua_export
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
134        private:
135            void tagsUpdated(void); //!< Updates the comma-seperated string of all tags, if the set of tags has changed.
136
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
149            std::string name_; //!< The name of the Level.
150            std::string description_; //!< The description of the Level.
151            std::string screenshot_; //!< The screenshot of the Level.
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.
154    }; // tolua_export
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.
162        - @b screenshot The screenshot of the level.
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>.
164
165        An example would be:
166        @code
167        <LevelInfo
168            name = "Levelname"lhs->compare(rhs) < 0
169            description = "This is just some awesome level."
170            screenshot = "Screenshot.png"
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
178
179    @ingroup Orxonox
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.
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(); }
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    };
229
230    /**
231    @brief
232        Struct that overloads the compare operation between two @ref orxonox::LevelInfoItem "LevelInfoItem" pointers.
233
234    @ingroup Orxonox
235    */
236    struct LevelInfoCompare
237    {
238        bool operator() (const LevelInfoItem* lhs, const LevelInfoItem* rhs) const
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            }
244    };
245   
246} // tolua_export
247
248#endif /* _LevelInfo_H__ */
Note: See TracBrowser for help on using the repository browser.