-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathspec.go
244 lines (226 loc) · 9.03 KB
/
spec.go
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
package tmx
// Flip flags stored in the highest three bits of the GID.
const (
FlagDiagonalFlip = 0x20000000
FlagVerticalFlip = 0x40000000
FlagHorizontalFlip = 0x80000000
FlagFlip = FlagDiagonalFlip | FlagVerticalFlip | FlagHorizontalFlip
)
// A Map contains all the map information stored in tmx files.
//
// The TileWidth and TileHeight properties determine the general grid size of
// the map. The individual tiles may have different sizes. Larger tiles will
// extend at the top and right (anchored to the bottom left).
type Map struct {
// The TMX format version, generally 1.0.
Version string `xml:"version,attr"`
// Map orientation. Tiled supports "orthogonal" and "isometric" at the
// moment.
Orientation string `xml:"orientation,attr"`
// The map width (cols) in tiles.
Width int `xml:"width,attr"`
// The map height (rows) in tiles.
Height int `xml:"height,attr"`
// The width in pixels of a tile.
TileWidth int `xml:"tilewidth,attr"`
// The height in pixels of a tile.
TileHeight int `xml:"tileheight,attr"`
// Properties associated with the map.
Properties []Property `xml:"properties>property"`
// Tilesets associated with the map.
Tilesets []Tileset `xml:"tileset"`
// Layers associated with the map.
Layers []Layer `xml:"layer"`
// Object layers associated with the map.
ObjectLayers []ObjectLayer `xml:"objectgroup"`
}
// A Property is a name, value pair.
type Property struct {
// The name of the property.
Name string `xml:"name,attr"`
// The value of the property.
Value string `xml:"value,attr"`
}
/// ### [ todo ] ###
/// - Source: load info from TSX files.
/// ### [/ todo ] ###
// A Tileset is a sprite sheet of tiles.
type Tileset struct {
// FirstGID is the first global tile ID of the tileset and it maps to the
// first tile in the tilset.
FirstGID int `xml:"firstgid,attr"`
// Source refers to an external TSX (Tile Set XML) file. The TSX file has the
// same structure as the Tileset described here, but without the firstgid and
// source attributes, since they are map specific.
Source string `xml:"source,attr"`
// The name of the tileset.
Name string `xml:"name,attr"`
// The (maximum) width of the tiles in the tileset.
TileWidth int `xml:"tilewidth,attr"`
// The (maximum) height of the tiles in the tileset.
TileHeight int `xml:"tileheight,attr"`
// The spacing in pixels between the tiles in the tileset (applies to the
// tileset image).
Spacing int `xml:"spacing,attr"`
// The margin around the tiles in the tileset (applies to the tileset image).
Margin int `xml:"margin,attr"`
// Tile offset associated with the tileset.
TileOffset TileOffset `xml:"tileoffset"`
// Properties associated with the tileset.
Properties []Property `xml:"properties>property"`
// The image associated with the tileset.
Image Image `xml:"image"`
// TilesInfo contains information about the tiles within a tileset.
TilesInfo []TileInfo `xml:"tile"`
}
// A TileOffset specifies an offset in pixels, to be applied when drawing a tile
// from the related tileset.
type TileOffset struct {
// Horizontal offset in pixels
X int `xml:"x,attr"`
// Vertical offset in pixels (positive is down)
Y int `xml:"y,attr"`
}
// An Image is associated with each tileset. It is cut into smaller tiles based
// on the attributes defined in the tileset.
type Image struct {
// Source refers to the tileset image file.
Source string `xml:"source,attr"`
// Trans defines a specific color that is treated as transparent (example
// value: "FF00FF" for magenta).
Trans string `xml:"trans,attr"`
// The image width in pixels (optional, used for tile index correction when
// the image changes).
Width int `xml:"width,attr"`
// The image height in pixels (optional).
Height int `xml:"height,attr"`
}
// TileInfo contains information about a tile within a tileset.
type TileInfo struct {
// The local tile ID within its tileset.
ID int `xml:"id,attr"`
// Properties associated with the tile.
Properties []Property `xml:"properties>property"`
}
/// ### [ todo ] ###
/// - Visible: default value true
/// - Opacity: default value 1.0
/// ### [/ todo ] ###
// A Layer contains information about which global tile ID any given coordinate
// has. A Map can contain any number of layers.
type Layer struct {
// The name of the layer.
Name string `xml:"name,attr"`
// Visible specifies whether the layer is shown (true) or hidden (false).
Visible bool `xml:"visible,attr"`
// The opacity of the layer as a value from 0.0 to 1.0.
Opacity float64 `xml:"opacity,attr"`
// Properties associated with the layer.
Properties []Property `xml:"properties>property"`
// Data contains the information about the tile GIDs associated with a layer.
//
// Note: Data should not be accessed directly. Use the GetGID method instead
// to obtain the GID at a given coordinate.
Data *Data `xml:"data"`
}
// GID corresponds to a global tile ID.
//
// Note: The highest three bits of the GID are used to store flip flags. These
// must be cleared before using the GID as a global tile ID. Either use the
// convenience methods or clear the flip flags manually before using the GID
// value.
type GID uint32
// Data contains the information about the tile GIDs associated with a layer.
//
// Note: Data should not be accessed directly. Use the GetGID method instead to
// obtain the GID at a given coordinate.
type Data struct {
// Encoding specifies the encoding method used for the RawData. Options
// include "base64", "csv" and "" for XML encoding.
Encoding string `xml:"encoding,attr"`
// Compression specifies the compression method used for the RawData. Options
// include "gzip", "zlib" and "" for no compression.
Compression string `xml:"compression,attr"`
// RawData contains the raw data of tile GIDs, which can be represented in
// several different ways as specified by Encoding and Compression.
RawData string `xml:",innerxml"`
// Tiles associated with the layer.
Tiles []Tile `xml:"tile"`
// gids contains the decoded tile GIDs arranged by col and row.
gids [][]GID
}
// A Tile contains the GID of a single tile on a tile layer.
type Tile struct {
// The global tile ID.
GID GID `xml:"gid,attr"`
}
/// ### [ todo ] ###
/// - Visible: default value true
/// ### [/ todo ] ###
// An ObjectLayer contains information about different objects on the map. A Map
// can contain any number of object layers.
//
// While tile layers are very suitable for anything repetitive aligned to the
// tile grid, sometimes you want to annotate your map with other information,
// not necessarily aligned to the grid. Hence the objects have their coordinates
// and size in pixels, but you can still easily align that to the grid when you
// want to.
type ObjectLayer struct {
// The name of the object layer.
Name string `xml:"name,attr"`
// Visible specifies whether the layer is shown (true) or hidden (false).
Visible bool `xml:"visible,attr"`
// The opacity of the layer as a value from 0.0 to 1.0.
Opacity float64 `xml:"opacity,attr"`
// Objects associated with the object layer.
Objects []Object `xml:"object"`
}
// An Object can be positioned anywhere on the map, and is not necessarily
// aligned to the grid.
//
// You generally use objects to add custom information to your tile map, such
// as spawn points, warps, exits, etc.
type Object struct {
// The name of the object.
Name string `xml:"name,attr"`
// The type of the object.
Type string `xml:"type,attr"`
// The x coordinate of the object in pixels.
X int `xml:"x,attr"`
// The y coordinate of the object in pixels.
Y int `xml:"y,attr"`
// The width of the object in pixels.
Width int `xml:"width,attr"`
// The height of the object in pixels.
Height int `xml:"height,attr"`
// GID is a reference to a global tile ID.
//
// When the object has a GID set, then it is represented by the image of the
// tile with that global tile ID. Currently that means Width and Height are
// ignored for such objects. The image alignment currently depends on the map
// orientation. In orthogonal orientation it's aligned to the bottom-left
// while in isometric it's aligned to the bottom-center.
GID GID `xml:"gid,attr"`
// Properties associated with the object.
Properties []Property `xml:"properties>property"`
// A Polygon associated with the object.
Polygon Polygon `xml:"polygon"`
// A Polyline associated with the object.
Polyline Polyline `xml:"polyline"`
}
// A Polygon object is made up of a space-delimited list of x,y coordinates. The
// origin for these coordinates is the location of the parent object. By
// default, the first point is created as 0,0 denoting that the point will
// originate exactly where the object is placed.
type Polygon struct {
// Points contains a list of x,y coordinates in pixels.
Points string `xml:"points,attr"`
}
// A Polyline object is made up of a space-delimited list of x,y coordinates.
// The origin for these coordinates is the location of the parent object. By
// default, the first point is created as 0,0 denoting that the point will
// originate exactly where the object is placed.
type Polyline struct {
// Points contains a list of x,y coordinates in pixels.
Points string `xml:"points,attr"`
}