Gamedev Framework (gf)  0.6.0
A C++11 framework for 2D games
Tmx.h
1 /*
2  * Gamedev Framework (gf)
3  * Copyright (C) 2016-2017 Julien Bernard
4  *
5  * This software is provided 'as-is', without any express or implied
6  * warranty. In no event will the authors be held liable for any damages
7  * arising from the use of this software.
8  *
9  * Permission is granted to anyone to use this software for any purpose,
10  * including commercial applications, and to alter it and redistribute it
11  * freely, subject to the following restrictions:
12  *
13  * 1. The origin of this software must not be misrepresented; you must not
14  * claim that you wrote the original software. If you use this software
15  * in a product, an acknowledgment in the product documentation would be
16  * appreciated but is not required.
17  * 2. Altered source versions must be plainly marked as such, and must not be
18  * misrepresented as being the original software.
19  * 3. This notice may not be removed or altered from any source distribution.
20  */
21 #ifndef GF_TMX_H
22 #define GF_TMX_H
23 
24 #include <cstdint>
25 
26 #include <map>
27 #include <memory>
28 #include <string>
29 #include <vector>
30 
31 #include "Flags.h"
32 #include "Id.h"
33 #include "Path.h"
34 #include "Portability.h"
35 #include "Rect.h"
36 #include "Time.h"
37 #include "Vector.h"
38 
39 namespace gf {
40 #ifndef DOXYGEN_SHOULD_SKIP_THIS
41 inline namespace v1 {
42 #endif
43  /**
44  * @ingroup game
45  * @brief The orientation of the map.
46  */
47  enum class TmxOrientation {
48  Unknown, ///< An unknown orientation
49  Orthogonal, ///< An orthogonal orientation
50  Isometric, ///< An isometric orientation
51  Staggered, ///< A staggered orientation
52  Hexagonal, ///< A hexagonal orientation
53  };
54 
55  /**
56  * @ingroup game
57  * @brief Stagger index of the hexagonal map.
58  */
59  enum class TmxStaggerIndex {
60  Odd, ///< A odd stagger index
61  Even, ///< An even stagger index
62  };
63 
64  /**
65  * @ingroup game
66  * @brief Stagger axis of the hexagonal map.
67  */
68  enum class TmxStaggerAxis {
69  X, ///< The x stagger axis
70  Y, ///< The y stagger axis
71  };
72 
73  /**
74  * @ingroup game
75  * @brief the render order of the tiles.
76  */
77  enum class TmxRenderOrder {
78  RightDown, ///< Right down order
79  RightUp, ///< Right up order
80  LeftDown, ///< Left down order
81  LeftUp, ///< Left up order
82  };
83 
84  /**
85  * @ingroup game
86  * @brief The properties for TMX entities
87  *
88  */
90  public:
91  /**
92  * @brief Default constructor
93  */
94  TmxProperties() = default;
95 
96  /**
97  * @brief Default move constructor
98  */
99  TmxProperties(TmxProperties&&) = default;
100 
101  /**
102  * @brief Default move assignment
103  */
104  TmxProperties& operator=(TmxProperties&&) = default;
105 
106  /**
107  * @brief Add a string property
108  *
109  * @param name The name of the property
110  * @param value The value of the property
111  */
112  void addStringProperty(std::string name, std::string value);
113 
114  /**
115  * @brief Add an integer property
116  *
117  * @param name The name of the property
118  * @param value The value of the property
119  */
120  void addIntProperty(std::string name, int value);
121 
122  /**
123  * @brief Add a float property
124  *
125  * @param name The name of the property
126  * @param value The value of the property
127  */
128  void addFloatProperty(std::string name, double value);
129 
130  /**
131  * @brief Add a boolean property
132  *
133  * @param name The name of the property
134  * @param value The value of the property
135  */
136  void addBoolProperty(std::string name, bool value);
137 
138  /**
139  * @brief Add a color property
140  *
141  * @param name The name of the property
142  * @param value The value of the property
143  */
144  void addColorProperty(std::string name, Color4u value);
145 
146  /**
147  * @brief Add a file property
148  *
149  * @param name The name of the property
150  * @param value The value of the property
151  */
152  void addFileProperty(std::string name, Path value);
153 
154  /**
155  * @brief Get a string property
156  *
157  * @param name The name of the property
158  * @param def The default value if the property does not exist
159  * @returns The value of the given property
160  */
161  std::string getStringProperty(const std::string& name, const std::string& def) const;
162 
163  /**
164  * @brief Get an integer property
165  *
166  * @param name The name of the property
167  * @param def The default value if the property does not exist
168  * @returns The value of the given property
169  */
170  int getIntProperty(const std::string& name, int def) const;
171 
172  /**
173  * @brief Get a float property
174  *
175  * @param name The name of the property
176  * @param def The default value if the property does not exist
177  * @returns The value of the given property
178  */
179  double getFloatProperty(const std::string& name, double def) const;
180 
181  /**
182  * @brief Get a boolean property
183  *
184  * @param name The name of the property
185  * @param def The default value if the property does not exist
186  * @returns The value of the given property
187  */
188  bool getBoolProperty(const std::string& name, bool def) const;
189 
190  /**
191  * @brief Get a color property
192  *
193  * @param name The name of the property
194  * @param def The default value if the property does not exist
195  * @returns The value of the given property
196  */
197  Color4u getColorProperty(const std::string& name, const Color4u& def) const;
198 
199  /**
200  * @brief Get a file property
201  *
202  * @param name The name of the property
203  * @param def The default value if the property does not exist
204  * @returns The value of the given property
205  */
206  Path getFileProperty(const std::string& name, const Path& def) const;
207 
208  private:
209  std::map<std::string, std::string> m_stringProps;
210  std::map<std::string, int> m_intProps;
211  std::map<std::string, double> m_floatProps;
212  std::map<std::string, bool> m_boolProps;
213  std::map<std::string, Color4u> m_colorProps;
214  std::map<std::string, Path> m_fileProps;
215  };
216 
217  struct TmxLayers;
218 
219  struct TmxTileLayer;
220  struct TmxObjectLayer;
221  struct TmxImageLayer;
222  struct TmxGroupLayer;
223 
224  /**
225  * @ingroup game
226  * @brief A visitor for layers in the visitor pattern
227  *
228  * @sa gf::TmxLayer::accept()
229  * @sa [Wikipedia - Visitor pattern](https://en.wikipedia.org/wiki/Visitor_pattern)
230  */
232  public:
233  /**
234  * @brief Destructor
235  */
236  virtual ~TmxVisitor();
237 
238  /**
239  * @brief Visit a tile layer.
240  *
241  * @param map The containing map
242  * @param layer The tile layer
243  */
244  virtual void visitTileLayer(const TmxLayers& map, const TmxTileLayer& layer);
245 
246  /**
247  * @brief Visit an object layer.
248  *
249  * @param map The containing map
250  * @param layer The object layer
251  */
252  virtual void visitObjectLayer(const TmxLayers& map, const TmxObjectLayer& layer);
253 
254  /**
255  * @brief Visit an image layer.
256  *
257  * @param map The containing map
258  * @param layer The image layer
259  */
260  virtual void visitImageLayer(const TmxLayers& map, const TmxImageLayer& layer);
261 
262  /**
263  * @brief Visit a group layer
264  *
265  * @param map The containing map
266  * @param layer The group layer
267  */
268  virtual void visitGroupLayer(const TmxLayers& map, const TmxGroupLayer& layer);
269  };
270 
271  /**
272  * @ingroup game
273  * @brief A layer in the whole map
274  *
275  * The are four kinds of layers: tile layers, image layers, object layers and
276  * group layers.
277  *
278  * @sa gf::TmxTileLayer, gf::TmxImageLayer, gf::TmxObjectLayer, gf::TmxGroupLayer
279  */
280  struct GF_API TmxLayer {
281  /**
282  * @brief Destructor
283  */
284  virtual ~TmxLayer();
285 
286  /**
287  * @brief Accept function in the visitor pattern
288  *
289  * @param map The containing map
290  * @param visitor The visitor
291  *
292  * @sa [Wikipedia - Visitor pattern](https://en.wikipedia.org/wiki/Visitor_pattern)
293  */
294  virtual void accept(const TmxLayers& map, TmxVisitor& visitor) const = 0;
295 
296  TmxProperties properties; ///< The properties of the layer
297  std::string name; ///< The name of the layer
298  double opacity; ///< The opacity of the layer
299  bool visible; ///< The visibility of the layer
300  Vector2i offset; ///< The offset of the layer
301  };
302 
303  /**
304  * @ingroup game
305  * @brief A flag to indicate how to flip a tile in a cell
306  *
307  * @sa gf::TmxCell
308  */
309  enum class TmxFlip : uint8_t {
310  Horizontally = 0x01, ///< Flip horizontally
311  Vertically = 0x02, ///< Flip vertically
312  Diagonally = 0x04, ///< Flip diagonally
313  };
314 
315  /**
316  * @ingroup game
317  * @brief A cell in a tile layer
318  */
319  struct GF_API TmxCell {
320  unsigned gid; ///< The global id of the tile
321  Flags<TmxFlip> flip = None; ///< The flip properties of the tile
322  };
323 
324  /**
325  * @ingroup game
326  * @brief A layer with tiles in cells
327  */
328  struct GF_API TmxTileLayer : public TmxLayer {
329  std::vector<TmxCell> cells; ///< The cells of the layer
330 
331  virtual void accept(const TmxLayers& map, TmxVisitor& visitor) const override;
332  };
333 
334  /**
335  * @ingroup game
336  * @brief The draw order of the objects
337  */
338  enum class TmxDrawOrder {
339  TopDown, ///< Top-down order
340  Index, ///< Index order
341  };
342 
343 
344  /**
345  * @ingroup game
346  * @brief A geometrical object
347  *
348  * There are six kinds of objects:
349  *
350  * - rectangles (see gf::TmxRectangle)
351  * - ellipses (see gf::TmxEllipse)
352  * - polylines (see gf::TmxPolyline)
353  * - polygons (see gf::TmxPolygon)
354  * - tiles (see gf::TmxTileObject)
355  * - texts (see gf::TmxText)
356  *
357  * @sa gf::TmxObjectLayer
358  */
359  struct GF_API TmxObject {
360  /**
361  * @brief Destructor
362  */
363  virtual ~TmxObject();
364 
365  /**
366  * @brief The kind of object
367  */
368  enum Kind {
369  Rectangle, ///< A rectangle object
370  Ellipse, ///< An ellipse object
371  Polyline, ///< A polyline object
372  Polygon, ///< A polygon object
373  Tile, ///< A tile object
374  Text, ///< A text object
375  };
376 
377  Kind kind; ///< The kind of the object
378 
379  TmxProperties properties; ///< The properties of the object
380 
381  Id id; ///< The id of the object
382  std::string name; ///< The name of the object
383  std::string type; ///< The type of the object
384  Vector2u position; ///< The position of the object
385  double rotation; ///< The rotation of the object
386  bool visible; ///< The visibility of the object
387  };
388 
389  /**
390  * @ingroup game
391  * @brief A rectangle object
392  */
393  struct GF_API TmxRectangle : public TmxObject {
394  Vector2u size; ///< The size of the rectangle
395  };
396 
397  /**
398  * @ingroup game
399  * @brief An ellipse object
400  */
401  struct GF_API TmxEllipse : public TmxObject {
402  Vector2u size; ///< The size of the ellipse
403  };
404 
405  /**
406  * @ingroup game
407  * @brief An image put in the map identified by its global id
408  */
409  struct GF_API TmxTileObject : public TmxObject {
410  unsigned gid;
412  };
413 
414  /**
415  * @ingroup game
416  * @brief A polyline object
417  *
418  * A polyline is an open set of lines
419  */
420  struct GF_API TmxPolyline : public TmxObject {
421  std::vector<Vector2i> points; ///< The points of the polyline
422  };
423 
424  /**
425  * @ingroup game
426  * @brief A polygon object
427  *
428  * A polygon is a closed set of lines
429  */
430  struct GF_API TmxPolygon : public TmxObject {
431  std::vector<Vector2i> points; ///< The points of the polygon
432  };
433 
434  /**
435  * @ingroup game
436  * @brief A text object
437  */
438  struct GF_API TmxText : public TmxObject {
439  std::string text; ///< The text of the object
440 
441  std::string fontFamily; ///< The font family
442  unsigned sizeInPixels; ///< The size of the text in pixel
443  bool wrap; ///< The wrap mode
444  Color4u color; ///< The color of the text
445  bool bold; ///< Is the text in bold?
446  bool italic; ///< Is the text in italic?
447  bool underline; ///< Is the text underlined?
448  bool strikeout; ///< Is the text striked out?
449  bool kerning; ///< Is the text using kerning?
450 
451  /**
452  * @brief An horizontal alignment
453  */
454  enum class HAlign {
455  Left, ///< A left horizontal alignment
456  Center, ///< A centered horizontal alignment
457  Right, ///< A right horizontal alignment
458  };
459 
460  HAlign halign; ///< The horizontal alignment of the text
461 
462  /**
463  * @brief A vertical alignment
464  */
465  enum class VAlign {
466  Top, ///< A top vertical alignment
467  Center, ///< A centered vertical alignment
468  Bottom, ///< A bottom vertical alignment
469  };
470 
471  VAlign valign; ///< The vertical alignment of the text
472  };
473 
474  /**
475  * @ingroup game
476  * @brief A layer with objects
477  */
478  struct GF_API TmxObjectLayer : public TmxLayer {
479  Color4u color; ///< The color of the objects
480  TmxDrawOrder drawOrder; ///< The draw order of the objects
481  std::vector<std::unique_ptr<TmxObject>> objects; ///< The objects of the layer
482 
483  virtual void accept(const TmxLayers& map, TmxVisitor& visitor) const override;
484  };
485 
486  /**
487  * @ingroup game
488  * @brief A reference to an image
489  */
490  struct GF_API TmxImage {
491  std::string format; ///< The format of the image
492  Path source; ///< The path to the image
493  Color4u transparent; ///< The transparent color
494  Vector2u size; ///< The size of the image
495  };
496 
497  /**
498  * @ingroup game
499  * @brief A layer with an image
500  */
501  struct GF_API TmxImageLayer : public TmxLayer {
502  std::unique_ptr<TmxImage> image; ///< The image of the layer
503 
504  virtual void accept(const TmxLayers& map, TmxVisitor& visitor) const override;
505  };
506 
507 
508  /**
509  * @ingroup game
510  * @brief A layer with other layers
511  */
512  struct GF_API TmxGroupLayer : public TmxLayer {
513  std::vector<std::unique_ptr<TmxLayer>> layers; ///< The other layers
514 
515  virtual void accept(const TmxLayers& map, TmxVisitor& visitor) const override;
516  };
517 
518  /**
519  * @ingroup game
520  * @brief A frame in a tile animation
521  *
522  * @sa gf::TmxAnimation
523  */
524  struct GF_API TmxFrame {
525  unsigned tileId;
527  };
528 
529  /**
530  * @ingroup game
531  * @brief A tile animation
532  */
534  std::vector<TmxFrame> frames; ///< The frames of the animation
535  };
536 
537  /**
538  * @ingroup game
539  * @brief A description of a kind of terrain on the map
540  *
541  * @sa gf::TmxTileset
542  */
544  TmxProperties properties; ///< The properties of the terrain
545  std::string name; ///< The name of the terrain
546  unsigned tile; ///< The representing tile for the terrain
547  };
548 
549  /**
550  * @ingroup game
551  * @brief A rectangular part of a tileset
552  *
553  * @sa gf::TmxTileset
554  */
555  struct GF_API TmxTile {
556  TmxProperties properties; ///< The properties of the tile
557  unsigned id; ///< The local id of the tile
558  std::string type; ///< The type of the tile
559  std::array<unsigned, 4> terrain; ///< The terrain if the corners (top-left, top-right, bottom-left, bottom-right)
560  unsigned probability; ///< The probability of the tile
561 
562  std::unique_ptr<TmxImage> image; ///< The image of this tile
563  std::unique_ptr<TmxObjectLayer> objects; ///< The objects in the tile
564  std::unique_ptr<TmxAnimation> animation; ///< The animation data of the tile
565  };
566 
567  /**
568  * @ingroup game
569  * @brief A set of tiles in a single file (image or TSX file)
570  */
572  TmxProperties properties; ///< The properties of the tileset
573 
574  unsigned firstGid; ///< The first global id of the tileset
575  std::string name; ///< The name of the tileset
576  Vector2u tileSize; ///< The size of the tileset
577  unsigned spacing; ///< The spacing between tiles (in pixels)
578  unsigned margin; ///< The margin around tiles (in pixels)
579  unsigned tileCount; ///< The number of tiles
580  unsigned columnCount; ///< The number of columns
581 
582  Vector2i offset; ///< The offset of the tileset
583 
584  std::unique_ptr<TmxImage> image; ///< The image of the tileset
585  std::vector<TmxTerrain> terrains; ///< The terrains of the tileset
586  std::vector<TmxTile> tiles; ///< The tiles of the tileset
587 
588  public:
589  /**
590  * @brief Get the tile corresponding to an id.
591  *
592  * @param id The id of the tile
593  * @returns The tile
594  */
595  const TmxTile *getTile(unsigned id) const noexcept;
596 
597  /**
598  * @brief Get the rectangle of a tile corresponding to an id.
599  *
600  * @param id The id of the tile
601  * @param size The size of the image corresponding to the tile
602  * @returns The rectangle of the tile
603  */
604  RectU getSubTexture(unsigned id, Vector2u size) const noexcept;
605 
606  };
607 
608  /**
609  * @ingroup game
610  * @brief A TMX map
611  */
612  struct GF_API TmxLayers {
613  TmxProperties properties; ///< The properties of the map
614 
615  std::string version; ///< The version of the map
616  std::string tiledVersion; ///< The tiled version of the map
617  TmxOrientation orientation; ///< The orientation of the map
618  TmxRenderOrder renderOrder; ///< The render order of the map
619 
620  Vector2u mapSize; ///< The size of the map
621  Vector2u tileSize; ///< The size of the tiles
622 
623  unsigned hexSideLength; ///< The length of the side for hexagonal map
624  TmxStaggerAxis staggerAxis; ///< The stagger axis for hexagonal map
625  TmxStaggerIndex staggerIndex; ///< The stagger index for hexagonal map
626 
627  Color4u backgroundColor; ///< The background color
628 
629  unsigned nextObjectId; ///< The next object id
630 
631  std::vector<TmxTileset> tilesets; ///< The tilesets used in the map
632  std::vector<std::unique_ptr<TmxLayer>> layers; ///< The layers of the map
633 
634  public:
635 
636  /**
637  * @brief Get the tileset corresponding to a global id.
638  *
639  * @param gid A global id
640  * @returns The corresponding tileset
641  */
642  const TmxTileset *getTileSetFromGID(unsigned gid) const noexcept;
643 
644  /**
645  * @brief Visit the layers with a visitor.
646  *
647  * @param visitor the visitor
648  */
649  void visitLayers(TmxVisitor& visitor) const;
650 
651  /**
652  * @brief Load a TMX file
653  *
654  * @param filename The name of the TMX file
655  */
656  bool loadFromFile(const Path& filename);
657 
658  };
659 
660 #ifndef DOXYGEN_SHOULD_SKIP_THIS
661 }
662 #endif
663 }
664 
665 #endif // GF_TMX_H
Vector2u size
The size of the image.
Definition: Tmx.h:494
unsigned tileCount
The number of tiles.
Definition: Tmx.h:579
double opacity
The opacity of the layer.
Definition: Tmx.h:298
VAlign valign
The vertical alignment of the text.
Definition: Tmx.h:471
RectU getSubTexture(unsigned id, Vector2u size) const noexcept
Get the rectangle of a tile corresponding to an id.
Vector2u size
The size of the ellipse.
Definition: Tmx.h:402
A layer with an image.
Definition: Tmx.h:501
Flags< TmxFlip > flip
The flip properties of the tile.
Definition: Tmx.h:321
bool bold
Is the text in bold?
Definition: Tmx.h:445
TmxStaggerIndex
Stagger index of the hexagonal map.
Definition: Tmx.h:59
unsigned columnCount
The number of columns.
Definition: Tmx.h:580
A visitor for layers in the visitor pattern.
Definition: Tmx.h:231
TmxProperties properties
The properties of the terrain.
Definition: Tmx.h:544
void addIntProperty(std::string name, int value)
Add an integer property.
TmxFlip
A flag to indicate how to flip a tile in a cell.
Definition: Tmx.h:309
The y stagger axis.
void addFileProperty(std::string name, Path value)
Add a file property.
bool wrap
The wrap mode.
Definition: Tmx.h:443
std::string text
The text of the object.
Definition: Tmx.h:439
std::vector< TmxTerrain > terrains
The terrains of the tileset.
Definition: Tmx.h:585
A rectangle object.
Definition: Tmx.h:393
std::string name
The name of the object.
Definition: Tmx.h:382
An unknown orientation.
std::vector< TmxFrame > frames
The frames of the animation.
Definition: Tmx.h:534
unsigned gid
The global id of the tile.
Definition: Tmx.h:320
Flip vertically.
A bottom vertical alignment.
unsigned sizeInPixels
The size of the text in pixel.
Definition: Tmx.h:442
Color4u backgroundColor
The background color.
Definition: Tmx.h:627
std::vector< std::unique_ptr< TmxObject > > objects
The objects of the layer.
Definition: Tmx.h:481
virtual ~TmxObject()
Destructor.
Flip horizontally.
const TmxTile * getTile(unsigned id) const noexcept
Get the tile corresponding to an id.
Bitfield relying on an enumeration.
Definition: Flags.h:68
TmxDrawOrder
The draw order of the objects.
Definition: Tmx.h:338
A left horizontal alignment.
Vector2u size
The size of the rectangle.
Definition: Tmx.h:394
Id id
The id of the object.
Definition: Tmx.h:381
virtual void visitTileLayer(const TmxLayers &map, const TmxTileLayer &layer)
Visit a tile layer.
TmxStaggerAxis staggerAxis
The stagger axis for hexagonal map.
Definition: Tmx.h:624
std::unique_ptr< TmxImage > image
The image of the layer.
Definition: Tmx.h:502
An ellipse object.
Definition: Tmx.h:401
A hexagonal orientation.
virtual ~TmxLayer()
Destructor.
TmxDrawOrder drawOrder
The draw order of the objects.
Definition: Tmx.h:480
double rotation
The rotation of the object.
Definition: Tmx.h:385
unsigned spacing
The spacing between tiles (in pixels)
Definition: Tmx.h:577
unsigned tile
The representing tile for the terrain.
Definition: Tmx.h:546
A layer with objects.
Definition: Tmx.h:478
Path getFileProperty(const std::string &name, const Path &def) const
Get a file property.
An ellipse object.
Definition: Tmx.h:370
A layer in the whole map.
Definition: Tmx.h:280
Path source
The path to the image.
Definition: Tmx.h:492
std::string tiledVersion
The tiled version of the map.
Definition: Tmx.h:616
void visitLayers(TmxVisitor &visitor) const
Visit the layers with a visitor.
bool getBoolProperty(const std::string &name, bool def) const
Get a boolean property.
std::string name
The name of the tileset.
Definition: Tmx.h:575
A tile animation.
Definition: Tmx.h:533
A TMX map.
Definition: Tmx.h:612
bool kerning
Is the text using kerning?
Definition: Tmx.h:449
A tile object.
Definition: Tmx.h:373
std::string getStringProperty(const std::string &name, const std::string &def) const
Get a string property.
std::vector< TmxTileset > tilesets
The tilesets used in the map.
Definition: Tmx.h:631
void addFloatProperty(std::string name, double value)
Add a float property.
A staggered orientation.
Represents a time value.
Definition: Time.h:73
std::unique_ptr< TmxAnimation > animation
The animation data of the tile.
Definition: Tmx.h:564
std::vector< TmxTile > tiles
The tiles of the tileset.
Definition: Tmx.h:586
TmxProperties(TmxProperties &&)=default
Default move constructor.
Vector2u position
The position of the object.
Definition: Tmx.h:384
std::string fontFamily
The font family.
Definition: Tmx.h:441
The x stagger axis.
Color4u transparent
The transparent color.
Definition: Tmx.h:493
Vector2i offset
The offset of the layer.
Definition: Tmx.h:300
void addColorProperty(std::string name, Color4u value)
Add a color property.
A text object.
Definition: Tmx.h:438
HAlign halign
The horizontal alignment of the text.
Definition: Tmx.h:460
A centered horizontal alignment.
virtual ~TmxVisitor()
Destructor.
std::string type
The type of the object.
Definition: Tmx.h:383
virtual void visitImageLayer(const TmxLayers &map, const TmxImageLayer &layer)
Visit an image layer.
TmxStaggerAxis
Stagger axis of the hexagonal map.
Definition: Tmx.h:68
std::vector< std::unique_ptr< TmxLayer > > layers
The layers of the map.
Definition: Tmx.h:632
std::string name
The name of the terrain.
Definition: Tmx.h:545
std::string version
The version of the map.
Definition: Tmx.h:615
virtual void accept(const TmxLayers &map, TmxVisitor &visitor) const =0
Accept function in the visitor pattern.
virtual void accept(const TmxLayers &map, TmxVisitor &visitor) const override
Accept function in the visitor pattern.
unsigned id
The local id of the tile.
Definition: Tmx.h:557
std::vector< std::unique_ptr< TmxLayer > > layers
The other layers.
Definition: Tmx.h:513
TmxRenderOrder renderOrder
The render order of the map.
Definition: Tmx.h:618
Kind
The kind of object.
Definition: Tmx.h:368
virtual void accept(const TmxLayers &map, TmxVisitor &visitor) const override
Accept function in the visitor pattern.
Vector2u mapSize
The size of the map.
Definition: Tmx.h:620
The namespace for gf classes.
Definition: Action.h:34
A polyline object.
Definition: Tmx.h:420
A centered vertical alignment.
unsigned hexSideLength
The length of the side for hexagonal map.
Definition: Tmx.h:623
TmxProperties properties
The properties of the tile.
Definition: Tmx.h:556
unsigned probability
The probability of the tile.
Definition: Tmx.h:560
TmxProperties & operator=(TmxProperties &&)=default
Default move assignment.
std::unique_ptr< TmxObjectLayer > objects
The objects in the tile.
Definition: Tmx.h:563
A frame in a tile animation.
Definition: Tmx.h:524
int getIntProperty(const std::string &name, int def) const
Get an integer property.
Vector2i offset
The offset of the tileset.
Definition: Tmx.h:582
TmxProperties properties
The properties of the tileset.
Definition: Tmx.h:572
An even stagger index.
TmxProperties properties
The properties of the map.
Definition: Tmx.h:613
Kind kind
The kind of the object.
Definition: Tmx.h:377
std::string type
The type of the tile.
Definition: Tmx.h:558
std::vector< Vector2i > points
The points of the polygon.
Definition: Tmx.h:431
Vector2u tileSize
The size of the tileset.
Definition: Tmx.h:576
TmxOrientation orientation
The orientation of the map.
Definition: Tmx.h:617
Color4u color
The color of the text.
Definition: Tmx.h:444
double getFloatProperty(const std::string &name, double def) const
Get a float property.
A description of a kind of terrain on the map.
Definition: Tmx.h:543
A rectangle object.
Definition: Tmx.h:369
The properties for TMX entities.
Definition: Tmx.h:89
bool visible
The visibility of the object.
Definition: Tmx.h:386
Flags< TmxFlip > flip
Definition: Tmx.h:411
VAlign
A vertical alignment.
Definition: Tmx.h:465
void addStringProperty(std::string name, std::string value)
Add a string property.
An isometric orientation.
A right horizontal alignment.
A rectangular part of a tileset.
Definition: Tmx.h:555
TmxRenderOrder
the render order of the tiles.
Definition: Tmx.h:77
std::string format
The format of the image.
Definition: Tmx.h:491
HAlign
An horizontal alignment.
Definition: Tmx.h:454
TmxStaggerIndex staggerIndex
The stagger index for hexagonal map.
Definition: Tmx.h:625
Color4u color
The color of the objects.
Definition: Tmx.h:479
A polygon object.
Definition: Tmx.h:372
A geometrical object.
Definition: Tmx.h:359
const TmxTileset * getTileSetFromGID(unsigned gid) const noexcept
Get the tileset corresponding to a global id.
A cell in a tile layer.
Definition: Tmx.h:319
std::unique_ptr< TmxImage > image
The image of this tile.
Definition: Tmx.h:562
A text object.
Definition: Tmx.h:374
unsigned margin
The margin around tiles (in pixels)
Definition: Tmx.h:578
virtual void accept(const TmxLayers &map, TmxVisitor &visitor) const override
Accept function in the visitor pattern.
unsigned tileId
Definition: Tmx.h:525
TmxOrientation
The orientation of the map.
Definition: Tmx.h:47
TmxProperties properties
The properties of the object.
Definition: Tmx.h:379
Flip diagonally.
A set of tiles in a single file (image or TSX file)
Definition: Tmx.h:571
TmxProperties()=default
Default constructor.
unsigned nextObjectId
The next object id.
Definition: Tmx.h:629
unsigned firstGid
The first global id of the tileset.
Definition: Tmx.h:574
unsigned gid
Definition: Tmx.h:410
An image put in the map identified by its global id.
Definition: Tmx.h:409
virtual void visitGroupLayer(const TmxLayers &map, const TmxGroupLayer &layer)
Visit a group layer.
Vector2u tileSize
The size of the tiles.
Definition: Tmx.h:621
bool italic
Is the text in italic?
Definition: Tmx.h:446
#define GF_API
Definition: Portability.h:35
A layer with tiles in cells.
Definition: Tmx.h:328
std::array< unsigned, 4 > terrain
The terrain if the corners (top-left, top-right, bottom-left, bottom-right)
Definition: Tmx.h:559
std::unique_ptr< TmxImage > image
The image of the tileset.
Definition: Tmx.h:584
std::vector< TmxCell > cells
The cells of the layer.
Definition: Tmx.h:329
A polyline object.
Definition: Tmx.h:371
bool loadFromFile(const Path &filename)
Load a TMX file.
virtual void visitObjectLayer(const TmxLayers &map, const TmxObjectLayer &layer)
Visit an object layer.
A layer with other layers.
Definition: Tmx.h:512
bool strikeout
Is the text striked out?
Definition: Tmx.h:448
Time duration
Definition: Tmx.h:526
std::string name
The name of the layer.
Definition: Tmx.h:297
void addBoolProperty(std::string name, bool value)
Add a boolean property.
A odd stagger index.
A polygon object.
Definition: Tmx.h:430
bool visible
The visibility of the layer.
Definition: Tmx.h:299
A top vertical alignment.
Color4u getColorProperty(const std::string &name, const Color4u &def) const
Get a color property.
TmxProperties properties
The properties of the layer.
Definition: Tmx.h:296
virtual void accept(const TmxLayers &map, TmxVisitor &visitor) const override
Accept function in the visitor pattern.
bool underline
Is the text underlined?
Definition: Tmx.h:447
std::vector< Vector2i > points
The points of the polyline.
Definition: Tmx.h:421
An orthogonal orientation.
A reference to an image.
Definition: Tmx.h:490