-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/save_load_tileset
- Loading branch information
Showing
24 changed files
with
458 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
repo: lafriks/go-tiled | ||
|
||
service: github | ||
|
||
groups: | ||
- | ||
name: BREAKING | ||
labels: | ||
- breaking | ||
- | ||
name: ENHANCEMENTS | ||
labels: | ||
- enhancement | ||
- | ||
name: BUGFIXES | ||
labels: | ||
- bug | ||
- | ||
name: TESTING | ||
labels: | ||
- testing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,30 @@ | ||
--- | ||
kind: pipeline | ||
type: docker | ||
name: testing | ||
|
||
clone: | ||
depth: 50 | ||
|
||
trigger: | ||
branch: | ||
- master | ||
event: | ||
- push | ||
- pull_request | ||
|
||
steps: | ||
- name: lint | ||
image: golang:1.11 | ||
pull: true | ||
image: golang:1.16 | ||
pull: always | ||
commands: | ||
- go tool vet -all -shadowstrict . | ||
- go vet -all . | ||
- go get -u github.com/mgechev/revive | ||
- revive -config .revive.toml -exclude=./vendor/... ./... | ||
|
||
- name: test | ||
image: golang:1.11 | ||
pull: true | ||
image: golang:1.16 | ||
pull: always | ||
commands: | ||
- go test -v . | ||
- go vet |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
tab_width = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.{go,tmpl}] | ||
indent_style = tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,74 @@ | ||
# go-tiled | ||
|
||
[![godoc reference](https://img.shields.io/badge/godoc-reference-5272B4)](https://pkg.go.dev/github.com/lafriks/go-tiled?tab=doc) | ||
[![Build Status](https://cloud.drone.io/api/badges/lafriks/go-tiled/status.svg)](https://cloud.drone.io/lafriks/go-tiled) | ||
[![PkgGoDev](https://pkg.go.dev/badge/github.com/lafriks/go-tiled)](https://pkg.go.dev/github.com/lafriks/go-tiled) | ||
[![Build Status](https://cloud.drone.io/api/badges/lafriks/go-tiled/status.svg?ref=refs/heads/master)](https://cloud.drone.io/lafriks/go-tiled) | ||
|
||
Go library to parse Tiled map editor file format (TMX) and render map to image. Currently supports only orthogonal rendering out-of-the-box. | ||
|
||
## Installing | ||
|
||
$ go get github.com/lafriks/go-tiled | ||
```sh | ||
go get github.com/lafriks/go-tiled | ||
``` | ||
|
||
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. | ||
|
||
## Basic Usage: | ||
## Basic Usage | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/lafriks/go-tiled" | ||
"github.com/lafriks/go-tiled/render" | ||
"github.com/lafriks/go-tiled" | ||
"github.com/lafriks/go-tiled/render" | ||
) | ||
|
||
const mapPath = "maps/map.tmx" // Path to your Tiled Map. | ||
|
||
func main() { | ||
// Parse .tmx file. | ||
gameMap, err := tiled.LoadFromFile(mapPath) | ||
if err != nil { | ||
fmt.Printf("error parsing map: %s", err.Error() | ||
os.Exit(2) | ||
} | ||
|
||
fmt.Println(gameMap) | ||
|
||
// You can also render the map to an in-memory image for direct | ||
// use with the default Renderer, or by making your own. | ||
renderer, err := render.NewRenderer(gameMap) | ||
if err != nil { | ||
fmt.Printf("map unsupported for rendering: %s", err.Error() | ||
os.Exit(2) | ||
} | ||
|
||
// Render just layer 0 to the Renderer. | ||
err = renderer.RenderLayer(0) | ||
if err != nil { | ||
fmt.Printf("layer unsupported for rendering: %s", err.Error() | ||
os.Exit(2) | ||
} | ||
|
||
// Get a reference to the Renderer's output, an image.NRGBA struct. | ||
img := renderer.Result | ||
|
||
// Clear the render result after copying the output if separation of | ||
// layers is desired. | ||
renderer.Clear() | ||
|
||
// And so on. You can also export the image to a file by using the | ||
// Renderer's Save functions. | ||
|
||
gameMap, err := tiled.LoadFromFile(mapPath) | ||
if err != nil { | ||
fmt.Printf("error parsing map: %s", err.Error() | ||
os.Exit(2) | ||
} | ||
|
||
fmt.Println(gameMap) | ||
|
||
// You can also render the map to an in-memory image for direct | ||
// use with the default Renderer, or by making your own. | ||
renderer, err := render.NewRenderer(gameMap) | ||
if err != nil { | ||
fmt.Printf("map unsupported for rendering: %s", err.Error() | ||
os.Exit(2) | ||
} | ||
|
||
// Render just layer 0 to the Renderer. | ||
err = renderer.RenderLayer(0) | ||
if err != nil { | ||
fmt.Printf("layer unsupported for rendering: %s", err.Error() | ||
os.Exit(2) | ||
} | ||
|
||
// Get a reference to the Renderer's output, an image.NRGBA struct. | ||
img := renderer.Result | ||
|
||
// Clear the render result after copying the output if separation of | ||
// layers is desired. | ||
renderer.Clear() | ||
|
||
// And so on. You can also export the image to a file by using the | ||
// Renderer's Save functions. | ||
} | ||
|
||
``` | ||
|
||
## Documentation | ||
|
||
For further documentation, see https://pkg.go.dev/github.com/lafriks/go-tiled or run: | ||
|
||
$ godoc github.com/lafriks/go-tiled | ||
For further documentation, see <https://pkg.go.dev/github.com/lafriks/go-tiled> or run: | ||
|
||
```sh | ||
godoc github.com/lafriks/go-tiled | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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"> | ||
<tileset firstgid="1" source="tilesets/kenny-racing/kenny-racing-tileset-grass.tsx"/> | ||
<layer id="1" name="Tile Layer 1" width="10" height="10"> | ||
<data encoding="base64" compression="zlib"> | ||
eJxjYWBgYEHCjEDMhCaGDbMBMTsOOVxmoIvjMgOXODXcRipGtxOXG9DtJNcNADh3AZE= | ||
</data> | ||
</layer> | ||
</map> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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"> | ||
<tileset firstgid="1" source="tilesets/test2.tsx"/> | ||
<objectgroup id="3" name="Off-tile objects"> | ||
<object id="1" gid="8" x="146.667" y="108" width="32" height="32"> | ||
</object> | ||
</objectgroup> | ||
</map> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
module github.com/lafriks/go-tiled | ||
|
||
go 1.11 | ||
go 1.16 | ||
|
||
require ( | ||
github.com/disintegration/imaging v1.6.0 | ||
github.com/stretchr/testify v1.3.0 | ||
github.com/disintegration/imaging v1.6.2 | ||
github.com/stretchr/testify v1.7.0 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/disintegration/imaging v1.6.0 h1:nVPXRUUQ36Z7MNf0O77UzgnOb1mkMMor7lmJMJXc/mA= | ||
github.com/disintegration/imaging v1.6.0/go.mod h1:xuIt+sRxDFrHS0drzXUlCJthkJ8k7lkkUojDSR247MQ= | ||
github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c= | ||
github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4= | ||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
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/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= | ||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | ||
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81 h1:00VmoueYNlNz/aHIilyyQz/MHSqGoWJzpFv/HW8xpzI= | ||
golang.org/x/image v0.0.0-20180708004352-c73c2afc3b81/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= | ||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= | ||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
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= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= | ||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.