mirror of
https://github.com/OMGeeky/pytiled_parser.git
synced 2025-12-26 17:02:28 +01:00
tests: All map tests working
This commit is contained in:
73
tests/test_cross_template/map.json
Normal file
73
tests/test_cross_template/map.json
Normal file
@@ -0,0 +1,73 @@
|
||||
{ "backgroundcolor":"#ff0004",
|
||||
"compressionlevel":0,
|
||||
"height":6,
|
||||
"infinite":false,
|
||||
"layers":[
|
||||
{
|
||||
"draworder":"topdown",
|
||||
"id":2,
|
||||
"name":"Object Layer 1",
|
||||
"objects":[
|
||||
{
|
||||
"id":2,
|
||||
"template":"template-rectangle.tx",
|
||||
"x":98.4987608686521,
|
||||
"y":46.2385012811358
|
||||
}],
|
||||
"opacity":1,
|
||||
"type":"objectgroup",
|
||||
"visible":true,
|
||||
"x":0,
|
||||
"y":0
|
||||
}],
|
||||
"nextlayerid":3,
|
||||
"nextobjectid":8,
|
||||
"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.7.1",
|
||||
"tileheight":32,
|
||||
"tilesets":[
|
||||
{
|
||||
"firstgid":1,
|
||||
"source":"tileset.json"
|
||||
},
|
||||
{
|
||||
"firstgid":49,
|
||||
"source":"tile_set_image_for_template.json"
|
||||
}],
|
||||
"tilewidth":32,
|
||||
"type":"map",
|
||||
"version":"1.6",
|
||||
"width":8
|
||||
}
|
||||
16
tests/test_cross_template/map.tmx
Normal file
16
tests/test_cross_template/map.tmx
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.5" tiledversion="1.7.0" orientation="orthogonal" renderorder="right-down" compressionlevel="0" width="8" height="6" tilewidth="32" tileheight="32" infinite="0" backgroundcolor="#ff0004" nextlayerid="3" nextobjectid="8">
|
||||
<properties>
|
||||
<property name="bool property - true" type="bool" value="true"/>
|
||||
<property name="color property" type="color" value="#ff49fcff"/>
|
||||
<property name="file property" type="file" value="../../../../../../var/log/syslog"/>
|
||||
<property name="float property" type="float" value="1.23456789"/>
|
||||
<property name="int property" type="int" value="13"/>
|
||||
<property name="string property" value="Hello, World!!"/>
|
||||
</properties>
|
||||
<tileset firstgid="1" source="tileset.tsx"/>
|
||||
<tileset firstgid="49" source="tile_set_image_for_template.tsx"/>
|
||||
<objectgroup id="2" name="Object Layer 1">
|
||||
<object id="2" template="template-rectangle.json" x="98.4988" y="46.2385"/>
|
||||
</objectgroup>
|
||||
</map>
|
||||
12
tests/test_cross_template/template-rectangle.json
Normal file
12
tests/test_cross_template/template-rectangle.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{ "object":
|
||||
{
|
||||
"height":38.2811778048473,
|
||||
"id":1,
|
||||
"name":"",
|
||||
"rotation":0,
|
||||
"type":"",
|
||||
"visible":true,
|
||||
"width":63.6585878103079
|
||||
},
|
||||
"type":"template"
|
||||
}
|
||||
4
tests/test_cross_template/template-rectangle.tx
Normal file
4
tests/test_cross_template/template-rectangle.tx
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<template>
|
||||
<object width="63.6586" height="38.2812"/>
|
||||
</template>
|
||||
16
tests/test_cross_template/test_cross_template.py
Normal file
16
tests/test_cross_template/test_cross_template.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from pytiled_parser import parse_map
|
||||
|
||||
|
||||
def test_cross_template_tmx_json():
|
||||
with pytest.raises(NotImplementedError):
|
||||
parse_map(Path(os.path.dirname(os.path.abspath(__file__))) / "map.tmx")
|
||||
|
||||
|
||||
def test_cross_template_json_tmx():
|
||||
with pytest.raises(NotImplementedError):
|
||||
parse_map(Path(os.path.dirname(os.path.abspath(__file__))) / "map.json")
|
||||
14
tests/test_cross_template/tile_set_image_for_template.json
Normal file
14
tests/test_cross_template/tile_set_image_for_template.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{ "columns":1,
|
||||
"image":"..\/..\/images\/tile_04.png",
|
||||
"imageheight":32,
|
||||
"imagewidth":32,
|
||||
"margin":0,
|
||||
"name":"tile_set_image_for_template",
|
||||
"spacing":0,
|
||||
"tilecount":1,
|
||||
"tiledversion":"1.7.1",
|
||||
"tileheight":32,
|
||||
"tilewidth":32,
|
||||
"type":"tileset",
|
||||
"version":"1.6"
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tileset version="1.5" tiledversion="1.7.0" name="tile_set_image_for_template" tilewidth="32" tileheight="32" tilecount="1" columns="1">
|
||||
<image source="../../images/tile_04.png" width="32" height="32"/>
|
||||
</tileset>
|
||||
14
tests/test_cross_template/tileset.json
Normal file
14
tests/test_cross_template/tileset.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{ "columns":8,
|
||||
"image":"..\/test_data\/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"
|
||||
}
|
||||
4
tests/test_cross_template/tileset.tsx
Normal file
4
tests/test_cross_template/tileset.tsx
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tileset version="1.5" tiledversion="1.7.0" name="tile_set_image" tilewidth="32" tileheight="32" spacing="1" margin="1" tilecount="48" columns="8">
|
||||
<image source="../../images/tmw_desert_spacing.png" width="265" height="199"/>
|
||||
</tileset>
|
||||
6
tests/test_data/map_tests/embedded_tileset/map.tmx
Normal file
6
tests/test_data/map_tests/embedded_tileset/map.tmx
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.5" tiledversion="1.7.0" orientation="orthogonal" renderorder="right-down" compressionlevel="0" width="8" height="6" tilewidth="32" tileheight="32" infinite="0" nextlayerid="2" nextobjectid="1">
|
||||
<tileset firstgid="1" name="tileset" tilewidth="32" tileheight="32" spacing="1" margin="1" tilecount="48" columns="8">
|
||||
<image source="../../images/tmw_desert_spacing.png" width="265" height="199"/>
|
||||
</tileset>
|
||||
</map>
|
||||
17
tests/test_data/map_tests/external_tileset_dif_dir/map.tmx
Normal file
17
tests/test_data/map_tests/external_tileset_dif_dir/map.tmx
Normal file
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.5" tiledversion="1.7.0" orientation="orthogonal" renderorder="right-down" compressionlevel="0" width="8" height="6" tilewidth="32" tileheight="32" infinite="0" backgroundcolor="#ff0004" nextlayerid="3" nextobjectid="1">
|
||||
<properties>
|
||||
<property name="bool property - true" type="bool" value="true"/>
|
||||
<property name="color property" type="color" value="#ff49fcff"/>
|
||||
<property name="file property" type="file" value="../../../../../../var/log/syslog"/>
|
||||
<property name="float property" type="float" value="1.23456789"/>
|
||||
<property name="int property" type="int" value="13"/>
|
||||
<property name="string property" value="Hello, World!!"/>
|
||||
</properties>
|
||||
<tileset firstgid="1" source="tileset/tileset.tsx"/>
|
||||
<layer id="2" name="Layer 1" width="8" height="6">
|
||||
<data encoding="base64" compression="zlib">
|
||||
eAFjYWBgYAZiJiBmBOKhBgAIGAAL
|
||||
</data>
|
||||
</layer>
|
||||
</map>
|
||||
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tileset version="1.5" tiledversion="1.7.0" name="tileset" tilewidth="32" tileheight="32" tilecount="4" columns="0">
|
||||
<grid orientation="orthogonal" width="1" height="1"/>
|
||||
<tile id="0" type="tile">
|
||||
<properties>
|
||||
<property name="float property" type="float" value="2.2"/>
|
||||
</properties>
|
||||
<image width="32" height="32" source="../../../images/tile_01.png"/>
|
||||
<animation>
|
||||
<frame tileid="0" duration="100"/>
|
||||
<frame tileid="1" duration="100"/>
|
||||
<frame tileid="2" duration="100"/>
|
||||
<frame tileid="3" duration="100"/>
|
||||
</animation>
|
||||
</tile>
|
||||
<tile id="1" type="tile">
|
||||
<properties>
|
||||
<property name="string property" value="testing"/>
|
||||
</properties>
|
||||
<image width="32" height="32" source="../../../images/tile_02.png"/>
|
||||
<objectgroup draworder="index">
|
||||
<object id="2" x="13.4358" y="13.5305" width="14.4766" height="13.7197"/>
|
||||
<object id="3" x="13.8143" y="1.98699" width="14.2874" height="11.0704">
|
||||
<ellipse/>
|
||||
</object>
|
||||
</objectgroup>
|
||||
</tile>
|
||||
<tile id="2" type="tile">
|
||||
<properties>
|
||||
<property name="bool property" type="bool" value="true"/>
|
||||
</properties>
|
||||
<image width="32" height="32" source="../../../images/tile_03.png"/>
|
||||
</tile>
|
||||
<tile id="3" type="tile">
|
||||
<image width="32" height="32" source="../../../images/tile_04.png"/>
|
||||
</tile>
|
||||
</tileset>
|
||||
18
tests/test_data/map_tests/hexagonal/map.tmx
Normal file
18
tests/test_data/map_tests/hexagonal/map.tmx
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.5" tiledversion="1.7.0" orientation="hexagonal" renderorder="right-down" width="10" height="10" tilewidth="14" tileheight="12" infinite="0" hexsidelength="6" staggeraxis="y" staggerindex="odd" nextlayerid="2" nextobjectid="1">
|
||||
<tileset firstgid="1" source="tileset.tsx"/>
|
||||
<layer id="1" name="Tile Layer 1" width="10" height="10">
|
||||
<data encoding="csv">
|
||||
3,3,3,3,9,9,9,9,17,17,
|
||||
3,3,3,9,9,9,9,17,17,17,
|
||||
3,3,3,9,9,9,9,9,17,17,
|
||||
3,3,1,7,9,9,9,15,17,17,
|
||||
1,1,12,5,7,7,7,15,15,15,
|
||||
12,1,5,5,7,7,7,15,15,15,
|
||||
2,2,5,5,5,5,4,14,14,14,
|
||||
2,2,5,5,5,4,14,14,14,14,
|
||||
2,2,2,5,5,5,4,14,14,14,
|
||||
2,2,2,2,5,5,4,4,14,14
|
||||
</data>
|
||||
</layer>
|
||||
</map>
|
||||
5
tests/test_data/map_tests/hexagonal/tileset.tsx
Normal file
5
tests/test_data/map_tests/hexagonal/tileset.tsx
Normal file
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tileset version="1.5" tiledversion="1.7.0" name="tileset" tilewidth="18" tileheight="18" tilecount="20" columns="5">
|
||||
<tileoffset x="0" y="1"/>
|
||||
<image source="../../images/hexmini.png" width="106" height="72"/>
|
||||
</tileset>
|
||||
4
tests/test_data/map_tests/no_background_color/map.tmx
Normal file
4
tests/test_data/map_tests/no_background_color/map.tmx
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.6" tiledversion="1.6.0" orientation="orthogonal" renderorder="right-down" compressionlevel="0" width="8" height="6" tilewidth="32" tileheight="32" infinite="0" nextlayerid="2" nextobjectid="1">
|
||||
<tileset firstgid="1" source="tileset.tsx"/>
|
||||
</map>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tileset version="1.6" tiledversion="1.6.0" name="tile_set_image" tilewidth="32" tileheight="32" spacing="1" margin="1" tilecount="48" columns="8">
|
||||
<image source="../../images/tmw_desert_spacing.png" width="265" height="199"/>
|
||||
</tileset>
|
||||
12
tests/test_data/map_tests/no_layers/map.tmx
Normal file
12
tests/test_data/map_tests/no_layers/map.tmx
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.5" tiledversion="1.7.0" orientation="orthogonal" renderorder="right-down" compressionlevel="0" width="8" height="6" tilewidth="32" tileheight="32" infinite="0" backgroundcolor="#ff0004" nextlayerid="2" nextobjectid="1">
|
||||
<properties>
|
||||
<property name="bool property - true" type="bool" value="true"/>
|
||||
<property name="color property" type="color" value="#ff49fcff"/>
|
||||
<property name="file property" type="file" value="../../../../../../var/log/syslog"/>
|
||||
<property name="float property" type="float" value="1.23456789"/>
|
||||
<property name="int property" type="int" value="13"/>
|
||||
<property name="string property" value="Hello, World!!"/>
|
||||
</properties>
|
||||
<tileset firstgid="1" source="tileset.tsx"/>
|
||||
</map>
|
||||
4
tests/test_data/map_tests/no_layers/tileset.tsx
Normal file
4
tests/test_data/map_tests/no_layers/tileset.tsx
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tileset version="1.6" tiledversion="1.6.0" name="tile_set_image" tilewidth="32" tileheight="32" spacing="1" margin="1" tilecount="48" columns="8">
|
||||
<image source="../../images/tmw_desert_spacing.png" width="265" height="199"/>
|
||||
</tileset>
|
||||
18
tests/test_data/map_tests/template/map.tmx
Normal file
18
tests/test_data/map_tests/template/map.tmx
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.5" tiledversion="1.7.0" orientation="orthogonal" renderorder="right-down" compressionlevel="0" width="8" height="6" tilewidth="32" tileheight="32" infinite="0" backgroundcolor="#ff0004" nextlayerid="3" nextobjectid="8">
|
||||
<properties>
|
||||
<property name="bool property - true" type="bool" value="true"/>
|
||||
<property name="color property" type="color" value="#ff49fcff"/>
|
||||
<property name="file property" type="file" value="../../../../../../var/log/syslog"/>
|
||||
<property name="float property" type="float" value="1.23456789"/>
|
||||
<property name="int property" type="int" value="13"/>
|
||||
<property name="string property" value="Hello, World!!"/>
|
||||
</properties>
|
||||
<tileset firstgid="1" source="tileset.tsx"/>
|
||||
<tileset firstgid="49" source="tile_set_image_for_template.tsx"/>
|
||||
<objectgroup id="2" name="Object Layer 1">
|
||||
<object id="2" template="template-rectangle.tx" x="98.4988" y="46.2385"/>
|
||||
<object id="6" template="template-tile-spritesheet.tx" x="46" y="136.667"/>
|
||||
<object id="7" template="template-tile-image.tx" x="141.333" y="148"/>
|
||||
</objectgroup>
|
||||
</map>
|
||||
4
tests/test_data/map_tests/template/template-rectangle.tx
Normal file
4
tests/test_data/map_tests/template/template-rectangle.tx
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<template>
|
||||
<object width="63.6586" height="38.2812"/>
|
||||
</template>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<template>
|
||||
<tileset firstgid="1" source="tile_set_single_image.tsx"/>
|
||||
<object gid="1" width="32" height="32"/>
|
||||
</template>
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<template>
|
||||
<tileset firstgid="1" source="tile_set_image_for_template.tsx"/>
|
||||
<object gid="1" width="32" height="32"/>
|
||||
</template>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tileset version="1.5" tiledversion="1.7.0" name="tile_set_image_for_template" tilewidth="32" tileheight="32" tilecount="1" columns="1">
|
||||
<image source="../../images/tile_04.png" width="32" height="32"/>
|
||||
</tileset>
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tileset version="1.5" tiledversion="1.7.0" name="tile_set_single_image" tilewidth="32" tileheight="32" tilecount="1" columns="0">
|
||||
<grid orientation="orthogonal" width="1" height="1"/>
|
||||
<tile id="0">
|
||||
<image width="32" height="32" source="../../images/tile_02.png"/>
|
||||
</tile>
|
||||
</tileset>
|
||||
4
tests/test_data/map_tests/template/tileset.tsx
Normal file
4
tests/test_data/map_tests/template/tileset.tsx
Normal file
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tileset version="1.5" tiledversion="1.7.0" name="tile_set_image" tilewidth="32" tileheight="32" spacing="1" margin="1" tilecount="48" columns="8">
|
||||
<image source="../../images/tmw_desert_spacing.png" width="265" height="199"/>
|
||||
</tileset>
|
||||
@@ -6,6 +6,7 @@ from pathlib import Path
|
||||
import pytest
|
||||
|
||||
from pytiled_parser import parse_map
|
||||
from pytiled_parser.common_types import OrderedPair, Size
|
||||
|
||||
TESTS_DIR = Path(os.path.dirname(os.path.abspath(__file__)))
|
||||
TEST_DATA = TESTS_DIR / "test_data"
|
||||
@@ -21,17 +22,64 @@ ALL_MAP_TESTS = [
|
||||
]
|
||||
|
||||
|
||||
def fix_object(my_object):
|
||||
my_object.coordinates = OrderedPair(
|
||||
round(my_object.coordinates[0], 3), round(my_object.coordinates[1], 3)
|
||||
)
|
||||
my_object.size = Size(round(my_object.size[0], 4), round(my_object.size[1], 4))
|
||||
|
||||
|
||||
def fix_tileset(tileset):
|
||||
tileset.version = None
|
||||
tileset.tiled_version = None
|
||||
if tileset.tiles:
|
||||
for tile in tileset.tiles.values():
|
||||
if tile.objects:
|
||||
for my_object in tile.objects.tiled_objects:
|
||||
fix_object(my_object)
|
||||
|
||||
|
||||
def fix_layer(layer):
|
||||
for tiled_object in layer.tiled_objects:
|
||||
fix_object(tiled_object)
|
||||
|
||||
|
||||
def fix_map(map):
|
||||
map.version = None
|
||||
map.tiled_version = None
|
||||
for layer in [layer for layer in map.layers if hasattr(layer, "tiled_objects")]:
|
||||
fix_layer(layer)
|
||||
|
||||
for tileset in map.tilesets.values():
|
||||
fix_tileset(tileset)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("parser_type", ["json", "tmx"])
|
||||
@pytest.mark.parametrize("map_test", ALL_MAP_TESTS)
|
||||
def test_map_integration(map_test):
|
||||
def test_map_integration(parser_type, map_test):
|
||||
# it's a PITA to import like this, don't do it
|
||||
# https://stackoverflow.com/a/67692/1342874
|
||||
spec = importlib.util.spec_from_file_location("expected", map_test / "expected.py")
|
||||
expected = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(expected)
|
||||
|
||||
raw_maps_path = map_test / "map.json"
|
||||
if parser_type == "json":
|
||||
raw_maps_path = map_test / "map.json"
|
||||
elif parser_type == "tmx":
|
||||
raw_maps_path = map_test / "map.tmx"
|
||||
|
||||
casted_map = parse_map(raw_maps_path)
|
||||
|
||||
# file detection when running from unit tests is broken
|
||||
expected.EXPECTED.map_file = casted_map.map_file
|
||||
|
||||
# who even knows what/how/when the gods determine what the
|
||||
# version values in maps/tileset files are, so we're just not
|
||||
# gonna check them, because they don't make sense anyways.
|
||||
#
|
||||
# Yes the values could be set to None in the expected objects
|
||||
# directly, but alas, this is just test code that's already stupid fast
|
||||
# and I'm lazy because there's too many of them already existing.
|
||||
fix_map(expected.EXPECTED)
|
||||
fix_map(casted_map)
|
||||
assert casted_map == expected.EXPECTED
|
||||
|
||||
Reference in New Issue
Block a user