Skip to content

Commit 3ad32b1

Browse files
committed
Add test for external tileset in different directory than the map
1 parent 4335cb4 commit 3ad32b1

File tree

7 files changed

+382
-3
lines changed

7 files changed

+382
-3
lines changed
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
from pathlib import Path
2+
3+
from pytiled_parser import common_types, layer, tiled_map, tiled_object, tileset
4+
5+
EXPECTED = tiled_map.TiledMap(
6+
infinite=False,
7+
map_size=common_types.Size(8, 6),
8+
next_layer_id=3,
9+
next_object_id=1,
10+
orientation="orthogonal",
11+
render_order="right-down",
12+
tiled_version="1.5.0",
13+
tile_size=common_types.Size(32, 32),
14+
version=1.5,
15+
background_color=common_types.Color(255, 0, 4, 255),
16+
layers=[
17+
layer.TileLayer(
18+
name="Layer 1",
19+
opacity=1,
20+
visible=True,
21+
id=2,
22+
size=common_types.Size(8, 6),
23+
data=[
24+
[4, 3, 2, 1, 0, 0, 0, 0],
25+
[
26+
0,
27+
0,
28+
0,
29+
0,
30+
0,
31+
0,
32+
0,
33+
0,
34+
],
35+
[
36+
0,
37+
0,
38+
0,
39+
0,
40+
0,
41+
0,
42+
0,
43+
0,
44+
],
45+
[
46+
0,
47+
0,
48+
0,
49+
0,
50+
0,
51+
0,
52+
0,
53+
0,
54+
],
55+
[
56+
0,
57+
0,
58+
0,
59+
0,
60+
0,
61+
0,
62+
0,
63+
0,
64+
],
65+
[
66+
0,
67+
0,
68+
0,
69+
0,
70+
0,
71+
0,
72+
0,
73+
0,
74+
],
75+
],
76+
),
77+
],
78+
tilesets={
79+
1: tileset.Tileset(
80+
columns=0,
81+
margin=0,
82+
spacing=0,
83+
name="tileset",
84+
tile_count=4,
85+
tiled_version="1.3.5",
86+
tile_height=32,
87+
tile_width=32,
88+
version=1.2,
89+
type="tileset",
90+
grid=tileset.Grid(orientation="orthogonal", width=1, height=1),
91+
tiles={
92+
0: tileset.Tile(
93+
animation=[
94+
tileset.Frame(duration=100, tile_id=0),
95+
tileset.Frame(duration=100, tile_id=1),
96+
tileset.Frame(duration=100, tile_id=2),
97+
tileset.Frame(duration=100, tile_id=3),
98+
],
99+
id=0,
100+
image=Path(Path(__file__).parent / "../../images/tile_01.png")
101+
.absolute()
102+
.resolve(),
103+
image_height=32,
104+
image_width=32,
105+
properties={"float property": 2.2},
106+
type="tile",
107+
),
108+
1: tileset.Tile(
109+
id=1,
110+
image=Path(Path(__file__).parent / "../../images/tile_02.png")
111+
.absolute()
112+
.resolve(),
113+
image_height=32,
114+
image_width=32,
115+
objects=layer.ObjectLayer(
116+
name="",
117+
opacity=1,
118+
visible=True,
119+
draw_order="index",
120+
tiled_objects=[
121+
tiled_object.Rectangle(
122+
id=2,
123+
name="",
124+
size=common_types.Size(
125+
14.4766410408043, 13.7196924896511
126+
),
127+
rotation=0,
128+
type="",
129+
visible=True,
130+
coordinates=common_types.OrderedPair(
131+
13.4358367829687, 13.5304553518628
132+
),
133+
),
134+
tiled_object.Ellipse(
135+
id=3,
136+
name="",
137+
size=common_types.Size(
138+
14.287403903016, 11.070372560615
139+
),
140+
rotation=0,
141+
type="",
142+
visible=True,
143+
coordinates=common_types.OrderedPair(
144+
13.8143110585452, 1.98698994677705
145+
),
146+
),
147+
],
148+
),
149+
properties={"string property": "testing"},
150+
type="tile",
151+
),
152+
2: tileset.Tile(
153+
id=2,
154+
image=Path(Path(__file__).parent / "../../images/tile_03.png")
155+
.absolute()
156+
.resolve(),
157+
image_height=32,
158+
image_width=32,
159+
properties={"bool property": True},
160+
type="tile",
161+
),
162+
3: tileset.Tile(
163+
id=3,
164+
image=Path(Path(__file__).parent / "../../images/tile_04.png")
165+
.absolute()
166+
.resolve(),
167+
image_height=32,
168+
image_width=32,
169+
type="tile",
170+
),
171+
},
172+
)
173+
},
174+
properties={
175+
"bool property - true": True,
176+
"color property": common_types.Color(255, 73, 252, 255),
177+
"file property": Path("../../../../../../var/log/syslog"),
178+
"float property": 1.23456789,
179+
"int property": 13,
180+
"string property": "Hello, World!!",
181+
},
182+
)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{ "backgroundcolor":"#ff0004",
2+
"compressionlevel":0,
3+
"height":6,
4+
"infinite":false,
5+
"layers":[
6+
{
7+
"compression":"zlib",
8+
"data":"eAFjYWBgYAZiJiBmBOKhBgAIGAAL",
9+
"encoding":"base64",
10+
"height":6,
11+
"id":2,
12+
"name":"Layer 1",
13+
"opacity":1,
14+
"type":"tilelayer",
15+
"visible":true,
16+
"width":8,
17+
"x":0,
18+
"y":0
19+
}],
20+
"nextlayerid":3,
21+
"nextobjectid":1,
22+
"orientation":"orthogonal",
23+
"properties":[
24+
{
25+
"name":"bool property - true",
26+
"type":"bool",
27+
"value":true
28+
},
29+
{
30+
"name":"color property",
31+
"type":"color",
32+
"value":"#ff49fcff"
33+
},
34+
{
35+
"name":"file property",
36+
"type":"file",
37+
"value":"..\/..\/..\/..\/..\/..\/var\/log\/syslog"
38+
},
39+
{
40+
"name":"float property",
41+
"type":"float",
42+
"value":1.23456789
43+
},
44+
{
45+
"name":"int property",
46+
"type":"int",
47+
"value":13
48+
},
49+
{
50+
"name":"string property",
51+
"type":"string",
52+
"value":"Hello, World!!"
53+
}],
54+
"renderorder":"right-down",
55+
"tiledversion":"1.5.0",
56+
"tileheight":32,
57+
"tilesets":[
58+
{
59+
"firstgid":1,
60+
"source":"tileset\/tileset.json"
61+
}],
62+
"tilewidth":32,
63+
"type":"map",
64+
"version":1.5,
65+
"width":8
66+
}
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
{ "columns":0,
2+
"editorsettings":
3+
{
4+
"export":
5+
{
6+
"format":"",
7+
"target":"."
8+
}
9+
},
10+
"grid":
11+
{
12+
"height":1,
13+
"orientation":"orthogonal",
14+
"width":1
15+
},
16+
"margin":0,
17+
"name":"tileset",
18+
"spacing":0,
19+
"tilecount":4,
20+
"tiledversion":"1.3.5",
21+
"tileheight":32,
22+
"tiles":[
23+
{
24+
"animation":[
25+
{
26+
"duration":100,
27+
"tileid":0
28+
},
29+
{
30+
"duration":100,
31+
"tileid":1
32+
},
33+
{
34+
"duration":100,
35+
"tileid":2
36+
},
37+
{
38+
"duration":100,
39+
"tileid":3
40+
}],
41+
"id":0,
42+
"image":"..\/..\/..\/images\/tile_01.png",
43+
"imageheight":32,
44+
"imagewidth":32,
45+
"properties":[
46+
{
47+
"name":"float property",
48+
"type":"float",
49+
"value":2.2
50+
}],
51+
"type":"tile"
52+
},
53+
{
54+
"id":1,
55+
"image":"..\/..\/..\/images\/tile_02.png",
56+
"imageheight":32,
57+
"imagewidth":32,
58+
"objectgroup":
59+
{
60+
"draworder":"index",
61+
"name":"",
62+
"objects":[
63+
{
64+
"height":13.7196924896511,
65+
"id":2,
66+
"name":"",
67+
"rotation":0,
68+
"type":"",
69+
"visible":true,
70+
"width":14.4766410408043,
71+
"x":13.4358367829687,
72+
"y":13.5304553518628
73+
},
74+
{
75+
"ellipse":true,
76+
"height":11.070372560615,
77+
"id":3,
78+
"name":"",
79+
"rotation":0,
80+
"type":"",
81+
"visible":true,
82+
"width":14.287403903016,
83+
"x":13.8143110585452,
84+
"y":1.98698994677705
85+
}],
86+
"opacity":1,
87+
"type":"objectgroup",
88+
"visible":true,
89+
"x":0,
90+
"y":0
91+
},
92+
"properties":[
93+
{
94+
"name":"string property",
95+
"type":"string",
96+
"value":"testing"
97+
}],
98+
"type":"tile"
99+
},
100+
{
101+
"id":2,
102+
"image":"..\/..\/..\/images\/tile_03.png",
103+
"imageheight":32,
104+
"imagewidth":32,
105+
"properties":[
106+
{
107+
"name":"bool property",
108+
"type":"bool",
109+
"value":true
110+
}],
111+
"type":"tile"
112+
},
113+
{
114+
"id":3,
115+
"image":"..\/..\/..\/images\/tile_04.png",
116+
"imageheight":32,
117+
"imagewidth":32,
118+
"type":"tile"
119+
}],
120+
"tilewidth":32,
121+
"type":"tileset",
122+
"version":1.2
123+
}
124+

tests/test_data/map_tests/hexagonal/expected.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@
138138
tilesets={
139139
1: tileset.Tileset(
140140
columns=5,
141-
image=Path("../../images/hexmini.png"),
141+
image=Path(Path(__file__).parent / "../../images/hexmini.png")
142+
.absolute()
143+
.resolve(),
142144
image_width=106,
143145
image_height=72,
144146
margin=0,

tests/test_data/map_tests/no_background_color/expected.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
tilesets={
1717
1: tileset.Tileset(
1818
columns=8,
19-
image=Path("../../images/tmw_desert_spacing.png"),
19+
image=Path(Path(__file__).parent / "../../images/tmw_desert_spacing.png")
20+
.absolute()
21+
.resolve(),
2022
image_width=265,
2123
image_height=199,
2224
margin=1,

0 commit comments

Comments
 (0)