-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloader.go
126 lines (106 loc) · 3.25 KB
/
loader.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
// Package tmx provides an TMX file loader
// specification: http://doc.mapeditor.org/reference/tmx-map-format/
package tmx
import "encoding/xml"
const (
//GIDHorizontalFlip for horizontal flipped tiles
GIDHorizontalFlip = 0x80000000
//GIDVerticalFlip for vertical flipped tiles
GIDVerticalFlip = 0x40000000
//GIDDiagonalFlip for diagonally flipped tile
GIDDiagonalFlip = 0x20000000
//GIDFlips removes all flipping informations
GIDFlips = GIDHorizontalFlip | GIDVerticalFlip | GIDDiagonalFlip
)
//GID is a global tile id
type GID uint32
//DataTile datatile
type DataTile struct {
GID GID `xml:"gid,attr"`
//HorizontalFlip true if the tile should be rendered with flip in x dir
HorizontalFlip bool
//VerticalFlip true if the tile should be rendered with flip in y dir
VerticalFlip bool
//DiagonalFlip true if it should be rendered flipped diagonally, can be combined
//with `HorizontalFlip` or `VerticalFlip`
DiagonalFlip bool
}
//visibleValue must be used since the stupid default for visible is true
type visibleValue struct {
value bool
}
func (v *visibleValue) UnmarshalXMLAttr(attr xml.Attr) error {
if attr.Value == "" {
v.value = true
return nil
}
v.value = attr.Value != "0"
return nil
}
//Layer represents one layer of the map.
type Layer struct {
Name string `xml:"name,attr"`
Opacity float32 `xml:"opacity,attr"`
Visible *visibleValue `xml:"visible,attr"`
Properties []Property `xml:"properties>property"`
Data Data `xml:"data"`
Width int `xml:"width,attr"`
Height int `xml:"height,attr"`
}
//IsVisible returns true if the layer is visible, false otherwise
func (l Layer) IsVisible() bool {
if l.Visible == nil {
return true
}
return l.Visible.value
}
//ObjectGroup is a group of objects
type ObjectGroup struct {
Name string `xml:"name,attr"`
Color string `xml:"color,attr"`
Opacity float32 `xml:"opacity,attr"`
Visible *visibleValue `xml:"visible,attr"`
Properties []Property `xml:"properties>property"`
Objects []Object `xml:"object"`
}
//IsVisible returns true if the object group is visible, false otherwise
func (o ObjectGroup) IsVisible() bool {
if o.Visible == nil {
return true
}
return o.Visible.value
}
// Object is an object
type Object struct {
Name string `xml:"name,attr"`
Type string `xml:"type,attr"`
X int `xml:"x,attr"`
Y int `xml:"y,attr"`
Width int `xml:"width,attr"`
Height int `xml:"height,attr"`
GID int `xml:"gid,attr"`
Visible *visibleValue `xml:"visible,attr"`
Polygons []Polygon `xml:"polygon"`
PolyLines []PolyLine `xml:"polyline"`
Properties []Property `xml:"properties>property"`
}
//IsVisible returns true if the object is visible, false otherwise
func (o Object) IsVisible() bool {
if o.Visible == nil {
return true
}
return o.Visible.value
}
//Polygon loads a polygon from tmx
type Polygon struct {
Points string `xml:"points,attr"`
}
//PolyLine loads a polyline from tmx
type PolyLine struct {
Points string `xml:"points,attr"`
}
//Property can be set on tiles
type Property struct {
Name string `xml:"name,attr"`
Value string `xml:"value,attr"`
}