Test case and fix for object template overrides

This commit is contained in:
Darren Eberly
2023-03-10 18:04:53 -05:00
parent 481bf3e71c
commit ae2ab80d5d
5 changed files with 363 additions and 349 deletions

3
.gitignore vendored
View File

@@ -107,5 +107,8 @@ venv.bak/
.mypy_cache/
.idea/
# ruff
.ruff_cache
# VS Code Directory
.vscode

View File

@@ -272,14 +272,14 @@ def parse(raw_object: etree.Element, parent_dir: Optional[Path] = None) -> Tiled
if isinstance(template, etree.Element):
new_object = template.find("./object")
if new_object is not None:
if raw_object.attrib.get("id") is not None:
new_object.attrib["id"] = raw_object.attrib["id"]
for key, val in raw_object.attrib.items():
if key == "template":
continue
new_object.attrib[key] = val
if raw_object.attrib.get("x") is not None:
new_object.attrib["x"] = raw_object.attrib["x"]
if raw_object.attrib.get("y") is not None:
new_object.attrib["y"] = raw_object.attrib["y"]
properties_element = raw_object.find("./properties")
if properties_element is not None:
new_object.append(properties_element)
raw_object = new_object
elif isinstance(template, dict):

View File

@@ -20,6 +20,7 @@ EXPECTED = tiled_map.TiledMap(
coordinates=common_types.OrderedPair(
98.4987608686521, 46.2385012811358
),
properties={"test": "hello"},
visible=True,
class_="",
),
@@ -51,9 +52,9 @@ EXPECTED = tiled_map.TiledMap(
next_object_id=8,
orientation="orthogonal",
render_order="right-down",
tiled_version="1.7.1",
tiled_version="1.9.2",
tile_size=common_types.Size(32, 32),
version="1.6",
version="1.9",
background_color=common_types.Color(255, 0, 4, 255),
tilesets={
1: tileset.Tileset(
@@ -107,7 +108,7 @@ EXPECTED = tiled_map.TiledMap(
image_height=32,
image_width=32,
width=32,
height=32
height=32,
)
},
tile_count=1,

View File

@@ -10,6 +10,12 @@
"objects":[
{
"id":2,
"properties":[
{
"name":"test",
"type":"string",
"value":"hello"
}],
"template":"template-rectangle.json",
"x":98.4987608686521,
"y":46.2385012811358
@@ -67,7 +73,7 @@
"value":"Hello, World!!"
}],
"renderorder":"right-down",
"tiledversion":"1.9.0",
"tiledversion":"1.9.2",
"tileheight":32,
"tilesets":[
{

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.9" tiledversion="1.9.0" orientation="orthogonal" renderorder="right-down" compressionlevel="0" width="8" height="6" tilewidth="32" tileheight="32" infinite="0" backgroundcolor="#ff0004" nextlayerid="3" nextobjectid="8">
<map version="1.9" tiledversion="1.9.2" orientation="orthogonal" renderorder="right-down" compressionlevel="0" width="8" height="6" tilewidth="32" tileheight="32" infinite="0" backgroundcolor="#ff0004" nextlayerid="3" nextobjectid="8">
<properties>
<property name="bool property - true" type="bool" value="true"/>
<property name="color property" type="color" value="#ff49fcff"/>
@@ -11,7 +11,11 @@
<tileset firstgid="1" source="tileset.tsx"/>
<tileset firstgid="49" source="tile_set_image_for_template.tsx"/>
<objectgroup id="2" name="Object Layer 1">
<object id="2" template="template-rectangle.tx" x="98.4988" y="46.2385"/>
<object id="2" template="template-rectangle.tx" x="98.4988" y="46.2385">
<properties>
<property name="test" value="hello"/>
</properties>
</object>
<object id="6" template="template-tile-spritesheet.tx" x="46" y="136.667"/>
<object id="7" template="template-tile-image.tx" x="141.333" y="148"/>
</objectgroup>