Skip to content

Commit 81e3dcb

Browse files
committed
Ensure name field of objects is not overriden by templates (#79)
1 parent 73f9d9d commit 81e3dcb

File tree

5 files changed

+7
-3
lines changed

5 files changed

+7
-3
lines changed

pytiled_parser/parsers/json/tiled_object.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,9 @@ def parse(
337337

338338
if not found:
339339
raw_object["properties"].append(prop)
340+
elif key == "name":
341+
if "name" not in raw_object:
342+
raw_object["name"] = loaded_template[key]
340343
else:
341344
raw_object[key] = loaded_template[key] # type: ignore
342345
else:

tests/test_data/map_tests/template/expected.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
tiled_objects=[
1616
tiled_object.Rectangle(
1717
id=2,
18-
name="",
18+
name="hello",
1919
rotation=0,
2020
size=common_types.Size(63.6585878103079, 38.2811778048473),
2121
coordinates=common_types.OrderedPair(

tests/test_data/map_tests/template/map.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"value":"hello"
1818
}],
1919
"template":"template-rectangle.json",
20+
"name": "hello",
2021
"x":98.4987608686521,
2122
"y":46.2385012811358
2223
},

tests/test_data/map_tests/template/map.tmx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<tileset firstgid="1" source="tileset.tsx"/>
1212
<tileset firstgid="49" source="tile_set_image_for_template.tsx"/>
1313
<objectgroup id="2" name="Object Layer 1">
14-
<object id="2" template="template-rectangle.tx" x="98.4988" y="46.2385">
14+
<object id="2" template="template-rectangle.tx" name="hello" x="98.4988" y="46.2385">
1515
<properties>
1616
<property name="test" value="hello"/>
1717
</properties>

tests/test_data/map_tests/template/template-rectangle.tx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<template>
3-
<object width="63.6586" height="38.2812">
3+
<object name="test" width="63.6586" height="38.2812">
44
<properties>
55
<property name="test" value="world"/>
66
<property name="testtest" value="fromtemplate"/>

0 commit comments

Comments
 (0)