From e19e9e64dd6a9eb2292cb43a7f13761caa0fb0be Mon Sep 17 00:00:00 2001 From: Darren Eberly Date: Tue, 12 Oct 2021 19:57:30 -0400 Subject: [PATCH] Fix for only one parallax value being set. (#45) --- pytiled_parser/layer.py | 11 ++++++++--- .../test_data/layer_tests/all_layer_types/expected.py | 4 ++-- tests/test_data/layer_tests/all_layer_types/map.json | 6 ++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/pytiled_parser/layer.py b/pytiled_parser/layer.py index 6dd2fe7..a0237b2 100644 --- a/pytiled_parser/layer.py +++ b/pytiled_parser/layer.py @@ -356,10 +356,15 @@ def _get_common_attributes(raw_layer: RawLayer) -> Layer: if raw_layer.get("properties") is not None: common_attributes.properties = properties_.cast(raw_layer["properties"]) + parallax = [1.0, 1.0] + if raw_layer.get("parallaxx") is not None: - common_attributes.parallax_factor = OrderedPair( - raw_layer["parallaxx"], raw_layer["parallaxy"] - ) + parallax[0] = raw_layer["parallaxx"] + + if raw_layer.get("parallaxy") is not None: + parallax[1] = raw_layer["parallaxy"] + + common_attributes.parallax_factor = OrderedPair(parallax[0], parallax[1]) if raw_layer.get("tintcolor") is not None: common_attributes.tint_color = parse_color(raw_layer["tintcolor"]) diff --git a/tests/test_data/layer_tests/all_layer_types/expected.py b/tests/test_data/layer_tests/all_layer_types/expected.py index 6b24eb0..63dc6ab 100644 --- a/tests/test_data/layer_tests/all_layer_types/expected.py +++ b/tests/test_data/layer_tests/all_layer_types/expected.py @@ -83,7 +83,7 @@ EXPECTED = [ opacity=1, visible=True, id=4, - parallax_factor=common_types.OrderedPair(2.3, 1.2), + parallax_factor=common_types.OrderedPair(1.4, 1.0), tint_color=common_types.Color(0, 0, 255, 255), layers=[ layer.ObjectLayer( @@ -122,7 +122,7 @@ EXPECTED = [ opacity=1, visible=True, id=5, - parallax_factor=common_types.OrderedPair(1.5, 1.2), + parallax_factor=common_types.OrderedPair(1.0, 1.4), image=Path("../../images/tile_04.png"), ), ] diff --git a/tests/test_data/layer_tests/all_layer_types/map.json b/tests/test_data/layer_tests/all_layer_types/map.json index a04bdd6..e564a55 100644 --- a/tests/test_data/layer_tests/all_layer_types/map.json +++ b/tests/test_data/layer_tests/all_layer_types/map.json @@ -52,8 +52,7 @@ }], "name":"Group 1", "opacity":1, - "parallaxx":2.3, - "parallaxy":1.2, + "parallaxx":1.4, "tintcolor":"#0000ff", "type":"group", "visible":true, @@ -79,8 +78,7 @@ "image":"..\/..\/images\/tile_04.png", "name":"Image Layer 2", "opacity":1, - "parallaxx":1.5, - "parallaxy":1.2, + "parallaxy":1.4, "type":"imagelayer", "visible":true, "x":0,