Initial object template tests

This commit is contained in:
Darren Eberly
2021-05-16 00:40:48 -04:00
parent fec406420f
commit e2573ff655
7 changed files with 213 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
from pathlib import Path
from pytiled_parser import common_types, layer, tiled_map, tiled_object, tileset
EXPECTED = tiled_map.TiledMap(
infinite=False,
layers=[
layer.ObjectLayer(
name="Object Layer 1",
opacity=1,
visible=True,
id=2,
draw_order="topdown",
tiled_objects=[
tiled_object.Rectangle(
id=2,
name="",
rotation=0,
size=common_types.Size(63.6585878103079, 38.2811778048473),
coordinates=common_types.OrderedPair(
98.4987608686521, 46.2385012811358
),
visible=True,
type="",
),
tiled_object.Tile(
id=3,
coordinates=common_types.OrderedPair(
46.3682110303692, 112.993321292057
),
name="",
rotation=0,
type="",
visible=True,
size=common_types.Size(32, 32),
gid=30,
),
],
)
],
map_size=common_types.Size(8, 6),
next_layer_id=3,
next_object_id=4,
orientation="orthogonal",
render_order="right-down",
tiled_version="1.6.0",
tile_size=common_types.Size(32, 32),
version="1.6",
background_color=common_types.Color(255, 0, 4, 255),
tilesets={
1: tileset.Tileset(
columns=8,
image=Path(Path(__file__).parent / "../../images/tmw_desert_spacing.png")
.absolute()
.resolve(),
image_width=265,
image_height=199,
margin=1,
spacing=1,
name="tile_set_image",
tile_count=48,
tiled_version="1.6.0",
tile_height=32,
tile_width=32,
version="1.6",
type="tileset",
)
},
properties={
"bool property - true": True,
"color property": common_types.Color(255, 73, 252, 255),
"file property": Path("../../../../../../var/log/syslog"),
"float property": 1.23456789,
"int property": 13,
"string property": "Hello, World!!",
},
)

View File

@@ -0,0 +1,75 @@
{ "backgroundcolor":"#ff0004",
"compressionlevel":0,
"height":6,
"infinite":false,
"layers":[
{
"draworder":"topdown",
"id":2,
"name":"Object Layer 1",
"objects":[
{
"id":2,
"template":"template.json",
"x":98.4987608686521,
"y":46.2385012811358
},
{
"id":3,
"template":"template_tile.json",
"x":46.3682110303692,
"y":112.993321292057
}],
"opacity":1,
"type":"objectgroup",
"visible":true,
"x":0,
"y":0
}],
"nextlayerid":3,
"nextobjectid":4,
"orientation":"orthogonal",
"properties":[
{
"name":"bool property - true",
"type":"bool",
"value":true
},
{
"name":"color property",
"type":"color",
"value":"#ff49fcff"
},
{
"name":"file property",
"type":"file",
"value":"..\/..\/..\/..\/..\/..\/var\/log\/syslog"
},
{
"name":"float property",
"type":"float",
"value":1.23456789
},
{
"name":"int property",
"type":"int",
"value":13
},
{
"name":"string property",
"type":"string",
"value":"Hello, World!!"
}],
"renderorder":"right-down",
"tiledversion":"1.6.0",
"tileheight":32,
"tilesets":[
{
"firstgid":1,
"source":"tileset.json"
}],
"tilewidth":32,
"type":"map",
"version":"1.6",
"width":8
}

View File

@@ -0,0 +1,12 @@
{ "object":
{
"height":38.2811778048473,
"id":1,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":63.6585878103079
},
"type":"template"
}

View File

@@ -0,0 +1,18 @@
{ "object":
{
"gid":30,
"height":32,
"id":3,
"name":"",
"rotation":0,
"type":"",
"visible":true,
"width":32
},
"tileset":
{
"firstgid":1,
"source":"tileset.json"
},
"type":"template"
}

View File

@@ -0,0 +1,14 @@
{ "columns":8,
"image":"..\/..\/images\/tmw_desert_spacing.png",
"imageheight":199,
"imagewidth":265,
"margin":1,
"name":"tile_set_image",
"spacing":1,
"tilecount":48,
"tiledversion":"1.6.0",
"tileheight":32,
"tilewidth":32,
"type":"tileset",
"version":"1.6"
}

View File

@@ -17,6 +17,7 @@ ALL_MAP_TESTS = [
MAP_TESTS / "no_background_color",
MAP_TESTS / "hexagonal",
MAP_TESTS / "embedded_tileset",
MAP_TESTS / "template",
]

View File

@@ -1103,3 +1103,19 @@ def test_parse_layer(raw_object_json, expected):
result = tiled_object.cast(raw_object)
assert result == expected
def test_parse_no_parent_dir():
raw_object = """
{
"id":1,
"template": "mytemplate.json",
"x":27.7185404115039,
"y":23.571672160964
}
"""
json_object = json.loads(raw_object)
with pytest.raises(RuntimeError):
tiled_object.cast(json_object)