tmxparser  2.1.0
 All Classes Functions Variables Pages
TmxTileLayer.h
1 //-----------------------------------------------------------------------------
2 // TmxTileLayer.h
3 //
4 // Copyright (c) 2010-2014, Tamir Atias
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
16 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 // DISCLAIMED. IN NO EVENT SHALL TAMIR ATIAS BE LIABLE FOR ANY
19 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
21 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
22 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 //
26 // Author: Tamir Atias
27 //-----------------------------------------------------------------------------
28 #pragma once
29 
30 #include <string>
31 
32 #include "TmxLayer.h"
33 #include "TmxPropertySet.h"
34 #include "TmxMapTile.h"
35 
36 namespace tinyxml2 {
37  class XMLNode;
38 }
39 
40 namespace Tmx
41 {
42  class Map;
43 
44  //-------------------------------------------------------------------------
46  //-------------------------------------------------------------------------
47  enum TileLayerEncodingType
48  {
49  TMX_ENCODING_XML,
50  TMX_ENCODING_BASE64,
51  TMX_ENCODING_CSV
52  };
53 
54  //-------------------------------------------------------------------------
56  //-------------------------------------------------------------------------
57  enum TileLayerCompressionType
58  {
59  TMX_COMPRESSION_NONE,
60  TMX_COMPRESSION_ZLIB,
61  TMX_COMPRESSION_GZIP
62  };
63 
64  //-------------------------------------------------------------------------
67  //-------------------------------------------------------------------------
68  class TileLayer : public Tmx::Layer
69  {
70  private:
72  TileLayer(const TileLayer &_layer);
73 
74  public:
76  TileLayer(const Tmx::Map *_map);
77  ~TileLayer();
78 
80  void Parse(const tinyxml2::XMLNode *tileLayerNode);
81 
83  unsigned GetTileId(int x, int y) const { return tile_map[y * width + x].id; }
84 
86  unsigned GetTileGid(int x, int y) const { return tile_map[y * width + x].gid; }
87 
89  int GetTileTilesetIndex(int x, int y) const { return tile_map[y * width + x].tilesetId; }
90 
92  bool IsTileFlippedHorizontally(int x, int y) const
93  { return tile_map[y * width + x].flippedHorizontally; }
94 
96  bool IsTileFlippedVertically(int x, int y) const
97  { return tile_map[y * width + x].flippedVertically; }
98 
100  bool IsTileFlippedDiagonally(int x, int y) const
101  { return tile_map[y * width + x].flippedDiagonally; }
102 
104  const Tmx::MapTile& GetTile(int x, int y) const { return tile_map[y * width + x]; }
105 
107  const Tmx::MapTile& GetTile(int index) const { return tile_map[index]; }
108 
111  Tmx::TileLayerEncodingType GetEncoding() const { return encoding; }
112 
115  Tmx::TileLayerCompressionType GetCompression() const { return compression; }
116 
117  private:
118  void ParseXML(const tinyxml2::XMLNode *dataNode);
119  void ParseBase64(const std::string &innerText);
120  void ParseCSV(const std::string &innerText);
121 
122  Tmx::MapTile *tile_map;
123 
124  Tmx::TileLayerEncodingType encoding;
125  Tmx::TileLayerCompressionType compression;
126  };
127 }
Base class for other layer types.
Definition: TmxLayer.h:54
unsigned gid
Gid.
Definition: TmxMapTile.h:73
int tilesetId
Tileset id.
Definition: TmxMapTile.h:67
bool flippedVertically
True when the tile should be drawn flipped vertically.
Definition: TmxMapTile.h:79
Tmx::TileLayerEncodingType GetEncoding() const
Get the type of encoding that was used for parsing the tile layer data.
Definition: TmxTileLayer.h:111
Tmx::TileLayerCompressionType GetCompression() const
Get the type of compression that was used for parsing the tile layer data.
Definition: TmxTileLayer.h:115
unsigned GetTileGid(int x, int y) const
Pick a specific tile gid from the list.
Definition: TmxTileLayer.h:86
Used for storing information about the tile ids for every tile layer.
Definition: TmxTileLayer.h:68
bool flippedDiagonally
True when the tile should be drawn flipped diagonally.
Definition: TmxMapTile.h:82
Struct to store information about a specific tile in the map layer.
Definition: TmxMapTile.h:42
int GetTileTilesetIndex(int x, int y) const
Get the tileset index for a tileset from the list.
Definition: TmxTileLayer.h:89
const Tmx::MapTile & GetTile(int index) const
Get a tile by its index.
Definition: TmxTileLayer.h:107
bool IsTileFlippedHorizontally(int x, int y) const
Get whether a tile is flipped horizontally.
Definition: TmxTileLayer.h:92
bool IsTileFlippedVertically(int x, int y) const
Get whether a tile is flipped vertically.
Definition: TmxTileLayer.h:96
This class is the root class of the parser.
Definition: TmxMap.h:115
unsigned id
Id.
Definition: TmxMapTile.h:70
bool flippedHorizontally
True when the tile should be drawn flipped horizontally.
Definition: TmxMapTile.h:76
void Parse(const tinyxml2::XMLNode *tileLayerNode)
Parse a tile layer node.
Definition: TmxTileLayer.cpp:63
const Tmx::MapTile & GetTile(int x, int y) const
Get the tile at the given position.
Definition: TmxTileLayer.h:104
unsigned GetTileId(int x, int y) const
Pick a specific tile id from the list.
Definition: TmxTileLayer.h:83
bool IsTileFlippedDiagonally(int x, int y) const
Get whether a tile is flipped diagonally.
Definition: TmxTileLayer.h:100