Skip to content

Commit e2573ff

Browse files
committed
Initial object template tests
1 parent fec4064 commit e2573ff

File tree

7 files changed

+213
-0
lines changed

7 files changed

+213
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
layers=[
8+
layer.ObjectLayer(
9+
name="Object Layer 1",
10+
opacity=1,
11+
visible=True,
12+
id=2,
13+
draw_order="topdown",
14+
tiled_objects=[
15+
tiled_object.Rectangle(
16+
id=2,
17+
name="",
18+
rotation=0,
19+
size=common_types.Size(63.6585878103079, 38.2811778048473),
20+
coordinates=common_types.OrderedPair(
21+
98.4987608686521, 46.2385012811358
22+
),
23+
visible=True,
24+
type="",
25+
),
26+
tiled_object.Tile(
27+
id=3,
28+
coordinates=common_types.OrderedPair(
29+
46.3682110303692, 112.993321292057
30+
),
31+
name="",
32+
rotation=0,
33+
type="",
34+
visible=True,
35+
size=common_types.Size(32, 32),
36+
gid=30,
37+
),
38+
],
39+
)
40+
],
41+
map_size=common_types.Size(8, 6),
42+
next_layer_id=3,
43+
next_object_id=4,
44+
orientation="orthogonal",
45+
render_order="right-down",
46+
tiled_version="1.6.0",
47+
tile_size=common_types.Size(32, 32),
48+
version="1.6",
49+
background_color=common_types.Color(255, 0, 4, 255),
50+
tilesets={
51+
1: tileset.Tileset(
52+
columns=8,
53+
image=Path(Path(__file__).parent / "../../images/tmw_desert_spacing.png")
54+
.absolute()
55+
.resolve(),
56+
image_width=265,
57+
image_height=199,
58+
margin=1,
59+
spacing=1,
60+
name="tile_set_image",
61+
tile_count=48,
62+
tiled_version="1.6.0",
63+
tile_height=32,
64+
tile_width=32,
65+
version="1.6",
66+
type="tileset",
67+
)
68+
},
69+
properties={
70+
"bool property - true": True,
71+
"color property": common_types.Color(255, 73, 252, 255),
72+
"file property": Path("../../../../../../var/log/syslog"),
73+
"float property": 1.23456789,
74+
"int property": 13,
75+
"string property": "Hello, World!!",
76+
},
77+
)
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
{ "backgroundcolor":"#ff0004",
2+
"compressionlevel":0,
3+
"height":6,
4+
"infinite":false,
5+
"layers":[
6+
{
7+
"draworder":"topdown",
8+
"id":2,
9+
"name":"Object Layer 1",
10+
"objects":[
11+
{
12+
"id":2,
13+
"template":"template.json",
14+
"x":98.4987608686521,
15+
"y":46.2385012811358
16+
},
17+
{
18+
"id":3,
19+
"template":"template_tile.json",
20+
"x":46.3682110303692,
21+
"y":112.993321292057
22+
}],
23+
"opacity":1,
24+
"type":"objectgroup",
25+
"visible":true,
26+
"x":0,
27+
"y":0
28+
}],
29+
"nextlayerid":3,
30+
"nextobjectid":4,
31+
"orientation":"orthogonal",
32+
"properties":[
33+
{
34+
"name":"bool property - true",
35+
"type":"bool",
36+
"value":true
37+
},
38+
{
39+
"name":"color property",
40+
"type":"color",
41+
"value":"#ff49fcff"
42+
},
43+
{
44+
"name":"file property",
45+
"type":"file",
46+
"value":"..\/..\/..\/..\/..\/..\/var\/log\/syslog"
47+
},
48+
{
49+
"name":"float property",
50+
"type":"float",
51+
"value":1.23456789
52+
},
53+
{
54+
"name":"int property",
55+
"type":"int",
56+
"value":13
57+
},
58+
{
59+
"name":"string property",
60+
"type":"string",
61+
"value":"Hello, World!!"
62+
}],
63+
"renderorder":"right-down",
64+
"tiledversion":"1.6.0",
65+
"tileheight":32,
66+
"tilesets":[
67+
{
68+
"firstgid":1,
69+
"source":"tileset.json"
70+
}],
71+
"tilewidth":32,
72+
"type":"map",
73+
"version":"1.6",
74+
"width":8
75+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{ "object":
2+
{
3+
"height":38.2811778048473,
4+
"id":1,
5+
"name":"",
6+
"rotation":0,
7+
"type":"",
8+
"visible":true,
9+
"width":63.6585878103079
10+
},
11+
"type":"template"
12+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{ "object":
2+
{
3+
"gid":30,
4+
"height":32,
5+
"id":3,
6+
"name":"",
7+
"rotation":0,
8+
"type":"",
9+
"visible":true,
10+
"width":32
11+
},
12+
"tileset":
13+
{
14+
"firstgid":1,
15+
"source":"tileset.json"
16+
},
17+
"type":"template"
18+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{ "columns":8,
2+
"image":"..\/..\/images\/tmw_desert_spacing.png",
3+
"imageheight":199,
4+
"imagewidth":265,
5+
"margin":1,
6+
"name":"tile_set_image",
7+
"spacing":1,
8+
"tilecount":48,
9+
"tiledversion":"1.6.0",
10+
"tileheight":32,
11+
"tilewidth":32,
12+
"type":"tileset",
13+
"version":"1.6"
14+
}

tests/test_map.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
MAP_TESTS / "no_background_color",
1818
MAP_TESTS / "hexagonal",
1919
MAP_TESTS / "embedded_tileset",
20+
MAP_TESTS / "template",
2021
]
2122

2223

tests/test_tiled_object.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,3 +1103,19 @@ def test_parse_layer(raw_object_json, expected):
11031103
result = tiled_object.cast(raw_object)
11041104

11051105
assert result == expected
1106+
1107+
1108+
def test_parse_no_parent_dir():
1109+
1110+
raw_object = """
1111+
{
1112+
"id":1,
1113+
"template": "mytemplate.json",
1114+
"x":27.7185404115039,
1115+
"y":23.571672160964
1116+
}
1117+
"""
1118+
1119+
json_object = json.loads(raw_object)
1120+
with pytest.raises(RuntimeError):
1121+
tiled_object.cast(json_object)

0 commit comments

Comments
 (0)