Skip to content

Commit dc6578b

Browse files
committed
Dependency update and code cleanup
1 parent 5a50648 commit dc6578b

File tree

8 files changed

+26
-25
lines changed

8 files changed

+26
-25
lines changed

cmd/tmx2img/main.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,8 @@ func main() {
4343
return
4444
}
4545
defer w.Close()
46-
rend.SaveAsPng(w)
46+
if err := rend.SaveAsPng(w); err != nil {
47+
fmt.Println(err)
48+
return
49+
}
4750
}

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ go 1.16
44

55
require (
66
github.com/disintegration/imaging v1.6.2
7-
github.com/stretchr/testify v1.8.0
7+
github.com/stretchr/testify v1.8.1
88
)

go.sum

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
77
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
88
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
99
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
10+
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
1011
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
11-
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
1212
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
13+
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
14+
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
1315
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 h1:hVwzHzIUGRjiF7EcUjqNxk3NCfkPxbDKRdnNE1Rpg0U=
1416
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
1517
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

tiled_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ func TestParseHexColor(t *testing.T) {
377377

378378
for _, c := range cases {
379379
color := &HexColor{}
380-
color.UnmarshalXMLAttr(c.attr)
380+
assert.NoError(t, color.UnmarshalXMLAttr(c.attr))
381381
assert.Equal(t, c.color, color.c, c.name)
382382
}
383383
}

tmx_data.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,12 @@ import (
2929
"encoding/base64"
3030
"errors"
3131
"io"
32-
"io/ioutil"
3332
"strconv"
3433
"strings"
3534
)
3635

37-
var (
38-
// ErrUnknownCompression error is returned when file contains invalid compression method
39-
ErrUnknownCompression = errors.New("tiled: invalid compression method")
40-
)
36+
// ErrUnknownCompression error is returned when file contains invalid compression method
37+
var ErrUnknownCompression = errors.New("tiled: invalid compression method")
4138

4239
// Data is raw data
4340
type Data struct {
@@ -82,7 +79,7 @@ func (d *Data) decodeBase64() (data []byte, err error) {
8279
return
8380
}
8481

85-
return ioutil.ReadAll(comr)
82+
return io.ReadAll(comr)
8683
}
8784

8885
func (d *Data) decodeCSV() ([]uint32, error) {

tmx_map.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ func (m *Map) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
203203

204204
// Decode object groups.
205205
for _, g := range item.ObjectGroups {
206-
g.DecodeObjectGroup((*Map)(&item))
206+
if err := g.DecodeObjectGroup((*Map)(&item)); err != nil {
207+
return err
208+
}
207209
}
208210

209211
*m = (Map)(item)

tmx_object.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@ import (
3030
"strings"
3131
)
3232

33-
var (
34-
// ErrInvalidObjectPoint error is returned if there is error parsing object points
35-
ErrInvalidObjectPoint = errors.New("tiled: invalid object point")
36-
)
33+
// ErrInvalidObjectPoint error is returned if there is error parsing object points
34+
var ErrInvalidObjectPoint = errors.New("tiled: invalid object point")
3735

3836
// ObjectGroup is in fact a map layer, and is hence called "object layer" in Tiled Qt
3937
type ObjectGroup struct {
@@ -64,18 +62,23 @@ type ObjectGroup struct {
6462
}
6563

6664
// DecodeObjectGroup decodes object group data
67-
func (g *ObjectGroup) DecodeObjectGroup(m *Map) {
65+
func (g *ObjectGroup) DecodeObjectGroup(m *Map) error {
6866
for _, object := range g.Objects {
6967
if object.GID > 0 {
7068
// Initialize all tilesets that are referenced by tile objects. Otherwise,
7169
// if a tileset is used by an object tile but not used by any layer it
7270
// won't be loaded.
73-
m.TileGIDToTile(object.GID)
71+
if _, err := m.TileGIDToTile(object.GID); err != nil {
72+
return err
73+
}
7474
}
7575
if len(object.TemplateSource) > 0 {
76-
object.initTemplate(m)
76+
if err := object.initTemplate(m); err != nil {
77+
return err
78+
}
7779
}
7880
}
81+
return nil
7982
}
8083

8184
// UnmarshalXML decodes a single XML element beginning with the given start element.
@@ -181,8 +184,7 @@ func (o *Object) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
181184
}
182185

183186
// Ellipse is used to mark an object as an ellipse.
184-
type Ellipse struct {
185-
}
187+
type Ellipse struct{}
186188

187189
// 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.
188190
// By default, the first point is created as 0,0 denoting that the point will originate exactly where the object is placed.

tmx_tileset.go

-5
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,12 @@ type AnimationFrame struct {
123123

124124
// GetTileRect returns a rectangle that contains the tile in the tileset.Image
125125
func (ts *Tileset) GetTileRect(tileID uint32) image.Rectangle {
126-
tilesetTileCount := ts.TileCount
127126
tilesetColumns := ts.Columns
128127

129128
if tilesetColumns == 0 {
130129
tilesetColumns = ts.Image.Width / (ts.TileWidth + ts.Spacing)
131130
}
132131

133-
if tilesetTileCount == 0 {
134-
tilesetTileCount = (ts.Image.Height / (ts.TileHeight + ts.Spacing)) * tilesetColumns
135-
}
136-
137132
x := int(tileID) % tilesetColumns
138133
y := int(tileID) / tilesetColumns
139134

0 commit comments

Comments
 (0)