Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/releasetodo/src/orxonox/LevelInfo.cc @ 7627

Last change on this file since 7627 was 7626, checked in by dafrick, 15 years ago

Accidentally removed a file. Re-adding it.
Levels that are tagged with "test" are now not displayed by default, but can be displayed by choosing show all.

File size: 4.8 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#include "LevelInfo.h"
30
31#include <sstream>
32#include <vector>
33
34#include "util/SubString.h"
35#include "core/CoreIncludes.h"
36#include "core/XMLPort.h"
37
38#include "LevelManager.h"
39
40namespace orxonox
41{
42
43    // LevelInfoItem
44
45    /**
46    @brief
47        Default constructor.
48    */
49    LevelInfoItem::LevelInfoItem()
50    {
51
52    }
53
54    /**
55    @brief
56        Constructor. Initializes the object.
57    @param name
58        The name of the Level.
59    @param filename
60        The XML-filename of the Level.
61    */
62    LevelInfoItem::LevelInfoItem(const std::string& name, const std::string filename)
63    {
64        this->setName(name);
65        this->setXMLFilename(filename);
66    }
67
68    /**
69    @brief
70        Destructor.
71    */
72    LevelInfoItem::~LevelInfoItem()
73    {
74
75    }
76
77    /**
78    @brief
79        Set the tags the Level is tagged with.
80    @param tags
81        A comma-seperated string of all the tags to be set.
82    */
83    void LevelInfoItem::setTags(const std::string& tags)
84    {
85        SubString substr = SubString(tags, ",", " "); // Split the string into tags.
86        const std::vector<std::string>& strings = substr.getAllStrings();
87        for(std::vector<std::string>::const_iterator it = strings.begin(); it != strings.end(); it++)
88            this->addTag(*it, false);
89
90        this->tagsUpdated();
91    }
92
93    /**
94    @brief
95        Add a tag to the set of tags the Level is tagged with.
96    @param tag
97        The tag to be added.
98    @param update
99        Whether the comma-seperated string of all tags should be updated. Default is true.
100    @return
101        Returns true if the tag was successfully added, if the tag was already present it returns false.
102    */
103    bool LevelInfoItem::addTag(const std::string& tag, bool update)
104    {
105        bool success = this->tags_.insert(std::string(tag)).second;
106        if(update && success)
107            this->tagsUpdated();
108        return success;
109    }
110
111    /**
112    @brief
113        Updates the comma-seperated string of all tags, if the set of tags has changed.
114    */
115    void LevelInfoItem::tagsUpdated(void)
116    {
117        std::stringstream stream;
118        std::set<std::string>::iterator temp;
119        for(std::set<std::string>::iterator it = this->tags_.begin(); it != this->tags_.end(); )
120        {
121            temp = it;
122            if(++it == this->tags_.end()) // If this is the last tag we don't add a comma.
123                stream << *temp;
124            else
125                stream << *temp << ", ";
126        }
127
128        this->tagsString_ = std::string(stream.str());
129    }
130
131    // LevelInfo
132
133    CreateFactory(LevelInfo);
134
135    /**
136    @brief
137
138    @param creator
139        The creator of this object.
140    */
141    LevelInfo::LevelInfo(BaseObject* creator) : BaseObject(creator)
142    {
143        RegisterObject(LevelInfo);
144
145        this->xmlfilename_ = this->getFilename();
146    }
147
148    /**
149    @brief
150        Destructor.
151    */
152    LevelInfo::~LevelInfo()
153    {
154
155    }
156
157    /**
158    @brief
159        Creates a LevelInfo object through XML.
160    */
161    void LevelInfo::XMLPort(Element& xmlelement, XMLPort::Mode mode)
162    {
163        SUPER(LevelInfo, XMLPort, xmlelement, mode);
164
165        XMLPortParam(LevelInfo, "description", setDescription, getDescription, xmlelement, mode);
166        XMLPortParam(LevelInfo, "tags", setTags, getTags, xmlelement, mode);
167    }
168
169    /**
170    @brief
171        Copies the contents of this LevelInfo object to a new LevelInfoItem object.
172        This is needed, because a LeveInfo object is only created within the scope of the XML-file it is loaded with and is destroyed once that is unloaded.
173    @return
174        Returns a new LevelInfoItem with the same contents as the LevelInfo object.
175    */
176    LevelInfoItem* LevelInfo::copy(void)
177    {
178        LevelInfoItem* info = new LevelInfoItem(this->BaseObject::getName(), this->getXMLFilename());
179        info->setDescription(this->getDescription());
180        info->setTags(this->getTags());
181        return info;
182    }
183
184}
185
Note: See TracBrowser for help on using the repository browser.