mirror of
https://github.com/OMGeeky/pytiled_parser.git
synced 2026-01-22 10:25:32 +01:00
Initial object template tests
This commit is contained in:
77
tests/test_data/map_tests/template/expected.py
Normal file
77
tests/test_data/map_tests/template/expected.py
Normal 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!!",
|
||||||
|
},
|
||||||
|
)
|
||||||
75
tests/test_data/map_tests/template/map.json
Normal file
75
tests/test_data/map_tests/template/map.json
Normal 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
|
||||||
|
}
|
||||||
12
tests/test_data/map_tests/template/template.json
Normal file
12
tests/test_data/map_tests/template/template.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{ "object":
|
||||||
|
{
|
||||||
|
"height":38.2811778048473,
|
||||||
|
"id":1,
|
||||||
|
"name":"",
|
||||||
|
"rotation":0,
|
||||||
|
"type":"",
|
||||||
|
"visible":true,
|
||||||
|
"width":63.6585878103079
|
||||||
|
},
|
||||||
|
"type":"template"
|
||||||
|
}
|
||||||
18
tests/test_data/map_tests/template/template_tile.json
Normal file
18
tests/test_data/map_tests/template/template_tile.json
Normal 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"
|
||||||
|
}
|
||||||
14
tests/test_data/map_tests/template/tileset.json
Normal file
14
tests/test_data/map_tests/template/tileset.json
Normal 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"
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ ALL_MAP_TESTS = [
|
|||||||
MAP_TESTS / "no_background_color",
|
MAP_TESTS / "no_background_color",
|
||||||
MAP_TESTS / "hexagonal",
|
MAP_TESTS / "hexagonal",
|
||||||
MAP_TESTS / "embedded_tileset",
|
MAP_TESTS / "embedded_tileset",
|
||||||
|
MAP_TESTS / "template",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1103,3 +1103,19 @@ def test_parse_layer(raw_object_json, expected):
|
|||||||
result = tiled_object.cast(raw_object)
|
result = tiled_object.cast(raw_object)
|
||||||
|
|
||||||
assert result == expected
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user