Skip to content

Commit 2d4c288

Browse files
cleanup
1 parent 87bd542 commit 2d4c288

File tree

7 files changed

+45
-43
lines changed

7 files changed

+45
-43
lines changed
File renamed without changes.

tiled.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,7 @@ func SaveTilesetToWriter(tileset *Tileset, w io.Writer) error {
110110
encoder.Indent("", " ")
111111
return encoder.Encode(tileset)
112112
}
113+
114+
func b(v bool) *bool {
115+
return &v
116+
}

tiled_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func TestFont(t *testing.T) {
184184
assert.Equal(t, false, text.Italic)
185185
assert.Equal(t, false, text.Underline)
186186
assert.Equal(t, false, text.Strikethrough)
187-
assert.Equal(t, true, text.Kerning)
187+
assert.Equal(t, true, *text.Kerning)
188188
assert.Equal(t, "left", text.HAlign)
189189
assert.Equal(t, "top", text.VAlign)
190190
}

tmx_object.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type ObjectGroup struct {
4747
// The opacity of the layer as a value from 0 to 1. Defaults to 1.
4848
Opacity float32 `xml:"opacity,attr,omitempty"`
4949
// Whether the layer is shown (1) or hidden (0). Defaults to 1.
50-
Visible *bool `xml:"visible,attr"` // TODO: default to non 0 value
50+
Visible *bool `xml:"visible,attr"`
5151
// Rendering offset for this layer in pixels. Defaults to 0. (since 0.14)
5252
OffsetX int `xml:"offsetx,attr,omitempty"`
5353
// Rendering offset for this layer in pixels. Defaults to 0. (since 0.14)
@@ -82,7 +82,7 @@ type Object struct {
8282
// An reference to a tile (optional).
8383
GID uint32 `xml:"gid,attr,omitempty"`
8484
// Whether the object is shown (1) or hidden (0). Defaults to 1. (since 0.9)
85-
Visible *bool `xml:"visible,attr"` // TODO: default not 0
85+
Visible *bool `xml:"visible,attr"`
8686
// Custom properties
8787
Properties *Properties `xml:"properties,omitempty"`
8888
// Used to mark an object as an ellipse. The existing x, y, width and height attributes are used to determine the size of the ellipse.
@@ -162,27 +162,27 @@ type Text struct {
162162
// The actual text
163163
Text string `xml:",chardata"`
164164
// The font family used (default: "sans-serif")
165-
FontFamily string `xml:"fontfamily,attr"`
165+
FontFamily string `xml:"fontfamily,attr,omitempty"`
166166
// The size of the font in pixels (not using points, because other sizes in the TMX format are also using pixels) (default: 16)
167-
Size int `xml:"pixelsize,attr"`
167+
Size int `xml:"pixelsize,attr,omitempty"`
168168
// Whether word wrapping is enabled (1) or disabled (0). Defaults to 0.
169-
Wrap bool `xml:"wrap,attr"`
169+
Wrap bool `xml:"wrap,attr,omitempty"`
170170
// Color of the text in #AARRGGBB or #RRGGBB format (default: #000000)
171-
Color *HexColor `xml:"color,attr"`
171+
Color *HexColor `xml:"color,attr,omitempty"`
172172
// Whether the font is bold (1) or not (0). Defaults to 0.
173-
Bold bool `xml:"bold,attr"`
173+
Bold bool `xml:"bold,attr,omitempty"`
174174
// Whether the font is italic (1) or not (0). Defaults to 0.
175-
Italic bool `xml:"italic,attr"`
175+
Italic bool `xml:"italic,attr,omitempty"`
176176
// Whether a line should be drawn below the text (1) or not (0). Defaults to 0.
177-
Underline bool `xml:"underline,attr"`
177+
Underline bool `xml:"underline,attr,omitempty"`
178178
// Whether a line should be drawn through the text (1) or not (0). Defaults to 0.
179-
Strikethrough bool `xml:"strikeout,attr"`
179+
Strikethrough bool `xml:"strikeout,attr,omitempty"`
180180
// Whether kerning should be used while rendering the text (1) or not (0). Default to 1.
181-
Kerning bool `xml:"kerning,attr"`
181+
Kerning *bool `xml:"kerning,attr,omitempty"`
182182
// Horizontal alignment of the text within the object (left (default), center, right or justify (since Tiled 1.2.1))
183-
HAlign string `xml:"halign,attr"`
183+
HAlign string `xml:"halign,attr,omitempty"`
184184
// Vertical alignment of the text within the object (top (default), center or bottom)
185-
VAlign string `xml:"valign,attr"`
185+
VAlign string `xml:"valign,attr,omitempty"`
186186
}
187187

188188
// UnmarshalXML decodes a single XML element beginning with the given start element.
@@ -192,7 +192,7 @@ func (t *Text) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
192192
item := Alias{
193193
FontFamily: "sans-serif",
194194
Size: 16,
195-
Kerning: true,
195+
Kerning: b(true),
196196
HAlign: "left",
197197
VAlign: "top",
198198
Color: &HexColor{},

tmx_property_test.go

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,27 @@ import (
3131
func TestGetProperty(t *testing.T) {
3232

3333
props := Properties{
34-
{
35-
Name: "string-name",
36-
Type: "string",
37-
Value: "string-value",
38-
},
39-
{
40-
Name: "int-name",
41-
Type: "int",
42-
Value: "123",
43-
},
44-
{
45-
Name: "float-name",
46-
Type: "float",
47-
Value: "1.23",
48-
},
49-
{
50-
Name: "bool-name",
51-
Type: "boolean",
52-
Value: "true",
34+
Property: []*Property{
35+
{
36+
Name: "string-name",
37+
Type: "string",
38+
Value: "string-value",
39+
},
40+
{
41+
Name: "int-name",
42+
Type: "int",
43+
Value: "123",
44+
},
45+
{
46+
Name: "float-name",
47+
Type: "float",
48+
Value: "1.23",
49+
},
50+
{
51+
Name: "bool-name",
52+
Type: "boolean",
53+
Value: "true",
54+
},
5355
},
5456
}
5557

tmx_tileset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ type TilesetTile struct {
9595
// Embedded image
9696
Image *Image `xml:"image"`
9797
// Tile object groups
98-
ObjectGroups []*ObjectGroup `xml:"objectgroup"`
98+
ObjectGroups []*ObjectGroup `xml:"objectgroup,omitempty"`
9999
// List of animation frames
100100
Animation *Animation `xml:"animation,omitempty"`
101101
}

tmx_tileset_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var testLoadTilesetFile = &Tileset{
5050
Version: "1.2",
5151
}
5252

53-
var testLoadTileFile = &TilesetTile{
53+
var testLoadTilesetTileFile = &TilesetTile{
5454
ID: 464,
5555
Animation: &Animation{
5656
Frame: []*AnimationFrame{
@@ -123,7 +123,7 @@ func TestSaveTileset(t *testing.T) {
123123
}
124124

125125
func TestLoadTile(t *testing.T) {
126-
tsxFile, err := os.Open(filepath.Join(GetAssetsDirectory(), "tilesets/testLoadTile.tsx"))
126+
tsxFile, err := os.Open(filepath.Join(GetAssetsDirectory(), "tilesets/testLoadTilesetTile.tsx"))
127127
assert.Nil(t, err)
128128
defer tsxFile.Close()
129129

@@ -132,11 +132,11 @@ func TestLoadTile(t *testing.T) {
132132
assert.Len(t, tsx.Tiles, 1)
133133

134134
tile := tsx.Tiles[0]
135-
assert.Equal(t, testLoadTileFile, tile)
135+
assert.Equal(t, testLoadTilesetTileFile, tile)
136136
}
137137

138138
func TestSaveTile(t *testing.T) {
139-
tsxFile, err := os.Open(filepath.Join(GetAssetsDirectory(), "tilesets/testLoadTile.tsx"))
139+
tsxFile, err := os.Open(filepath.Join(GetAssetsDirectory(), "tilesets/testLoadTilesetTile.tsx"))
140140
assert.Nil(t, err)
141141
defer tsxFile.Close()
142142

@@ -185,7 +185,3 @@ func (n *node) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
185185
}
186186
return nil
187187
}
188-
189-
func b(v bool) *bool {
190-
return &v
191-
}

0 commit comments

Comments
 (0)