Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Introducing LevelInfo class, which can be used to specify things about a Level and which is used to provide more flexibility in displaying a list of levels.
Basic functionality works, now all that needs to be dones is to exploit the new functionality.

File size: 7.1 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
43#include "core/BaseObject.h"
44#include "core/OrxonoxClass.h"
45
46namespace orxonox
47{
48
49    /**
50    @brief
51        The LevelInfoItem class stores information regarding a @ref orxonox::Level "Level" and makes that information it accessible trough the @ref orxonox::LevelManager "LevelManager".
52        A LevelInfoItem object is commonly created from a @ref orxonox::LevelInfo "LevelInfo" object, using its <code>copy()</code> method.
53
54    @author
55        Damian 'Mozork' Frick
56    */
57    class _OrxonoxExport LevelInfoItem : virtual public OrxonoxClass
58    {
59        public:
60            LevelInfoItem(); //!< Default constructor.
61            LevelInfoItem(const std::string& name, const std::string filename); //!< Constructor. Initializes the object.
62            virtual ~LevelInfoItem(); //!< Destructor.
63
64            /**
65            @brief Set the name of the Level.
66            @param name The name to be set.
67            */
68            inline void setName(const std::string& name)
69                { this->name_ = std::string(name); }
70            /**
71            @brief Get the name of the Level.
72            @return Returns the name of the Level.
73            */
74            inline const std::string& getName(void)
75                { return this->name_; }
76
77            /**
78            @brief Set the description of the Level.
79            @param description The description to be set.
80            */
81            inline void setDescription(const std::string& description)
82                { this->description_ = std::string(description); }
83            /**
84            @brief Get the description of the Level.
85            @return Returns the description of the Level.
86            */
87            inline const std::string& getDescription() const
88                { return this->description_; }
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            bool hasTag(const std::string& tag) const
104                { return this->tags_.find(tag) != this->tags_.end(); }
105
106            /**
107            @brief Get the XML-filename of the Level.
108            @return Returns the XML-filename (including *.oxw extension) of the Level.
109            */
110            inline const std::string& getXMLFilename(void)
111                { return this->xmlfilename_; }
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            std::string name_; //!< The name of the Level.
127            std::string description_; //!< The description of the Level.
128            std::set<std::string> tags_; //!< The set of tags the Level is tagged with.
129            std::string tagsString_; //!< The comma-seperated string of all the tags the Level is tagged with.
130    };
131
132    /**
133    @brief
134        The LevelInfo class can be used to store information regarding a @ref orxonox::Level "Level" in its level file.
135        The following parameters can be specified:
136        - @b name The name of the level.
137        - @b description The description of the level.
138        - @b tags A comma-seperated string of tags.
139
140        An example would be:
141        @code
142        <LevelInfo
143            name = "Levelname"
144            description = "This is just some awesome level."
145            tags = "test, awesome"
146        />
147        @endcode
148        The LevelInfo is best located at the top of the level file.
149
150    @author
151        Damian 'Mozork' Frick
152    */
153    class _OrxonoxExport LevelInfo : public BaseObject, public LevelInfoItem
154    {
155        public:
156            LevelInfo(BaseObject* creator);
157            virtual ~LevelInfo();
158
159            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Creates a LevelInfo object through XML.
160
161            /**
162            @brief Set the description of the Level.
163            @param description The description to be set.
164            */
165            inline void setDescription(const std::string& description)
166                { this->LevelInfoItem::setDescription(description); }
167            /**
168            @brief Get the description of the Level.
169            @return Returns the description of the Level.
170            */
171            inline const std::string& getDescription() const
172                { return this->LevelInfoItem::getDescription(); }
173
174            /**
175            @brief Set the tags the Level is tagged with.
176            @param tags A comma-seperated string of all the tags to be set.
177            */
178            inline void setTags(const std::string& tags)
179                { this->LevelInfoItem::setTags(tags); }
180            /**
181            @brief Get the lis of the tags the Level is tagged with.
182            @return Returns a comma-seperated string of all the tags the Level is tagged with.
183            */
184            inline const std::string& getTags(void) const
185                { return this->LevelInfoItem::getTags(); }
186
187            LevelInfoItem* copy(void); //!< Copies the contents of this LevelInfo object to a new LevelInfoItem object.
188
189    };
190}
191
192#endif /* _LevelInfo_H__ */
Note: See TracBrowser for help on using the repository browser.