Skip to content

Commit dd74439

Browse files
authored
ObjectGroup: set defaults (lafriks#52)
1 parent ad181ed commit dd74439

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

tiled_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ func TestLoadFromFile(t *testing.T) {
8181
assert.Len(t, m.Layers, 1)
8282
assert.Equal(t, uint32(1), m.Layers[0].ID)
8383

84+
// Test ObjectGroups.Visible defaults to true
8485
assert.Len(t, m.ObjectGroups, 1)
8586
assert.Equal(t, uint32(2), m.ObjectGroups[0].ID)
87+
assert.Equal(t, true, m.ObjectGroups[0].Visible)
8688

8789
// Test Object.Visible defaults to true
8890
assert.Len(t, m.ObjectGroups[0].Objects, 1)

tmx_defaults.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type aliasLayer struct {
2929
}
3030
type aliasMap Map
3131
type aliasObject Object
32+
type aliasObjectGroup ObjectGroup
3233
type aliasText Text
3334

3435
// SetDefaults provides default values for Group.
@@ -59,6 +60,12 @@ func (a *aliasObject) SetDefaults() {
5960
a.Visible = true
6061
}
6162

63+
// SetDefaults provides default values for ObjectGroup.
64+
func (a *aliasObjectGroup) SetDefaults() {
65+
a.Visible = true
66+
a.Opacity = 1
67+
}
68+
6269
// SetDefaults provides default values for Text.
6370
func (a *aliasText) SetDefaults() {
6471
a.FontFamily = "sans-serif"

tmx_object.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ func (g *ObjectGroup) DecodeObjectGroup(m *Map) {
7272
}
7373
}
7474

75+
// UnmarshalXML decodes a single XML element beginning with the given start element.
76+
func (g *ObjectGroup) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
77+
item := aliasObjectGroup{}
78+
item.SetDefaults()
79+
80+
if err := d.DecodeElement(&item, &start); err != nil {
81+
return err
82+
}
83+
84+
*g = (ObjectGroup)(item)
85+
86+
return nil
87+
}
88+
7589
// Object is used to add custom information to your tile map, such as spawn points, warps, exits, etc.
7690
type Object struct {
7791
// Unique ID of the object. Each object that is placed on a map gets a unique id. Even if an object was deleted, no object gets the same ID.

0 commit comments

Comments
 (0)