From 849f6e759aab1052e16c5e4e5a5ab6bbe8452229 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Vanicat?= Date: Mon, 10 Jul 2023 14:04:38 +0200 Subject: [PATCH 1/5] Test for rotatated and flipped object from tiled. For now, when the rotation is not 180, the position disagree between tiled and arcade. --- tests/fixtures/tilemaps/rotation.json | 223 ++++++++++++++++++++++- tests/unit/tilemap/test_rotation_flip.py | 70 +++++++ 2 files changed, 288 insertions(+), 5 deletions(-) diff --git a/tests/fixtures/tilemaps/rotation.json b/tests/fixtures/tilemaps/rotation.json index ba872d124..db4d79dd0 100644 --- a/tests/fixtures/tilemaps/rotation.json +++ b/tests/fixtures/tilemaps/rotation.json @@ -3,7 +3,16 @@ "infinite":false, "layers":[ { - "data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 2147483654, 0, 2684354566, 3758096390, 0, 3221225478, 1073741830, 0, 1610612742, 536870918], + "data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 6, 2147483654, 0, 2684354566, 3758096390, 0, 3221225478, 1073741830, 0, 1610612742, 536870918], "height":10, "id":1, "name":"Blocking Sprites", @@ -13,12 +22,216 @@ "width":11, "x":0, "y":0 + }, + { + "draworder":"topdown", + "id":2, + "name":"Objects Sprites", + "objects":[ + { + "gid":6, + "height":128, + "id":1, + "name":"not", + "rotation":0, + "type":"", + "visible":true, + "width":128, + "x":0, + "y":1024 + }, + { + "gid":2147483654, + "height":128, + "id":2, + "name":"h", + "rotation":0, + "type":"", + "visible":true, + "width":128, + "x":128, + "y":1024 + }, + { + "gid":6, + "height":128, + "id":3, + "name":"90", + "rotation":90, + "type":"", + "visible":true, + "width":128, + "x":384, + "y":896 + }, + { + "gid":2147483654, + "height":128, + "id":9, + "name":"h90", + "rotation":90, + "type":"", + "visible":true, + "width":128, + "x":512, + "y":896 + }, + { + "gid":6, + "height":128, + "id":5, + "name":"180", + "rotation":180, + "type":"", + "visible":true, + "width":128, + "x":896, + "y":896 + }, + { + "gid":2147483654, + "height":128, + "id":6, + "name":"h180", + "rotation":180, + "type":"", + "visible":true, + "width":128, + "x":1024, + "y":896 + }, + { + "gid":6, + "height":128, + "id":7, + "name":"-90", + "rotation":-90, + "type":"", + "visible":true, + "width":128, + "x":1280, + "y":1024 + }, + { + "gid":2147483654, + "height":128, + "id":8, + "name":"h-90", + "rotation":-90, + "type":"", + "visible":true, + "width":128, + "x":1408, + "y":1024 + }, + { + "gid":1073741830, + "height":128, + "id":10, + "name":"v", + "rotation":0, + "type":"", + "visible":true, + "width":128, + "x":0, + "y":768 + }, + { + "gid":3221225478, + "height":128, + "id":11, + "name":"hv", + "rotation":0, + "type":"", + "visible":true, + "width":128, + "x":128, + "y":768 + }, + { + "gid":1073741830, + "height":128, + "id":13, + "name":"v90", + "rotation":90, + "type":"", + "visible":true, + "width":128, + "x":384, + "y":640 + }, + + { + "gid":3221225478, + "height":128, + "id":14, + "name":"hv90", + "rotation":90, + "type":"", + "visible":true, + "width":128, + "x":512, + "y":640 + }, + { + "gid":1073741830, + "height":128, + "id":15, + "name":"v180", + "rotation":180, + "type":"", + "visible":true, + "width":128, + "x":896, + "y":640 + }, + { + "gid":3221225478, + "height":128, + "id":16, + "name":"hv180", + "rotation":180, + "type":"", + "visible":true, + "width":128, + "x":1024, + "y":640 + }, + { + "gid":1073741830, + "height":128, + "id":17, + "name":"v-90", + "rotation":-90, + "type":"", + "visible":true, + "width":128, + "x":1280, + "y":768 + }, + { + "gid":3221225478, + "height":128, + "id":18, + "name":"hv-90", + "rotation":-90, + "type":"", + "visible":true, + "width":128, + "x":1408, + "y":768 + }], + "opacity":1, + "type":"objectgroup", + "visible":true, + "x":0, + "y":0 }], - "nextlayerid":2, - "nextobjectid":1, + "nextlayerid":3, + "nextobjectid":19, "orientation":"orthogonal", "renderorder":"left-up", - "tiledversion":"1.4.3", + "tiledversion":"1.10.1", "tileheight":128, "tilesets":[ { @@ -27,6 +240,6 @@ }], "tilewidth":128, "type":"map", - "version":1.4, + "version":"1.10", "width":11 } \ No newline at end of file diff --git a/tests/unit/tilemap/test_rotation_flip.py b/tests/unit/tilemap/test_rotation_flip.py index 0e92098f2..e906c2b6d 100644 --- a/tests/unit/tilemap/test_rotation_flip.py +++ b/tests/unit/tilemap/test_rotation_flip.py @@ -65,3 +65,73 @@ def test_rotation_mirror(window): wall = wall_list[7] assert wall.position == (1344, 64) assert wall.texture._vertex_order == tt.TransposeTransform.order + + # --- Object --- + assert "Objects Sprites" in my_map.sprite_lists + wall_list = my_map.sprite_lists["Objects Sprites"] + + line = 64+128*2 + wall = wall_list[0] + assert wall.properties["name"] == "not" + assert wall.position == (64, line) + + wall = wall_list[1] + assert wall.properties["name"] == "h" + assert wall.position == (64+128*1, line) + + wall = wall_list[2] + assert wall.properties["name"] == "90" + assert wall.position == (64+128*3, line) # this do fail + + wall = wall_list[3] + assert wall.properties["name"] == "h90" + assert wall.position == (64+128*4, line) # this do fail + + wall = wall_list[4] + assert wall.properties["name"] == "180" + assert wall.position == (64+128*6, line) + + wall = wall_list[5] + assert wall.properties["name"] == "h180" + assert wall.position == (64+128*7, line) + + wall = wall_list[6] + assert wall.properties["name"] == "-90" + assert wall.position == (64+128*9, line) # this do fail + + wall = wall_list[7] + assert wall.properties["name"] == "h-90" + assert wall.position == (64+128*10, line) # this do fail + + line = 64+128*4 + wall = wall_list[8] + assert wall.properties["name"] == "v" + assert wall.position == (64, line) + + wall = wall_list[9] + assert wall.properties["name"] == "hv" + assert wall.position == (64+128*1, line) + + wall = wall_list[10] + assert wall.properties["name"] == "v90" + assert wall.position == (64+128*3, line) # this do fail + + wall = wall_list[11] + assert wall.properties["name"] == "hv90" + assert wall.position == (64+128*4, line) # this do fail + + wall = wall_list[12] + assert wall.properties["name"] == "v180" + assert wall.position == (64+128*6, line) + + wall = wall_list[13] + assert wall.properties["name"] == "hv180" + assert wall.position == (64+128*7, line) + + wall = wall_list[14] + assert wall.properties["name"] == "v-90" + assert wall.position == (64+128*9, line) # this do fail + + wall = wall_list[15] + assert wall.properties["name"] == "hv-90" + assert wall.position == (64+128*10, line) # this do fail \ No newline at end of file From 783ef534626553c6718f1032a15bd961112a1a7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Vanicat?= Date: Mon, 10 Jul 2023 16:20:39 +0200 Subject: [PATCH 2/5] Removing unneeded window for test rotation --- tests/unit/tilemap/test_rotation_flip.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/tilemap/test_rotation_flip.py b/tests/unit/tilemap/test_rotation_flip.py index e906c2b6d..80f4cd5b8 100644 --- a/tests/unit/tilemap/test_rotation_flip.py +++ b/tests/unit/tilemap/test_rotation_flip.py @@ -11,7 +11,7 @@ def _transform(*transforms): return order -def test_rotation_mirror(window): +def test_rotation_mirror(): # Read in the tiled map my_map = arcade.load_tilemap(":fixtures:tilemaps/rotation.json") From 479b2686e655371d7c1ea533278b5f9fad4e737a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Vanicat?= Date: Mon, 10 Jul 2023 16:21:18 +0200 Subject: [PATCH 3/5] Split test for tile and object on rotation --- tests/unit/tilemap/test_rotation_flip.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/unit/tilemap/test_rotation_flip.py b/tests/unit/tilemap/test_rotation_flip.py index 80f4cd5b8..fec0ea760 100644 --- a/tests/unit/tilemap/test_rotation_flip.py +++ b/tests/unit/tilemap/test_rotation_flip.py @@ -66,6 +66,11 @@ def test_rotation_mirror(): assert wall.position == (1344, 64) assert wall.texture._vertex_order == tt.TransposeTransform.order + +def test_object_rotation_placement(): + # Read in the tiled map + my_map = arcade.load_tilemap(":fixtures:tilemaps/rotation.json") + # --- Object --- assert "Objects Sprites" in my_map.sprite_lists wall_list = my_map.sprite_lists["Objects Sprites"] From d973155cda591f0fe4761bbdbcda9f2e92f02975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Vanicat?= Date: Mon, 10 Jul 2023 16:22:05 +0200 Subject: [PATCH 4/5] Add test for orientation of the rotation It failed for now: the rotation is done in the wrong direction. --- tests/fixtures/tilemaps/rotation.json | 50 +++++++++++++++++++++++- tests/unit/tilemap/test_rotation_flip.py | 46 ++++++++++++++++++++++ 2 files changed, 95 insertions(+), 1 deletion(-) diff --git a/tests/fixtures/tilemaps/rotation.json b/tests/fixtures/tilemaps/rotation.json index db4d79dd0..0974937eb 100644 --- a/tests/fixtures/tilemaps/rotation.json +++ b/tests/fixtures/tilemaps/rotation.json @@ -220,6 +220,54 @@ "width":128, "x":1408, "y":768 + }, + { + "gid":90, + "height":128, + "id":19, + "name":"r0", + "rotation":0, + "type":"", + "visible":true, + "width":128, + "x":0, + "y":512 + }, + { + "gid":90, + "height":128, + "id":20, + "name":"r1", + "rotation":-90, + "type":"", + "visible":true, + "width":128, + "x":384, + "y":512 + }, + { + "gid":90, + "height":128, + "id":21, + "name":"r2", + "rotation":-180, + "type":"", + "visible":true, + "width":128, + "x":640, + "y":384 + }, + { + "gid":90, + "height":128, + "id":22, + "name":"r3", + "rotation":90, + "type":"", + "visible":true, + "width":128, + "x":768, + "y":384 }], "opacity":1, "type":"objectgroup", @@ -228,7 +276,7 @@ "y":0 }], "nextlayerid":3, - "nextobjectid":19, + "nextobjectid":25, "orientation":"orthogonal", "renderorder":"left-up", "tiledversion":"1.10.1", diff --git a/tests/unit/tilemap/test_rotation_flip.py b/tests/unit/tilemap/test_rotation_flip.py index fec0ea760..ae5203b19 100644 --- a/tests/unit/tilemap/test_rotation_flip.py +++ b/tests/unit/tilemap/test_rotation_flip.py @@ -67,6 +67,52 @@ def test_rotation_mirror(): assert wall.texture._vertex_order == tt.TransposeTransform.order +def test_object_rotation_orientation(): + # Read in the tiled map + my_map = arcade.load_tilemap(":fixtures:tilemaps/rotation.json") + + assert my_map.tile_width == 128 + assert my_map.tile_height == 128 + assert my_map.width == 11 + assert my_map.height == 10 + # --- Object --- + assert "Objects Sprites" in my_map.sprite_lists + wall_list = my_map.sprite_lists["Objects Sprites"] + + # Check for the direction of rotation + # not rotated the top is aligned with the grid + wall = wall_list[16] + assert wall.properties["name"] == "r0" + assert (wall.top / 128).is_integer() + assert not (wall.bottom / 128).is_integer() + assert (wall.left / 128).is_integer() + assert (wall.right / 128).is_integer() + + # Turned 90 to the left + wall = wall_list[17] + assert wall.properties["name"] == "r1" + assert (wall.top / 128).is_integer() + assert (wall.bottom / 128).is_integer() + assert (wall.left / 128).is_integer() + assert not (wall.right / 128).is_integer() + + # Turned 180 + wall = wall_list[18] + assert wall.properties["name"] == "r2" + assert not (wall.top / 128).is_integer() + assert (wall.bottom / 128).is_integer() + assert (wall.left / 128).is_integer() + assert (wall.right / 128).is_integer() + + # Turned 270 to the left (90 to the right) + wall = wall_list[19] + assert wall.properties["name"] == "r3" + assert (wall.top / 128).is_integer() + assert (wall.bottom / 128).is_integer() + assert not (wall.left / 128).is_integer() + assert (wall.right / 128).is_integer() + + def test_object_rotation_placement(): # Read in the tiled map my_map = arcade.load_tilemap(":fixtures:tilemaps/rotation.json") From 1e77227a776df303f309535a109f4133758c02e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Vanicat?= Date: Mon, 10 Jul 2023 16:39:47 +0200 Subject: [PATCH 5/5] Change sign of the rotation for object from tiled. Changing some test to fix this. All test are now green. Probably fix #1805 --- arcade/tilemap/tilemap.py | 2 +- tests/unit/tilemap/test_rotation_flip.py | 16 ++++++++-------- tests/unit/tilemap/test_tilemap_objects.py | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/arcade/tilemap/tilemap.py b/arcade/tilemap/tilemap.py index d4762a243..83a23640a 100644 --- a/arcade/tilemap/tilemap.py +++ b/arcade/tilemap/tilemap.py @@ -858,7 +858,7 @@ def _process_object_layer( # center_x = width / 2 # center_y = height / 2 if cur_object.rotation: - rotation = -math.radians(cur_object.rotation) + rotation = math.radians(cur_object.rotation) else: rotation = 0 diff --git a/tests/unit/tilemap/test_rotation_flip.py b/tests/unit/tilemap/test_rotation_flip.py index ae5203b19..4ffe96859 100644 --- a/tests/unit/tilemap/test_rotation_flip.py +++ b/tests/unit/tilemap/test_rotation_flip.py @@ -132,11 +132,11 @@ def test_object_rotation_placement(): wall = wall_list[2] assert wall.properties["name"] == "90" - assert wall.position == (64+128*3, line) # this do fail + assert wall.position == (64+128*3, line) wall = wall_list[3] assert wall.properties["name"] == "h90" - assert wall.position == (64+128*4, line) # this do fail + assert wall.position == (64+128*4, line) wall = wall_list[4] assert wall.properties["name"] == "180" @@ -148,11 +148,11 @@ def test_object_rotation_placement(): wall = wall_list[6] assert wall.properties["name"] == "-90" - assert wall.position == (64+128*9, line) # this do fail + assert wall.position == (64+128*9, line) wall = wall_list[7] assert wall.properties["name"] == "h-90" - assert wall.position == (64+128*10, line) # this do fail + assert wall.position == (64+128*10, line) line = 64+128*4 wall = wall_list[8] @@ -165,11 +165,11 @@ def test_object_rotation_placement(): wall = wall_list[10] assert wall.properties["name"] == "v90" - assert wall.position == (64+128*3, line) # this do fail + assert wall.position == (64+128*3, line) wall = wall_list[11] assert wall.properties["name"] == "hv90" - assert wall.position == (64+128*4, line) # this do fail + assert wall.position == (64+128*4, line) wall = wall_list[12] assert wall.properties["name"] == "v180" @@ -181,8 +181,8 @@ def test_object_rotation_placement(): wall = wall_list[14] assert wall.properties["name"] == "v-90" - assert wall.position == (64+128*9, line) # this do fail + assert wall.position == (64+128*9, line) wall = wall_list[15] assert wall.properties["name"] == "hv-90" - assert wall.position == (64+128*10, line) # this do fail \ No newline at end of file + assert wall.position == (64+128*10, line) \ No newline at end of file diff --git a/tests/unit/tilemap/test_tilemap_objects.py b/tests/unit/tilemap/test_tilemap_objects.py index 413514f2e..1b93fb7ea 100644 --- a/tests/unit/tilemap/test_tilemap_objects.py +++ b/tests/unit/tilemap/test_tilemap_objects.py @@ -27,7 +27,7 @@ def test_one(): # assert sprite_1.width == 400 assert sprite_1.height == 1000 - assert sprite_1.angle == 45 + assert sprite_1.angle == -45 # # Test type and name properties