Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/releasetodo/src/orxonox/LevelInfo.h @ 7638

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

Adding restriction to possible tags.

File size: 7.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 <map>
41#include <set>
42#include <string>
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) { 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 std::set<std::string> possibleTags_s;
125            static const bool initialized_s = false;
126            void initializeTags(void);
127            bool validateTag(const std::string& tag)
128                { this->initializeTags(); return LevelInfoItem::possibleTags_s.find(tag) != LevelInfoItem::possibleTags_s.end(); }
129
130            std::string name_; //!< The name of the Level.
131            std::string description_; //!< The description of the Level.
132            std::set<std::string> tags_; //!< The set of tags the Level is tagged with.
133            std::string tagsString_; //!< The comma-seperated string of all the tags the Level is tagged with.
134    }; // tolua_export
135
136    /**
137    @brief
138        The LevelInfo class can be used to store information regarding a @ref orxonox::Level "Level" in its level file.
139        The following parameters can be specified:
140        - @b name The name of the level.
141        - @b description The description of the level.
142        - @b tags A comma-seperated string of tags.
143
144        An example would be:
145        @code
146        <LevelInfo
147            name = "Levelname"
148            description = "This is just some awesome level."
149            tags = "test, awesome"
150        />
151        @endcode
152        The LevelInfo is best located at the top of the level file.
153
154    @author
155        Damian 'Mozork' Frick
156    */
157    class _OrxonoxExport LevelInfo : public BaseObject, public LevelInfoItem
158    {
159        public:
160            LevelInfo(BaseObject* creator);
161            virtual ~LevelInfo();
162
163            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates a LevelInfo object through XML.
164
165            /**
166            @brief Set the description of the Level.
167            @param description The description to be set.
168            */
169            inline void setDescription(const std::string& description)
170                { this->LevelInfoItem::setDescription(description); }
171            /**
172            @brief Get the description of the Level.
173            @return Returns the description of the Level.
174            */
175            inline const std::string& getDescription() const
176                { return this->LevelInfoItem::getDescription(); }
177
178            /**
179            @brief Set the tags the Level is tagged with.
180            @param tags A comma-seperated string of all the tags to be set.
181            */
182            inline void setTags(const std::string& tags)
183                { this->LevelInfoItem::setTags(tags); }
184            /**
185            @brief Get the lis of the tags the Level is tagged with.
186            @return Returns a comma-seperated string of all the tags the Level is tagged with.
187            */
188            inline const std::string& getTags(void) const
189                { return this->LevelInfoItem::getTags(); }
190
191            LevelInfoItem* copy(void); //!< Copies the contents of this LevelInfo object to a new LevelInfoItem object.
192
193    };
194} // tolua_export
195
196#endif /* _LevelInfo_H__ */
Note: See TracBrowser for help on using the repository browser.