tmxlite
lightweight Tiled tmx map parser for C++
Map.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_MAP_HPP_
29 #define TMXLITE_MAP_HPP_
30 
31 #include <tmxlite/Tileset.hpp>
32 #include <tmxlite/Layer.hpp>
33 #include <tmxlite/Property.hpp>
34 #include <tmxlite/Types.hpp>
35 
36 #include <string>
37 #include <vector>
38 
39 namespace tmx
40 {
44  struct TMXLITE_EXPORT_API Version
45  {
46  //major/minor are apparently reserved by gcc
47  std::uint16_t upper;
48  std::uint16_t lower;
49  Version(std::uint16_t maj = 0, std::uint16_t min = 0)
50  : upper(maj), lower(min) {}
51  };
52 
53  enum class Orientation
54  {
55  Orthogonal,
56  Isometric,
57  Staggered,
58  Hexagonal,
59  None
60  };
61 
62  enum class RenderOrder
63  {
64  RightDown,
65  RightUp,
66  LeftDown,
67  LeftUp,
68  None
69  };
70 
71  enum class StaggerAxis
72  {
73  X, Y, None
74  };
75 
76  enum class StaggerIndex
77  {
78  Even, Odd, None
79  };
80 
90  class TMXLITE_EXPORT_API Map final
91  {
92  public:
93 
94  Map();
95  ~Map() = default;
96  Map(const Map&) = delete;
97  Map& operator = (const Map&) = delete;
98  Map(Map&&) = default;
99  Map& operator = (Map&&) = default;
100 
107  bool load(const std::string&);
108 
113  const Version& getVersion() const { return m_version; }
118  Orientation getOrientation() const { return m_orientation; }
123  RenderOrder getRenderOrder() const { return m_renderOrder; }
127  const Vector2u& getTileCount() const { return m_tileCount; }
133  const Vector2u& getTileSize() const { return m_tileSize; }
137  FloatRect getBounds() const { return FloatRect(0.f, 0.f, static_cast<float>(m_tileCount.x * m_tileSize.x), static_cast<float>(m_tileCount.y * m_tileSize.y)); }
146  float getHexSideLength() const { return m_hexSideLength; }
152  StaggerAxis getStaggerAxis() const { return m_staggerAxis; }
158  StaggerIndex getStaggerIndex() const { return m_staggerIndex; }
162  const Colour& getBackgroundColour() const { return m_backgroundColour; }
166  const std::vector<Tileset>& getTilesets() const { return m_tilesets; }
173  const std::vector<Layer::Ptr>& getLayers() const { return m_layers; }
177  const std::vector<Property>& getProperties() const { return m_properties; }
178 
179 
180  private:
181  Version m_version;
182  Orientation m_orientation;
183  RenderOrder m_renderOrder;
184 
185  Vector2u m_tileCount;
186  Vector2u m_tileSize;
187 
188  float m_hexSideLength;
189  StaggerAxis m_staggerAxis;
190  StaggerIndex m_staggerIndex;
191 
192  Colour m_backgroundColour;
193 
194  std::string m_workingDirectory;
195 
196  std::vector<Tileset> m_tilesets;
197  std::vector<Layer::Ptr> m_layers;
198  std::vector<Property> m_properties;
199 
200  //always returns false so we can return this
201  //on load failure
202  bool reset();
203 
204  struct Key {};
205  };
206 }
207 #endif //TMXLITE_MAP_HPP_
float getHexSideLength() const
Returns the length of an edge of a tile if a Hexagonal map is loaded. The length returned is in pixel...
Definition: Map.hpp:146
Definition: Log.hpp:58
const Version & getVersion() const
Returns the version of the tile map last parsed. If no tile map has yet been parsed the version will ...
Definition: Map.hpp:113
StaggerAxis getStaggerAxis() const
Stagger axis of the map. If either a Staggered or Hexagonal tile map is loaded this returns which axi...
Definition: Map.hpp:152
Orientation getOrientation() const
Returns the orientation of the map if one is loaded, else returns None.
Definition: Map.hpp:118
FloatRect getBounds() const
Returns the bounds of the map.
Definition: Map.hpp:137
Contains the red, green, blue and alpha values of a colour in the range 0 - 255.
Definition: Types.hpp:109
const Vector2u & getTileSize() const
Returns the size of the tile grid in this map. Actual tile sizes may vary and will be extended / shru...
Definition: Map.hpp:133
Parser for TMX format tile maps. This class can be used to parse the XML format tile maps created wit...
Definition: Map.hpp:90
const std::vector< Property > & getProperties() const
Returns a vector of Property objects loaded by the map.
Definition: Map.hpp:177
const Vector2u & getTileCount() const
Returns the tile count of the map in the X and Y directions.
Definition: Map.hpp:127
Holds the xml version of the loaded map.
Definition: Map.hpp:44
StaggerIndex getStaggerIndex() const
Stagger Index of the loaded map. If a Staggered or Hexagonal map is loaded this returns whether the e...
Definition: Map.hpp:158
const std::vector< Layer::Ptr > & getLayers() const
Returns a reference to the vector containing the layer data. Layers are pointer-to-baseclass, the concrete type of which can be found via Layer::getType()
Definition: Map.hpp:173
const std::vector< Tileset > & getTilesets() const
Returns a reference to the vector of tile sets used by the map.
Definition: Map.hpp:166
const Colour & getBackgroundColour() const
Returns the background colour of the map.
Definition: Map.hpp:162
RenderOrder getRenderOrder() const
Returns the RenderOrder of the map if one is loaded, else returns None.
Definition: Map.hpp:123