-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTiled.h
179 lines (155 loc) · 2.93 KB
/
Tiled.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#ifndef TILED
#define TILED
#include <cstdint>
#include "XML.h"
#include "Common.h"
#define MAP_DIRECTORY "../Maps/"
namespace Tiled
{
struct tile
{
//sf::Sprite* sprite;
std::int64_t id;
std::int64_t originalId;
std::int64_t horizontalFlip;
std::int64_t verticalFlip;
std::int64_t diagonalFlip;
std::int64_t hexagonal120Rotation;
};
struct image
{
bool lock;
char* source;
int width;// in pixels
int height;// in pixels
//sf::Texture* texture;
image();
~image();
};
struct TsxFile
{
char* name;
int width;
int height;
int tilewidth;
int tileheight;
int tilecount;
int columns;
};
struct tileset
{
image* images;
unsigned int imageCount;
bool lock;
int firstgid;
char* source;
TsxFile tsxFile;
tileset();
~tileset();
};
struct data
{
bool lock;
char* encoding;
char* compression;
tile* tiles;
unsigned int tileCount;
data();
~data();
};
struct layer
{
bool lock;
data data;
int id;
char* name;
char* layerclass; /*class*/
int x;
int y;
int width;
int height;
float opacity; /*0 to 1*/
bool visible;
int tintcolor;
int offsetx;
int offsety;
int parallaxx;
int parallaxy;
layer();
~layer();
};
struct Interaction
{
int id;
int secondaryId;
//sf::Vector2i position;
};
class Map
{
public:
void LoadAttributes(XML::Tag* _tag);
tileset* tilesets;
unsigned int tilesetsCount;
void AddTileset(XML::Tag* _tag);
layer* layers;
unsigned int layersCount;
void AddLayer(XML::Tag* _tag);
void SetAttributes(const char* _buffer, XML::Tag*& mapTag);
std::vector<Interaction> interactions;
Map();
~Map();
#pragma region Attributes
enum Orientation
{
Orthogonal,
Isometric,
Staggered,
Hexagonal,
};
enum RenderOrder
{
Right_Down,
Right_Up,
Left_Down,
Left_up,
};
float version;
float tiledversion;
Orientation orientation;
RenderOrder renderorder;
int compressionlevel; // default -1
int width;
int height;
int tilewidth;
int tileheight;
int hexsidelength;
int staggeraxis;
int staggerindex;
int parallaxoriginx;
int parallaxoriginy;
int backgroundcolor; //unk type
int nextlayerid;
int nextobjectid;
bool infinite;
#pragma endregion
};
namespace Reader
{
namespace Flags
{
enum Flags
{
FLIPPED_HORIZONTALLY = 0x80000000,
FLIPPED_VERTICALLY = 0x40000000,
FLIPPED_DIAGONALLY = 0x20000000,
ROTATED_HEXAGONAL_120 = 0x10000000,
};
}
void Tmx(const char* _fileName, Map& _map);
void UpdateTilesets(XML::Tag* _mapTag, Map& _map);
void UpdateLayers(XML::Tag* _mapTag, Map& _map);
void AddTileToGrid(tile& _tile, data& _data, unsigned int& _tileCount);
void ReadCsvGrid(data& _data, const char* _buffer, unsigned int& _tileCount);
}
}
#endif // !TILED