tmxlite 1.0.0
lightweight parse for Tiled maps
ObjectGroup.hpp
1/*********************************************************************
2Matt Marchant 2016 - 2022
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/Layer.hpp>
32#include <tmxlite/Object.hpp>
33
34#include <vector>
35
36namespace tmx
37{
42 class TMXLITE_EXPORT_API ObjectGroup final : public Layer
43 {
44 public:
45 enum class DrawOrder
46 {
47 Index, //< objects should be drawn in the order in which they appear
48 TopDown //< objects should be drawn sorted by their Y position
49 };
50
52
53 Type getType() const override { return Layer::Type::Object; }
54 void parse(const pugi::xml_node&, Map*) override;
55
59 const Colour& getColour() const { return m_colour; }
60
65 DrawOrder getDrawOrder() const { return m_drawOrder; }
66
71 const std::vector<Property>& getProperties() const { return m_properties; }
72
76 const std::vector<Object>& getObjects() const { return m_objects; }
77
78 private:
79 Colour m_colour;
80 DrawOrder m_drawOrder;
81
82 std::vector<Property> m_properties;
83 std::vector<Object> m_objects;
84 };
85
86 template <>
87 inline ObjectGroup& Layer::getLayerAs<ObjectGroup>()
88 {
89 assert(getType() == Type::Object);
90 return *static_cast<ObjectGroup*>(this);
91 }
92
93 template <>
94 inline const ObjectGroup& Layer::getLayerAs<ObjectGroup>() const
95 {
96 assert(getType() == Type::Object);
97 return *static_cast<const ObjectGroup*>(this);
98 }
99}
Represents a layer of a tmx format tile map. This is an abstract base class from which all layer type...
Definition Layer.hpp:56
T & getLayerAs()
Use this to get a reference to the concrete layer type which this layer points to....
Type
Layer type as returned by getType() Tile: this layer is a TileLayer type Object: This layer is an Obj...
Definition Layer.hpp:71
virtual Type getType() const =0
Returns a Type value representing the concrete type. Use this when deciding which conrete layer type ...
Parser for TMX format tile maps. This class can be used to parse the XML format tile maps created wit...
Definition Map.hpp:94
ObjectGroup layers contain a series of Objects which may be made up of shapes or images.
Definition ObjectGroup.hpp:43
DrawOrder getDrawOrder() const
Returns the DrawOrder for the objects in this group. Defaults to TopDown, where Objects are drawn sor...
Definition ObjectGroup.hpp:65
const Colour & getColour() const
Returns the colour associated with this layer.
Definition ObjectGroup.hpp:59
const std::vector< Object > & getObjects() const
Returns a reference to the vector of Objects which belong to the group.
Definition ObjectGroup.hpp:76
void parse(const pugi::xml_node &, Map *) override
Attempts to parse the specific node layer type.
Type getType() const override
Returns a Type value representing the concrete type. Use this when deciding which conrete layer type ...
Definition ObjectGroup.hpp:53
const std::vector< Property > & getProperties() const
Returns a reference to the vector of properties for the ObjectGroup.
Definition ObjectGroup.hpp:71
Contains the red, green, blue and alpha values of a colour in the range 0 - 255.
Definition Types.hpp:111