-
Notifications
You must be signed in to change notification settings - Fork 14
/
objectgroup.go
72 lines (59 loc) · 1.66 KB
/
objectgroup.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
package tilepix
import "fmt"
/*
___ _ _ _ ___
/ _ \| |__ (_)___ __| |_ / __|_ _ ___ _ _ _ __
| (_) | '_ \| / -_) _| _| (_ | '_/ _ \ || | '_ \
\___/|_.__// \___\__|\__|\___|_| \___/\_,_| .__/
|__/ |_|
*/
// ObjectGroup is a TMX file structure holding a Tiled ObjectGroup.
type ObjectGroup struct {
Name string `xml:"name,attr"`
Color string `xml:"color,attr"`
OffSetX float64 `xml:"offsetx,attr"`
OffSetY float64 `xml:"offsety,attr"`
Opacity float32 `xml:"opacity,attr"`
Visible bool `xml:"visible,attr"`
Properties []*Property `xml:"properties>property"`
Objects []*Object `xml:"object"`
// parentMap is the map which contains this object
parentMap *Map
}
func (og *ObjectGroup) String() string {
return fmt.Sprintf("ObjectGroup{Name: %s, Properties: %v, Objects: %v}", og.Name, og.Properties, og.Objects)
}
func (og *ObjectGroup) decode() error {
for _, o := range og.Objects {
// Have the object decode its' type
o.hydrateType()
// Set the x,y offsets of the layer onto the object
o.X += og.OffSetX
o.Y -= og.OffSetY
}
return nil
}
// GetObjectByName returns the ObjectGroups' Objects by their name
func (og *ObjectGroup) GetObjectByName(name string) []*Object {
var objs []*Object
for _, o := range og.Objects {
if o.Name == name {
objs = append(objs, o)
}
}
return objs
}
func (og *ObjectGroup) flipY() {
for _, o := range og.Objects {
o.flipY()
}
}
func (og *ObjectGroup) setParent(m *Map) {
og.parentMap = m
for _, p := range og.Properties {
p.setParent(m)
}
for _, o := range og.Objects {
o.setParent(m)
}
}