Skip to content

Commit 3c94bc7

Browse files
committed
Add support for repeatx and repeaty on layeres
1 parent 9a92a32 commit 3c94bc7

File tree

6 files changed

+31
-5
lines changed

6 files changed

+31
-5
lines changed

pytiled_parser/layer.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,20 @@ class Layer:
4444
properties: Properties for the layer.
4545
tint_color: Tint color that is multiplied with any graphics in this layer.
4646
class_: The Tiled class of this Layer.
47+
repeat_x: Repeat drawing on the X Axis(Currently only applies to image layers)
48+
repeat_y: Repeat drawing on the Y Axis(Currently only applies to image layers)
4749
"""
4850

4951
name: str
5052
opacity: float = 1
5153
visible: bool = True
5254

55+
# These technically only apply to image layers as of now, however Tiled has indicated
56+
# that is only at this time, and there's no reason they couldn't apply to other
57+
# types of layers in the future. For this reason they are stored in the common class.
58+
repeat_x: bool = False
59+
repeat_y: bool = False
60+
5361
coordinates: OrderedPair = OrderedPair(0, 0)
5462
parallax_factor: OrderedPair = OrderedPair(1, 1)
5563
offset: OrderedPair = OrderedPair(0, 0)

pytiled_parser/parsers/json/layer.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@
8181
"width": int,
8282
"x": int,
8383
"y": int,
84+
"repeatx": bool,
85+
"repeaty": bool,
8486
},
8587
)
8688
RawLayer.__doc__ = """
@@ -248,6 +250,12 @@ def _parse_common(raw_layer: RawLayer) -> Layer:
248250
if raw_layer.get("tintcolor") is not None:
249251
common.tint_color = parse_color(raw_layer["tintcolor"])
250252

253+
if raw_layer.get("repeatx") is not None:
254+
common.repeat_x = raw_layer["repeatx"]
255+
256+
if raw_layer.get("repeaty") is not None:
257+
common.repeat_y = raw_layer["repeaty"]
258+
251259
return common
252260

253261

pytiled_parser/parsers/tmx/layer.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ def _parse_common(raw_layer: etree.Element) -> Layer:
195195
if raw_layer.attrib.get("class") is not None:
196196
common.class_ = raw_layer.attrib["class"]
197197

198+
if raw_layer.attrib.get("repeatx") is not None:
199+
common.repeat_x = bool(int(raw_layer.attrib["repeatx"]))
200+
201+
if raw_layer.attrib.get("repeaty") is not None:
202+
common.repeat_y = bool(int(raw_layer.attrib["repeaty"]))
203+
198204
return common
199205

200206

@@ -302,7 +308,7 @@ def _parse_image_layer(raw_layer: etree.Element) -> ImageLayer:
302308
transparent_color=transparent_color,
303309
**_parse_common(raw_layer).__dict__,
304310
)
305-
print(image_layer.size)
311+
306312
return image_layer
307313

308314
raise RuntimeError("Tried to parse an image layer that doesn't have an image!")

tests/test_data/layer_tests/all_layer_types/expected.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
image=Path("../../images/tile_04.png"),
116116
transparent_color=common_types.Color(0, 0, 0, 255),
117117
tint_color=common_types.Color(255, 0, 0, 255),
118+
repeat_y=True,
118119
),
119120
layer.ImageLayer(
120121
name="Image Layer 2",
@@ -124,5 +125,6 @@
124125
id=5,
125126
parallax_factor=common_types.OrderedPair(1.0, 1.4),
126127
image=Path("../../images/tile_04.png"),
128+
repeat_x=True,
127129
),
128130
]

tests/test_data/layer_tests/all_layer_types/map.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"offsetx":1,
7272
"offsety":4,
7373
"opacity":1,
74+
"repeaty":true,
7475
"tintcolor":"#ff0000",
7576
"transparentcolor":"#000000",
7677
"type":"imagelayer",
@@ -84,6 +85,7 @@
8485
"name":"Image Layer 2",
8586
"opacity":1,
8687
"parallaxy":1.4,
88+
"repeatx":true,
8789
"type":"imagelayer",
8890
"visible":true,
8991
"x":0,
@@ -93,7 +95,7 @@
9395
"nextobjectid":3,
9496
"orientation":"orthogonal",
9597
"renderorder":"right-down",
96-
"tiledversion":"1.9.0",
98+
"tiledversion":"1.9.1",
9799
"tileheight":32,
98100
"tilesets":[
99101
{

tests/test_data/layer_tests/all_layer_types/map.tmx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<map version="1.9" tiledversion="1.9.0" orientation="orthogonal" renderorder="right-down" width="8" height="6" tilewidth="32" tileheight="32" infinite="0" nextlayerid="6" nextobjectid="3">
2+
<map version="1.9" tiledversion="1.9.1" orientation="orthogonal" renderorder="right-down" width="8" height="6" tilewidth="32" tileheight="32" infinite="0" nextlayerid="6" nextobjectid="3">
33
<tileset firstgid="1" source="tileset.tsx"/>
44
<layer id="1" name="Tile Layer 1" width="8" height="6" tintcolor="#aaffff" offsetx="1" offsety="3" parallaxx="1.4" parallaxy="1.3">
55
<properties>
@@ -19,10 +19,10 @@
1919
<object id="1" x="46.3333" y="39" width="69.3333" height="52.6667"/>
2020
</objectgroup>
2121
</group>
22-
<imagelayer id="3" name="Image Layer 1" tintcolor="#ff0000" offsetx="1" offsety="4">
22+
<imagelayer id="3" name="Image Layer 1" tintcolor="#ff0000" offsetx="1" offsety="4" repeaty="1">
2323
<image source="../../images/tile_04.png" trans="000000" width="32" height="32"/>
2424
</imagelayer>
25-
<imagelayer id="5" name="Image Layer 2" parallaxy="1.4">
25+
<imagelayer id="5" name="Image Layer 2" parallaxy="1.4" repeatx="1">
2626
<image source="../../images/tile_04.png" width="32" height="32"/>
2727
</imagelayer>
2828
</map>

0 commit comments

Comments
 (0)