diff --git a/tests/test_cross_template/map.json b/tests/test_cross_template/map.json new file mode 100644 index 0000000..451323f --- /dev/null +++ b/tests/test_cross_template/map.json @@ -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 +} \ No newline at end of file diff --git a/tests/test_cross_template/map.tmx b/tests/test_cross_template/map.tmx new file mode 100644 index 0000000..b77d63b --- /dev/null +++ b/tests/test_cross_template/map.tmx @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/tests/test_cross_template/template-rectangle.json b/tests/test_cross_template/template-rectangle.json new file mode 100644 index 0000000..fc39229 --- /dev/null +++ b/tests/test_cross_template/template-rectangle.json @@ -0,0 +1,12 @@ +{ "object": + { + "height":38.2811778048473, + "id":1, + "name":"", + "rotation":0, + "type":"", + "visible":true, + "width":63.6585878103079 + }, + "type":"template" +} \ No newline at end of file diff --git a/tests/test_cross_template/template-rectangle.tx b/tests/test_cross_template/template-rectangle.tx new file mode 100644 index 0000000..6daa364 --- /dev/null +++ b/tests/test_cross_template/template-rectangle.tx @@ -0,0 +1,4 @@ + + diff --git a/tests/test_cross_template/test_cross_template.py b/tests/test_cross_template/test_cross_template.py new file mode 100644 index 0000000..a1f8d86 --- /dev/null +++ b/tests/test_cross_template/test_cross_template.py @@ -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") diff --git a/tests/test_cross_template/tile_set_image_for_template.json b/tests/test_cross_template/tile_set_image_for_template.json new file mode 100644 index 0000000..c0cbf4e --- /dev/null +++ b/tests/test_cross_template/tile_set_image_for_template.json @@ -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" +} \ No newline at end of file diff --git a/tests/test_cross_template/tile_set_image_for_template.tsx b/tests/test_cross_template/tile_set_image_for_template.tsx new file mode 100644 index 0000000..9c59779 --- /dev/null +++ b/tests/test_cross_template/tile_set_image_for_template.tsx @@ -0,0 +1,4 @@ + + + + diff --git a/tests/test_cross_template/tileset.json b/tests/test_cross_template/tileset.json new file mode 100644 index 0000000..3302884 --- /dev/null +++ b/tests/test_cross_template/tileset.json @@ -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" +} \ No newline at end of file diff --git a/tests/test_cross_template/tileset.tsx b/tests/test_cross_template/tileset.tsx new file mode 100644 index 0000000..8aee17a --- /dev/null +++ b/tests/test_cross_template/tileset.tsx @@ -0,0 +1,4 @@ + + + + diff --git a/tests/test_data/map_tests/embedded_tileset/map.tmx b/tests/test_data/map_tests/embedded_tileset/map.tmx new file mode 100644 index 0000000..c39ca67 --- /dev/null +++ b/tests/test_data/map_tests/embedded_tileset/map.tmx @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/test_data/map_tests/external_tileset_dif_dir/map.tmx b/tests/test_data/map_tests/external_tileset_dif_dir/map.tmx new file mode 100644 index 0000000..9c19e15 --- /dev/null +++ b/tests/test_data/map_tests/external_tileset_dif_dir/map.tmx @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + eAFjYWBgYAZiJiBmBOKhBgAIGAAL + + + diff --git a/tests/test_data/map_tests/external_tileset_dif_dir/tileset/tileset.tsx b/tests/test_data/map_tests/external_tileset_dif_dir/tileset/tileset.tsx new file mode 100644 index 0000000..192b15e --- /dev/null +++ b/tests/test_data/map_tests/external_tileset_dif_dir/tileset/tileset.tsx @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/test_data/map_tests/hexagonal/map.tmx b/tests/test_data/map_tests/hexagonal/map.tmx new file mode 100644 index 0000000..482cf3c --- /dev/null +++ b/tests/test_data/map_tests/hexagonal/map.tmx @@ -0,0 +1,18 @@ + + + + + +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 + + + diff --git a/tests/test_data/map_tests/hexagonal/tileset.tsx b/tests/test_data/map_tests/hexagonal/tileset.tsx new file mode 100644 index 0000000..cba4d04 --- /dev/null +++ b/tests/test_data/map_tests/hexagonal/tileset.tsx @@ -0,0 +1,5 @@ + + + + + diff --git a/tests/test_data/map_tests/no_background_color/map.tmx b/tests/test_data/map_tests/no_background_color/map.tmx new file mode 100644 index 0000000..7e71558 --- /dev/null +++ b/tests/test_data/map_tests/no_background_color/map.tmx @@ -0,0 +1,4 @@ + + + + diff --git a/tests/test_data/map_tests/no_background_color/tileset.tsx b/tests/test_data/map_tests/no_background_color/tileset.tsx new file mode 100644 index 0000000..8b1cf24 --- /dev/null +++ b/tests/test_data/map_tests/no_background_color/tileset.tsx @@ -0,0 +1,4 @@ + + + + diff --git a/tests/test_data/map_tests/no_layers/map.tmx b/tests/test_data/map_tests/no_layers/map.tmx new file mode 100644 index 0000000..1ef8b7a --- /dev/null +++ b/tests/test_data/map_tests/no_layers/map.tmx @@ -0,0 +1,12 @@ + + + + + + + + + + + + diff --git a/tests/test_data/map_tests/no_layers/tileset.tsx b/tests/test_data/map_tests/no_layers/tileset.tsx new file mode 100644 index 0000000..8b1cf24 --- /dev/null +++ b/tests/test_data/map_tests/no_layers/tileset.tsx @@ -0,0 +1,4 @@ + + + + diff --git a/tests/test_data/map_tests/template/map.tmx b/tests/test_data/map_tests/template/map.tmx new file mode 100644 index 0000000..24cc2f0 --- /dev/null +++ b/tests/test_data/map_tests/template/map.tmx @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/tests/test_data/map_tests/template/template-rectangle.tx b/tests/test_data/map_tests/template/template-rectangle.tx new file mode 100644 index 0000000..6daa364 --- /dev/null +++ b/tests/test_data/map_tests/template/template-rectangle.tx @@ -0,0 +1,4 @@ + + diff --git a/tests/test_data/map_tests/template/template-tile-image.tx b/tests/test_data/map_tests/template/template-tile-image.tx new file mode 100644 index 0000000..989b725 --- /dev/null +++ b/tests/test_data/map_tests/template/template-tile-image.tx @@ -0,0 +1,5 @@ + + diff --git a/tests/test_data/map_tests/template/template-tile-spritesheet.tx b/tests/test_data/map_tests/template/template-tile-spritesheet.tx new file mode 100644 index 0000000..d958c77 --- /dev/null +++ b/tests/test_data/map_tests/template/template-tile-spritesheet.tx @@ -0,0 +1,5 @@ + + diff --git a/tests/test_data/map_tests/template/tile_set_image_for_template.tsx b/tests/test_data/map_tests/template/tile_set_image_for_template.tsx new file mode 100644 index 0000000..9c59779 --- /dev/null +++ b/tests/test_data/map_tests/template/tile_set_image_for_template.tsx @@ -0,0 +1,4 @@ + + + + diff --git a/tests/test_data/map_tests/template/tile_set_single_image.tsx b/tests/test_data/map_tests/template/tile_set_single_image.tsx new file mode 100644 index 0000000..c881c11 --- /dev/null +++ b/tests/test_data/map_tests/template/tile_set_single_image.tsx @@ -0,0 +1,7 @@ + + + + + + + diff --git a/tests/test_data/map_tests/template/tileset.tsx b/tests/test_data/map_tests/template/tileset.tsx new file mode 100644 index 0000000..8aee17a --- /dev/null +++ b/tests/test_data/map_tests/template/tileset.tsx @@ -0,0 +1,4 @@ + + + + diff --git a/tests/test_map.py b/tests/test_map.py index 68ad996..424e802 100644 --- a/tests/test_map.py +++ b/tests/test_map.py @@ -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