Skip to content

Commit

Permalink
Dependency update and code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lafriks committed Dec 5, 2022
1 parent 5a50648 commit dc6578b
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 25 deletions.
5 changes: 4 additions & 1 deletion cmd/tmx2img/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@ func main() {
return
}
defer w.Close()
rend.SaveAsPng(w)
if err := rend.SaveAsPng(w); err != nil {
fmt.Println(err)
return
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ go 1.16

require (
github.com/disintegration/imaging v1.6.2
github.com/stretchr/testify v1.8.0
github.com/stretchr/testify v1.8.1
)
4 changes: 3 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 h1:hVwzHzIUGRjiF7EcUjqNxk3NCfkPxbDKRdnNE1Rpg0U=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down
2 changes: 1 addition & 1 deletion tiled_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func TestParseHexColor(t *testing.T) {

for _, c := range cases {
color := &HexColor{}
color.UnmarshalXMLAttr(c.attr)
assert.NoError(t, color.UnmarshalXMLAttr(c.attr))
assert.Equal(t, c.color, color.c, c.name)
}
}
Expand Down
9 changes: 3 additions & 6 deletions tmx_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,12 @@ import (
"encoding/base64"
"errors"
"io"
"io/ioutil"
"strconv"
"strings"
)

var (
// ErrUnknownCompression error is returned when file contains invalid compression method
ErrUnknownCompression = errors.New("tiled: invalid compression method")
)
// ErrUnknownCompression error is returned when file contains invalid compression method
var ErrUnknownCompression = errors.New("tiled: invalid compression method")

// Data is raw data
type Data struct {
Expand Down Expand Up @@ -82,7 +79,7 @@ func (d *Data) decodeBase64() (data []byte, err error) {
return
}

return ioutil.ReadAll(comr)
return io.ReadAll(comr)
}

func (d *Data) decodeCSV() ([]uint32, error) {
Expand Down
4 changes: 3 additions & 1 deletion tmx_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ func (m *Map) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {

// Decode object groups.
for _, g := range item.ObjectGroups {
g.DecodeObjectGroup((*Map)(&item))
if err := g.DecodeObjectGroup((*Map)(&item)); err != nil {
return err
}
}

*m = (Map)(item)
Expand Down
20 changes: 11 additions & 9 deletions tmx_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,8 @@ import (
"strings"
)

var (
// ErrInvalidObjectPoint error is returned if there is error parsing object points
ErrInvalidObjectPoint = errors.New("tiled: invalid object point")
)
// ErrInvalidObjectPoint error is returned if there is error parsing object points
var ErrInvalidObjectPoint = errors.New("tiled: invalid object point")

// ObjectGroup is in fact a map layer, and is hence called "object layer" in Tiled Qt
type ObjectGroup struct {
Expand Down Expand Up @@ -64,18 +62,23 @@ type ObjectGroup struct {
}

// DecodeObjectGroup decodes object group data
func (g *ObjectGroup) DecodeObjectGroup(m *Map) {
func (g *ObjectGroup) DecodeObjectGroup(m *Map) error {
for _, object := range g.Objects {
if object.GID > 0 {
// Initialize all tilesets that are referenced by tile objects. Otherwise,
// if a tileset is used by an object tile but not used by any layer it
// won't be loaded.
m.TileGIDToTile(object.GID)
if _, err := m.TileGIDToTile(object.GID); err != nil {
return err
}
}
if len(object.TemplateSource) > 0 {
object.initTemplate(m)
if err := object.initTemplate(m); err != nil {
return err
}
}
}
return nil
}

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

// Ellipse is used to mark an object as an ellipse.
type Ellipse struct {
}
type Ellipse struct{}

// 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.
// By default, the first point is created as 0,0 denoting that the point will originate exactly where the object is placed.
Expand Down
5 changes: 0 additions & 5 deletions tmx_tileset.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,12 @@ type AnimationFrame struct {

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

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

if tilesetTileCount == 0 {
tilesetTileCount = (ts.Image.Height / (ts.TileHeight + ts.Spacing)) * tilesetColumns
}

x := int(tileID) % tilesetColumns
y := int(tileID) / tilesetColumns

Expand Down

0 comments on commit dc6578b

Please sign in to comment.