Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 6, 2010, 8:17:20 PM (15 years ago)
Author:
dafrick
Message:

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:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/releasetodo/src/orxonox/LevelInfo.h

    r7614 r7625  
    2727 */
    2828
     29/**
     30    @file LevelInfo.h
     31    @brief Definition of the LevelInfo and LevelInfoItem class.
     32    @ingroup Orxonox
     33*/
     34
    2935#ifndef _LevelInfo_H__
    3036#define _LevelInfo_H__
     
    3440#include <set>
    3541#include <string>
     42
    3643#include "core/BaseObject.h"
     44#include "core/OrxonoxClass.h"
    3745
    38 namespace orxonox // tolua_export
    39 {  // tolua_export
    40     class _OrxonoxExport LevelInfo  // tolua_export
    41         : public BaseObject
    42     { // tolua_export
    43    
     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    {
    44155        public:
    45156            LevelInfo(BaseObject* creator);
    46157            virtual ~LevelInfo();
    47            
    48             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    49158
     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            */
    50165            inline void setDescription(const std::string& description)
    51                 { this->description_ = description; }
    52             inline const std::string& getDescription() const // tolua_export
    53                 { return this->description_; }
    54                
    55             void setTags(const std::string& tags);
    56             inline bool addTag(const std::string& tag)
    57                 { bool success = this->tags_.insert(tag).second; if(success) this->tagsUpdated(); return success; }
     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            */
    58184            inline const std::string& getTags(void) const
    59                 { return this->tagsString_; }
    60             bool hasTag(const std::string& tag) { return this->tags_.find(tag) != this->tags_.end(); } // tolua_export
    61            
    62         private:
    63             void tagsUpdated(void);
    64        
    65             std::string description_;
    66             std::set<std::string> tags_;
    67             std::string tagsString_;
    68            
    69     }; // tolua_export
    70 } // tolua_export
     185                { return this->LevelInfoItem::getTags(); }
    71186
    72 #endif /* _Level_H__ */
     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 TracChangeset for help on using the changeset viewer.