-
Notifications
You must be signed in to change notification settings - Fork 2
/
tmx_test.go
133 lines (113 loc) · 2.6 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// Copyright 2012 Lightpoke. All rights reserved.
// This source code is subject to the terms and
// conditions defined in the "License.txt" file.
package tmx
import (
"io/ioutil"
"os"
"path/filepath"
"testing"
)
func verify(t *testing.T, name string) {
// Open file
f, err := os.Open(filepath.Join("testdata", name))
if err != nil {
t.Fatal(err)
}
// Read file data
data, err := ioutil.ReadAll(f)
if err != nil {
t.Fatal(err)
}
// Load the map
m, err := Parse(data)
if err != nil {
t.Fatal(err)
}
// External tilesets in the map must be loaded seperately
for _, ts := range m.Tilesets {
if len(ts.Source) > 0 {
// Open tsx file
f, err := os.Open(filepath.Join("testdata", ts.Source))
if err != nil {
t.Fatal(err)
}
// Read file data
data, err := ioutil.ReadAll(f)
if err != nil {
t.Fatal(err)
}
// Load the tileset
err = ts.Load(data)
if err != nil {
t.Fatal(err)
}
}
}
if m.VersionMajor != 1 || m.VersionMinor != 0 {
t.Log(m.VersionMajor, m.VersionMinor)
t.Fatal("incorrect version number")
}
if m.Orientation != Orthogonal {
t.Log(m.Orientation)
t.Fatal("incorrect orientation")
}
if m.Width != 60 || m.Height != 10 {
t.Log(m.Width)
t.Log(m.Height)
t.Fatal("incorrect width/height")
}
if m.TileWidth != 32 || m.TileHeight != 32 {
t.Log(m.TileWidth)
t.Log(m.TileHeight)
t.Fatal("incorrect tile width/height")
}
c := m.BackgroundColor
if c.R != 255 || c.G != 0 || c.B != 0 || c.A != 255 {
t.Log(m.BackgroundColor)
t.Fatal("incorrect background color")
}
v := m.Properties["mymap_prop"]
if v != "mymap_prop_value" {
t.Log(m.Properties)
t.Fatal("incorrect map property value")
}
for _, layer := range m.Layers {
for x := 0; x < m.Width; x++ {
for y := 0; y < m.Height; y++ {
gid, hasTile := layer.Tiles[Coord{x, y}]
if hasTile {
tileset := m.FindTileset(gid)
if tileset == nil {
t.Fatal("FindTileset failed to find correct tileset.")
}
_ = m.TilesetRect(tileset, tileset.Image.Width, tileset.Image.Height, true, gid)
}
}
}
}
}
func TestXMLMap(t *testing.T) {
verify(t, "test_xml.tmx")
}
func TestXMLDTDMap(t *testing.T) {
verify(t, "test_xml_dtd.tmx")
}
func TestCSVMap(t *testing.T) {
verify(t, "test_csv.tmx")
}
func TestCSVTSXMap(t *testing.T) {
verify(t, "test_csv_tsx.tmx")
}
func TestBase64Map(t *testing.T) {
verify(t, "test_base64.tmx")
}
func TestBase64GZipMap(t *testing.T) {
verify(t, "test_base64_gzip.tmx")
}
func TestBase64ZLibMap(t *testing.T) {
verify(t, "test_base64_zlib.tmx")
}
func TestObjects(t *testing.T) {
verify(t, "test_objects.tmx")
}