tmxlite
lightweight Tiled tmx map parser for C++
Layer.hpp
1 /*********************************************************************
2 Matt Marchant 2016
3 http://trederia.blogspot.com
4 
5 tmxlite - Zlib license.
6 
7 This software is provided 'as-is', without any express or
8 implied warranty. In no event will the authors be held
9 liable for any damages arising from the use of this software.
10 
11 Permission is granted to anyone to use this software for any purpose,
12 including commercial applications, and to alter it and redistribute
13 it freely, subject to the following restrictions:
14 
15 1. The origin of this software must not be misrepresented;
16 you must not claim that you wrote the original software.
17 If you use this software in a product, an acknowledgment
18 in the product documentation would be appreciated but
19 is not required.
20 
21 2. Altered source versions must be plainly marked as such,
22 and must not be misrepresented as being the original software.
23 
24 3. This notice may not be removed or altered from any
25 source distribution.
26 *********************************************************************/
27 
28 #ifndef TMXLITE_LAYER_HPP_
29 #define TMXLITE_LAYER_HPP_
30 
31 #include <tmxlite/Config.hpp>
32 #include <tmxlite/Property.hpp>
33 #include <tmxlite/Types.hpp>
34 
35 #include <string>
36 #include <memory>
37 #include <vector>
38 
39 namespace pugi
40 {
41  class xml_node;
42 }
43 
44 namespace tmx
45 {
46  class Map;
52  class TMXLITE_EXPORT_API Layer
53  {
54  public:
55  using Ptr = std::unique_ptr<Layer>;
56 
57  explicit Layer() : m_opacity(1.f), m_visible(true) {};
58  virtual ~Layer() = default;
59 
60  enum class Type
61  {
62  Tile,
63  Object,
64  Image
65  };
66 
70  virtual Type getType() const = 0;
74  virtual void parse(const pugi::xml_node&) = 0;
78  const std::string& getName() const { return m_name; }
82  float getOpacity() const { return m_opacity; }
86  bool getVisible() const { return m_visible; }
91  const Vector2i& getOffset() const { return m_offset; }
95  const std::vector<Property>& getProperties() const { return m_properties; }
96 
97  protected:
98 
99  void setName(const std::string& name) { m_name = name; }
100  void setOpacity(float opacity) { m_opacity = opacity; }
101  void setVisible(bool visible) { m_visible = visible; }
102  void setOffset(std::int32_t x, std::int32_t y) { m_offset = Vector2i(x, y); }
103  void addProperty(const pugi::xml_node& node) { m_properties.emplace_back(); m_properties.back().parse(node); }
104 
105  private:
106  std::string m_name;
107  float m_opacity;
108  bool m_visible;
109  Vector2i m_offset;
110 
111  std::vector<Property> m_properties;
112  };
113 }
114 
115 #endif //TMXLITE_LAYER_HPP_
Definition: Log.hpp:58
bool getVisible() const
Returns whether this layer is visible or not.
Definition: Layer.hpp:86
const Vector2i & getOffset() const
Returns the offset from the top left corner of the layer, in pixels.
Definition: Layer.hpp:91
Represents a layer of a tmx format tile map. This is an abstract base class from which all layer type...
Definition: Layer.hpp:52
Objects are stored in ObjectGroup layers. Objects may be rectangular, elliptical, polygonal or a poly...
Definition: Object.hpp:82
const std::string & getName() const
Returns the name of the layer.
Definition: Layer.hpp:78
float getOpacity() const
Returns the opacity value for the layer.
Definition: Layer.hpp:82
const std::vector< Property > & getProperties() const
Returns the list of properties of this layer.
Definition: Layer.hpp:95
Definition: Layer.hpp:39