-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmx_test.go
49 lines (41 loc) · 1.02 KB
/
tmx_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package tmx
import (
"encoding/xml"
"fmt"
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestLoad(t *testing.T) {
fp, err := os.Open("resources/arena.tmx")
require.NoError(t, err)
m, err := Load(fp)
defer fp.Close()
require.NoError(t, err)
t.Log(m)
out, err := xml.MarshalIndent(m, "", " ")
assert.NoError(t, err)
t.Log(string(out))
layer := m.Layers[1]
iter, err := layer.Data.Iter()
assert.NoError(t, err)
for iter.Next() {
fmt.Printf("%02d ", iter.Get().GID)
if iter.GetIndex()%*layer.Width == *layer.Width-1 {
fmt.Println("")
}
}
assert.NoError(t, iter.Error())
}
func TestLoadTSX(t *testing.T) {
fp, err := os.Open("resources/cave.tmx")
assert.NoError(t, err)
defer fp.Close()
m, err := Load(fp)
assert.NoError(t, err)
require.Equal(t, 1, len(m.TileSets))
assert.NotEmpty(t, m.TileSets[0].Source) // from tmx
assert.EqualValues(t, 1, m.TileSets[0].FirstGID) // from tmx
assert.Equal(t, "cave", m.TileSets[0].Name) // from tsx
}