tmxlite 1.0.0
lightweight parse for Tiled maps
Object.hpp
1/*********************************************************************
2(c) Matt 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/Property.hpp>
32#include <tmxlite/Types.hpp>
33
34#include <string>
35#include <vector>
36
37namespace pugi
38{
39 class xml_node;
40}
41
42namespace tmx
43{
44 class Map;
45
49 struct TMXLITE_EXPORT_API Text final
50 {
51 std::string fontFamily;
52 std::uint32_t pixelSize = 16;
53 bool wrap = false;
54 Colour colour;
55 bool bold = false;
56 bool italic = false;
57 bool underline = false;
58 bool strikethough = false;
59 bool kerning = true;
60
61 enum class HAlign
62 {
63 Left, Centre, Right
64 }hAlign = HAlign::Left;
65
66 enum class VAlign
67 {
68 Top, Centre, Bottom
69 }vAlign = VAlign::Top;
70
71 std::string content;
72 };
73
83 class TMXLITE_EXPORT_API Object final
84 {
85 public:
86 enum class Shape
87 {
89 Ellipse,
90 Point,
91 Polygon,
92 Polyline,
93 Text
94 };
95
96 Object();
97
102 void parse(const pugi::xml_node&, Map*);
103
107 std::uint32_t getUID() const { return m_UID; }
108
112 const std::string& getName() const { return m_name; }
113
117 const std::string& getType() const { return m_class; }
118
122 const std::string& getClass() const { return m_class; }
123
127 const Vector2f& getPosition() const { return m_position; }
128
135 const FloatRect& getAABB() const { return m_AABB; }
136
140 float getRotation() const { return m_rotation; }
141
147 std::uint32_t getTileID() const { return m_tileID; }
148
154 std::uint8_t getFlipFlags() const { return m_flipFlags; }
155
159 bool visible() const { return m_visible; }
160
164 Shape getShape() const { return m_shape; }
165
172 const std::vector<Vector2f>& getPoints() const { return m_points; }
173
178 const std::vector<Property>& getProperties() const { return m_properties; }
179
187 const Text& getText() const { return m_textData; }
188 Text& getText() { return m_textData; }
189
196 const std::string& getTilesetName() const { return m_tilesetName; }
197
198 private:
199 std::uint32_t m_UID;
200 std::string m_name;
201 std::string m_class;
202 Vector2f m_position;
203 FloatRect m_AABB;
204 float m_rotation;
205 std::uint32_t m_tileID;
206 std::uint8_t m_flipFlags;
207 bool m_visible;
208
209 Shape m_shape;
210 std::vector<Vector2f> m_points;
211 std::vector<Property> m_properties;
212
213 Text m_textData;
214
215 std::string m_tilesetName;
216
217 void parsePoints(const pugi::xml_node&);
218 void parseText(const pugi::xml_node&);
219 void parseTemplate(const std::string&, Map*);
220 };
221}
Parser for TMX format tile maps. This class can be used to parse the XML format tile maps created wit...
Definition Map.hpp:94
Objects are stored in ObjectGroup layers. Objects may be rectangular, elliptical, polygonal or a poly...
Definition Object.hpp:84
void parse(const pugi::xml_node &, Map *)
Attempts to parse the given xml node and read the Object properties if it is valid.
const FloatRect & getAABB() const
Returns the global Axis Aligned Bounding Box. The AABB is positioned via the left and top properties,...
Definition Object.hpp:135
float getRotation() const
Returns the rotation of the Object in degrees clockwise.
Definition Object.hpp:140
bool visible() const
Returns whether or not the Object is visible.
Definition Object.hpp:159
std::uint32_t getUID() const
Returns the unique ID of the Object.
Definition Object.hpp:107
const std::string & getClass() const
Returns the class (equal to type) of the Object, as defined in the editor Tiled 1....
Definition Object.hpp:122
const Vector2f & getPosition() const
Returns the position of the Object in pixels.
Definition Object.hpp:127
const std::vector< Property > & getProperties() const
Returns a reference to the vector of properties belonging to the Object.
Definition Object.hpp:178
const std::string & getTilesetName() const
Returns the tileset name used by this object if it is derived from a template, else returns an empty ...
Definition Object.hpp:196
std::uint8_t getFlipFlags() const
Returns the flip flags if the objects uses a TileID to draw it. Returns 0 otherwise.
Definition Object.hpp:154
const std::vector< Vector2f > & getPoints() const
Returns a reference to the vector of points which make up the Object. If the Object is rectangular or...
Definition Object.hpp:172
const std::string & getName() const
Returns the name of the Object.
Definition Object.hpp:112
const Text & getText() const
Returns a Text struct containing information about any text this object may have, such as font data a...
Definition Object.hpp:187
std::uint32_t getTileID() const
Returns the global tile ID associated with the Object if there is one. This is used to draw the Objec...
Definition Object.hpp:147
Shape getShape() const
Returns the Shape type of the Object.
Definition Object.hpp:164
const std::string & getType() const
Returns the type (equal to class) of the Object, as defined in the editor Tiled < 1....
Definition Object.hpp:117
Contains the red, green, blue and alpha values of a colour in the range 0 - 255.
Definition Types.hpp:111
Describes a rectangular area, such as an AABB (axis aligned bounding box)
Definition Types.hpp:96
Contains the text information stored in a Text object.
Definition Object.hpp:50
std::string content
actual string content
Definition Object.hpp:71