tmxlite 1.0.0
lightweight parse for Tiled maps
Property.hpp
1/*********************************************************************
2Matt Marchant 2016 - 2021
3http://trederia.blogspot.com
4
5tmxlite - Zlib license.
6
7This software is provided 'as-is', without any express or
8implied warranty. In no event will the authors be held
9liable for any damages arising from the use of this software.
10
11Permission is granted to anyone to use this software for any purpose,
12including commercial applications, and to alter it and redistribute
13it freely, subject to the following restrictions:
14
151. The origin of this software must not be misrepresented;
16you must not claim that you wrote the original software.
17If you use this software in a product, an acknowledgment
18in the product documentation would be appreciated but
19is not required.
20
212. Altered source versions must be plainly marked as such,
22and must not be misrepresented as being the original software.
23
243. This notice may not be removed or altered from any
25source distribution.
26*********************************************************************/
27
28#pragma once
29
30#include <tmxlite/Config.hpp>
31#include <tmxlite/Types.hpp>
32
33#include <string>
34#include <cassert>
35
36namespace pugi
37{
38 class xml_node;
39}
40
41namespace tmx
42{
50 class TMXLITE_EXPORT_API Property final
51 {
52 public:
53
54 enum class Type
55 {
56 Boolean,
57 Float,
58 Int,
59 String,
60 Colour,
61 File,
62 Object,
63 Undef
64 };
65
66 Property();
67
68 static Property fromBoolean(bool value);
69 static Property fromFloat(float value);
70 static Property fromInt(int value);
71 static Property fromString(const std::string& value);
72 static Property fromColour(const Colour& value);
73 static Property fromFile(const std::string& value);
74 static Property fromObject(int value);
75
80 void parse(const pugi::xml_node&, bool isObjectTypes = false);
81
88 Type getType() const { return m_type; }
89
93 const std::string& getName() const { return m_name; }
94
98 bool getBoolValue() const { assert(m_type == Type::Boolean); return m_boolValue; }
99
103 float getFloatValue() const { assert(m_type == Type::Float); return m_floatValue; }
104
108 int getIntValue() const { assert(m_type == Type::Int || m_type == Type::Object); return m_intValue; }
109
113 const std::string& getStringValue() const { assert(m_type == Type::String); return m_stringValue; }
114
118 const Colour& getColourValue() const { assert(m_type == Type::Colour); return m_colourValue; }
119
123 const std::string& getFileValue() const { assert(m_type == Type::File); return m_stringValue; }
124
128 int getObjectValue() const { assert(m_type == Type::Object); return m_intValue; }
129
130
131 private:
132 union
133 {
134 bool m_boolValue;
135 float m_floatValue;
136 int m_intValue;
137 };
138 std::string m_stringValue;
139 std::string m_name;
140 Colour m_colourValue;
141
142 Type m_type;
143 };
144}
Objects are stored in ObjectGroup layers. Objects may be rectangular, elliptical, polygonal or a poly...
Definition Object.hpp:84
Represents a custom property. Tiles, objects and layers of a tmx map may have custom properties assig...
Definition Property.hpp:51
float getFloatValue() const
Returns the property's value as a float.
Definition Property.hpp:103
void parse(const pugi::xml_node &, bool isObjectTypes=false)
Attempts to parse the given node as a property.
bool getBoolValue() const
Returns the property's value as a boolean.
Definition Property.hpp:98
const std::string & getStringValue() const
Returns the property's value as a string.
Definition Property.hpp:113
const Colour & getColourValue() const
Returns the property's value as a Colour struct.
Definition Property.hpp:118
int getObjectValue() const
Returns the property's value as an integer object handle.
Definition Property.hpp:128
const std::string & getFileValue() const
Returns the file path property as a string, relative to the map file.
Definition Property.hpp:123
Type getType() const
Returns the type of data stored in the property. This should generally be called first before trying ...
Definition Property.hpp:88
int getIntValue() const
Returns the property's value as an integer.
Definition Property.hpp:108
const std::string & getName() const
Returns the name of this property.
Definition Property.hpp:93
Contains the red, green, blue and alpha values of a colour in the range 0 - 255.
Definition Types.hpp:111