Skip to content

Commit c2a3f9b

Browse files
Merge branch 'master' into feature/save_load_tileset
2 parents 67d41bf + 8f6d20a commit c2a3f9b

24 files changed

+458
-124
lines changed

.changelog.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
repo: lafriks/go-tiled
2+
3+
service: github
4+
5+
groups:
6+
-
7+
name: BREAKING
8+
labels:
9+
- breaking
10+
-
11+
name: ENHANCEMENTS
12+
labels:
13+
- enhancement
14+
-
15+
name: BUGFIXES
16+
labels:
17+
- bug
18+
-
19+
name: TESTING
20+
labels:
21+
- testing

.drone.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,30 @@
1+
---
12
kind: pipeline
3+
type: docker
24
name: testing
35

46
clone:
57
depth: 50
68

9+
trigger:
10+
branch:
11+
- master
12+
event:
13+
- push
14+
- pull_request
15+
716
steps:
817
- name: lint
9-
image: golang:1.11
10-
pull: true
18+
image: golang:1.16
19+
pull: always
1120
commands:
12-
- go tool vet -all -shadowstrict .
21+
- go vet -all .
1322
- go get -u github.com/mgechev/revive
1423
- revive -config .revive.toml -exclude=./vendor/... ./...
1524

1625
- name: test
17-
image: golang:1.11
18-
pull: true
26+
image: golang:1.16
27+
pull: always
1928
commands:
2029
- go test -v .
2130
- go vet

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
tab_width = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.{go,tmpl}]
13+
indent_style = tab

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

README.md

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,74 @@
11
# go-tiled
22

3-
[![godoc reference](https://img.shields.io/badge/godoc-reference-5272B4)](https://pkg.go.dev/github.com/lafriks/go-tiled?tab=doc)
4-
[![Build Status](https://cloud.drone.io/api/badges/lafriks/go-tiled/status.svg)](https://cloud.drone.io/lafriks/go-tiled)
3+
[![PkgGoDev](https://pkg.go.dev/badge/github.com/lafriks/go-tiled)](https://pkg.go.dev/github.com/lafriks/go-tiled)
4+
[![Build Status](https://cloud.drone.io/api/badges/lafriks/go-tiled/status.svg?ref=refs/heads/master)](https://cloud.drone.io/lafriks/go-tiled)
55

66
Go library to parse Tiled map editor file format (TMX) and render map to image. Currently supports only orthogonal rendering out-of-the-box.
77

88
## Installing
99

10-
$ go get github.com/lafriks/go-tiled
10+
```sh
11+
go get github.com/lafriks/go-tiled
12+
```
1113

1214
You can use `go get -u` to update the package. You can also just import and start using the package directly if you're using Go modules, and Go will then download the package on first compilation.
1315

14-
## Basic Usage:
16+
## Basic Usage
1517

1618
```go
1719
package main
1820

1921
import (
20-
"fmt"
21-
"os"
22+
"fmt"
23+
"os"
2224

23-
"github.com/lafriks/go-tiled"
24-
"github.com/lafriks/go-tiled/render"
25+
"github.com/lafriks/go-tiled"
26+
"github.com/lafriks/go-tiled/render"
2527
)
2628

2729
const mapPath = "maps/map.tmx" // Path to your Tiled Map.
2830

2931
func main() {
3032
// Parse .tmx file.
31-
gameMap, err := tiled.LoadFromFile(mapPath)
32-
if err != nil {
33-
fmt.Printf("error parsing map: %s", err.Error()
34-
os.Exit(2)
35-
}
36-
37-
fmt.Println(gameMap)
38-
39-
// You can also render the map to an in-memory image for direct
40-
// use with the default Renderer, or by making your own.
41-
renderer, err := render.NewRenderer(gameMap)
42-
if err != nil {
43-
fmt.Printf("map unsupported for rendering: %s", err.Error()
44-
os.Exit(2)
45-
}
46-
47-
// Render just layer 0 to the Renderer.
48-
err = renderer.RenderLayer(0)
49-
if err != nil {
50-
fmt.Printf("layer unsupported for rendering: %s", err.Error()
51-
os.Exit(2)
52-
}
53-
54-
// Get a reference to the Renderer's output, an image.NRGBA struct.
55-
img := renderer.Result
56-
57-
// Clear the render result after copying the output if separation of
58-
// layers is desired.
59-
renderer.Clear()
60-
61-
// And so on. You can also export the image to a file by using the
62-
// Renderer's Save functions.
63-
33+
gameMap, err := tiled.LoadFromFile(mapPath)
34+
if err != nil {
35+
fmt.Printf("error parsing map: %s", err.Error()
36+
os.Exit(2)
37+
}
38+
39+
fmt.Println(gameMap)
40+
41+
// You can also render the map to an in-memory image for direct
42+
// use with the default Renderer, or by making your own.
43+
renderer, err := render.NewRenderer(gameMap)
44+
if err != nil {
45+
fmt.Printf("map unsupported for rendering: %s", err.Error()
46+
os.Exit(2)
47+
}
48+
49+
// Render just layer 0 to the Renderer.
50+
err = renderer.RenderLayer(0)
51+
if err != nil {
52+
fmt.Printf("layer unsupported for rendering: %s", err.Error()
53+
os.Exit(2)
54+
}
55+
56+
// Get a reference to the Renderer's output, an image.NRGBA struct.
57+
img := renderer.Result
58+
59+
// Clear the render result after copying the output if separation of
60+
// layers is desired.
61+
renderer.Clear()
62+
63+
// And so on. You can also export the image to a file by using the
64+
// Renderer's Save functions.
6465
}
65-
6666
```
6767

6868
## Documentation
6969

70-
For further documentation, see https://pkg.go.dev/github.com/lafriks/go-tiled or run:
71-
72-
$ godoc github.com/lafriks/go-tiled
70+
For further documentation, see <https://pkg.go.dev/github.com/lafriks/go-tiled> or run:
7371

72+
```sh
73+
godoc github.com/lafriks/go-tiled
74+
```

assets/groups.tmx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<layer id="3" name="Tile Layer 2" width="20" height="20">
1111
<data encoding="base64" compression="zlib">
1212
eJxjYBgFo2AUjIJRMApIBwAGQAAB
13-
</data>
13+
</data>
1414
</layer>
1515
<group id="8" name="C">
1616
<objectgroup id="7" name="Object Layer 1"/>

assets/test3.tmx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<map version="1.2" tiledversion="1.2.4" orientation="orthogonal" renderorder="right-down" width="10" height="10" tilewidth="128" tileheight="128" infinite="0" nextlayerid="2" nextobjectid="1">
3+
<tileset firstgid="1" source="tilesets/kenny-racing/kenny-racing-tileset-grass.tsx"/>
4+
<layer id="1" name="Tile Layer 1" width="10" height="10">
5+
<data encoding="base64" compression="zlib">
6+
eJxjYWBgYEHCjEDMhCaGDbMBMTsOOVxmoIvjMgOXODXcRipGtxOXG9DtJNcNADh3AZE=
7+
</data>
8+
</layer>
9+
</map>

assets/test_tileobject.tmx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<map version="1.2" tiledversion="1.2.3" orientation="orthogonal" renderorder="right-down" width="10" height="10" tilewidth="32" tileheight="32" infinite="0" nextlayerid="4" nextobjectid="2">
3+
<tileset firstgid="1" source="tilesets/test2.tsx"/>
4+
<objectgroup id="3" name="Off-tile objects">
5+
<object id="1" gid="8" x="146.667" y="108" width="32" height="32">
6+
</object>
7+
</objectgroup>
8+
</map>

assets/tilesets/testLoadTilesetTile.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<tileset version="1.2" tiledversion="1.2.3" name="ProjectUtumno_full" tilewidth="32" tileheight="32" tilecount="6080" columns="64">
33
<image source="ProjectUtumno_full.png" width="2048" height="3040"/>
44
<tile id="464">
5-
<objectgroup draworder="index">
6-
<object id="1" x="-0.25" y="17.75" width="32.375" height="6.125"/>
5+
<objectgroup opacity="1" visible="true" draworder="index">
6+
<object id="1" x="-0.25" y="17.75" width="32.375" height="6.125" visible="true"/>
77
</objectgroup>
88
<animation>
99
<frame tileid="75" duration="500"/>

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module github.com/lafriks/go-tiled
22

3-
go 1.11
3+
go 1.16
44

55
require (
6-
github.com/disintegration/imaging v1.6.0
7-
github.com/stretchr/testify v1.3.0
6+
github.com/disintegration/imaging v1.6.2
7+
github.com/stretchr/testify v1.7.0
88
)

0 commit comments

Comments
 (0)