mirror of
https://github.com/OMGeeky/pytiled_parser.git
synced 2026-02-23 15:49:52 +01:00
Test case and fix for object template overrides
This commit is contained in:
223
.gitignore
vendored
223
.gitignore
vendored
@@ -1,111 +1,114 @@
|
|||||||
# Tiled Session file from using a project file
|
# Tiled Session file from using a project file
|
||||||
*.tiled-session
|
*.tiled-session
|
||||||
|
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
*$py.class
|
*$py.class
|
||||||
|
|
||||||
# C extensions
|
# C extensions
|
||||||
*.so
|
*.so
|
||||||
|
|
||||||
# Distribution / packaging
|
# Distribution / packaging
|
||||||
.Python
|
.Python
|
||||||
build/
|
build/
|
||||||
develop-eggs/
|
develop-eggs/
|
||||||
dist/
|
dist/
|
||||||
downloads/
|
downloads/
|
||||||
eggs/
|
eggs/
|
||||||
.eggs/
|
.eggs/
|
||||||
lib/
|
lib/
|
||||||
lib64/
|
lib64/
|
||||||
parts/
|
parts/
|
||||||
sdist/
|
sdist/
|
||||||
var/
|
var/
|
||||||
wheels/
|
wheels/
|
||||||
*.egg-info/
|
*.egg-info/
|
||||||
.installed.cfg
|
.installed.cfg
|
||||||
*.egg
|
*.egg
|
||||||
MANIFEST
|
MANIFEST
|
||||||
|
|
||||||
# PyInstaller
|
# PyInstaller
|
||||||
# Usually these files are written by a python script from a template
|
# Usually these files are written by a python script from a template
|
||||||
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
||||||
*.manifest
|
*.manifest
|
||||||
*.spec
|
*.spec
|
||||||
|
|
||||||
# Installer logs
|
# Installer logs
|
||||||
pip-log.txt
|
pip-log.txt
|
||||||
pip-delete-this-directory.txt
|
pip-delete-this-directory.txt
|
||||||
|
|
||||||
# Unit test / coverage reports
|
# Unit test / coverage reports
|
||||||
htmlcov/
|
htmlcov/
|
||||||
.tox/
|
.tox/
|
||||||
.coverage
|
.coverage
|
||||||
.coverage.*
|
.coverage.*
|
||||||
.cache
|
.cache
|
||||||
nosetests.xml
|
nosetests.xml
|
||||||
coverage.xml
|
coverage.xml
|
||||||
*.cover
|
*.cover
|
||||||
.hypothesis/
|
.hypothesis/
|
||||||
.pytest_cache/
|
.pytest_cache/
|
||||||
|
|
||||||
# Translations
|
# Translations
|
||||||
*.mo
|
*.mo
|
||||||
*.pot
|
*.pot
|
||||||
|
|
||||||
# Django stuff:
|
# Django stuff:
|
||||||
*.log
|
*.log
|
||||||
local_settings.py
|
local_settings.py
|
||||||
db.sqlite3
|
db.sqlite3
|
||||||
|
|
||||||
# Flask stuff:
|
# Flask stuff:
|
||||||
instance/
|
instance/
|
||||||
.webassets-cache
|
.webassets-cache
|
||||||
|
|
||||||
# Scrapy stuff:
|
# Scrapy stuff:
|
||||||
.scrapy
|
.scrapy
|
||||||
|
|
||||||
# Sphinx documentation
|
# Sphinx documentation
|
||||||
docs/_build/
|
docs/_build/
|
||||||
|
|
||||||
# PyBuilder
|
# PyBuilder
|
||||||
target/
|
target/
|
||||||
|
|
||||||
# Jupyter Notebook
|
# Jupyter Notebook
|
||||||
.ipynb_checkpoints
|
.ipynb_checkpoints
|
||||||
|
|
||||||
# pyenv
|
# pyenv
|
||||||
.python-version
|
.python-version
|
||||||
|
|
||||||
# celery beat schedule file
|
# celery beat schedule file
|
||||||
celerybeat-schedule
|
celerybeat-schedule
|
||||||
|
|
||||||
# SageMath parsed files
|
# SageMath parsed files
|
||||||
*.sage.py
|
*.sage.py
|
||||||
|
|
||||||
# Environments
|
# Environments
|
||||||
.env
|
.env
|
||||||
.venv
|
.venv
|
||||||
env/
|
env/
|
||||||
venv/
|
venv/
|
||||||
ENV/
|
ENV/
|
||||||
env.bak/
|
env.bak/
|
||||||
venv.bak/
|
venv.bak/
|
||||||
|
|
||||||
# Spyder project settings
|
# Spyder project settings
|
||||||
.spyderproject
|
.spyderproject
|
||||||
.spyproject
|
.spyproject
|
||||||
|
|
||||||
# Rope project settings
|
# Rope project settings
|
||||||
.ropeproject
|
.ropeproject
|
||||||
|
|
||||||
# mkdocs documentation
|
# mkdocs documentation
|
||||||
/site
|
/site
|
||||||
|
|
||||||
# mypy
|
# mypy
|
||||||
.mypy_cache/
|
.mypy_cache/
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
# VS Code Directory
|
# ruff
|
||||||
|
.ruff_cache
|
||||||
|
|
||||||
|
# VS Code Directory
|
||||||
.vscode
|
.vscode
|
||||||
@@ -272,14 +272,14 @@ def parse(raw_object: etree.Element, parent_dir: Optional[Path] = None) -> Tiled
|
|||||||
if isinstance(template, etree.Element):
|
if isinstance(template, etree.Element):
|
||||||
new_object = template.find("./object")
|
new_object = template.find("./object")
|
||||||
if new_object is not None:
|
if new_object is not None:
|
||||||
if raw_object.attrib.get("id") is not None:
|
for key, val in raw_object.attrib.items():
|
||||||
new_object.attrib["id"] = raw_object.attrib["id"]
|
if key == "template":
|
||||||
|
continue
|
||||||
|
new_object.attrib[key] = val
|
||||||
|
|
||||||
if raw_object.attrib.get("x") is not None:
|
properties_element = raw_object.find("./properties")
|
||||||
new_object.attrib["x"] = raw_object.attrib["x"]
|
if properties_element is not None:
|
||||||
|
new_object.append(properties_element)
|
||||||
if raw_object.attrib.get("y") is not None:
|
|
||||||
new_object.attrib["y"] = raw_object.attrib["y"]
|
|
||||||
|
|
||||||
raw_object = new_object
|
raw_object = new_object
|
||||||
elif isinstance(template, dict):
|
elif isinstance(template, dict):
|
||||||
|
|||||||
@@ -1,130 +1,131 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from pytiled_parser import common_types, layer, tiled_map, tiled_object, tileset
|
from pytiled_parser import common_types, layer, tiled_map, tiled_object, tileset
|
||||||
|
|
||||||
EXPECTED = tiled_map.TiledMap(
|
EXPECTED = tiled_map.TiledMap(
|
||||||
infinite=False,
|
infinite=False,
|
||||||
layers=[
|
layers=[
|
||||||
layer.ObjectLayer(
|
layer.ObjectLayer(
|
||||||
name="Object Layer 1",
|
name="Object Layer 1",
|
||||||
opacity=1,
|
opacity=1,
|
||||||
visible=True,
|
visible=True,
|
||||||
id=2,
|
id=2,
|
||||||
draw_order="topdown",
|
draw_order="topdown",
|
||||||
tiled_objects=[
|
tiled_objects=[
|
||||||
tiled_object.Rectangle(
|
tiled_object.Rectangle(
|
||||||
id=2,
|
id=2,
|
||||||
name="",
|
name="",
|
||||||
rotation=0,
|
rotation=0,
|
||||||
size=common_types.Size(63.6585878103079, 38.2811778048473),
|
size=common_types.Size(63.6585878103079, 38.2811778048473),
|
||||||
coordinates=common_types.OrderedPair(
|
coordinates=common_types.OrderedPair(
|
||||||
98.4987608686521, 46.2385012811358
|
98.4987608686521, 46.2385012811358
|
||||||
),
|
),
|
||||||
visible=True,
|
properties={"test": "hello"},
|
||||||
class_="",
|
visible=True,
|
||||||
),
|
class_="",
|
||||||
tiled_object.Tile(
|
),
|
||||||
id=6,
|
tiled_object.Tile(
|
||||||
coordinates=common_types.OrderedPair(46, 136.666666666667),
|
id=6,
|
||||||
name="",
|
coordinates=common_types.OrderedPair(46, 136.666666666667),
|
||||||
rotation=0,
|
name="",
|
||||||
class_="",
|
rotation=0,
|
||||||
visible=True,
|
class_="",
|
||||||
size=common_types.Size(32, 32),
|
visible=True,
|
||||||
gid=49,
|
size=common_types.Size(32, 32),
|
||||||
),
|
gid=49,
|
||||||
tiled_object.Tile(
|
),
|
||||||
id=7,
|
tiled_object.Tile(
|
||||||
coordinates=common_types.OrderedPair(141.333333333333, 148),
|
id=7,
|
||||||
name="",
|
coordinates=common_types.OrderedPair(141.333333333333, 148),
|
||||||
rotation=0,
|
name="",
|
||||||
class_="",
|
rotation=0,
|
||||||
visible=True,
|
class_="",
|
||||||
size=common_types.Size(32, 32),
|
visible=True,
|
||||||
gid=50,
|
size=common_types.Size(32, 32),
|
||||||
),
|
gid=50,
|
||||||
],
|
),
|
||||||
)
|
],
|
||||||
],
|
)
|
||||||
map_size=common_types.Size(8, 6),
|
],
|
||||||
next_layer_id=3,
|
map_size=common_types.Size(8, 6),
|
||||||
next_object_id=8,
|
next_layer_id=3,
|
||||||
orientation="orthogonal",
|
next_object_id=8,
|
||||||
render_order="right-down",
|
orientation="orthogonal",
|
||||||
tiled_version="1.7.1",
|
render_order="right-down",
|
||||||
tile_size=common_types.Size(32, 32),
|
tiled_version="1.9.2",
|
||||||
version="1.6",
|
tile_size=common_types.Size(32, 32),
|
||||||
background_color=common_types.Color(255, 0, 4, 255),
|
version="1.9",
|
||||||
tilesets={
|
background_color=common_types.Color(255, 0, 4, 255),
|
||||||
1: tileset.Tileset(
|
tilesets={
|
||||||
columns=8,
|
1: tileset.Tileset(
|
||||||
image=Path(Path(__file__).parent / "../../images/tmw_desert_spacing.png")
|
columns=8,
|
||||||
.absolute()
|
image=Path(Path(__file__).parent / "../../images/tmw_desert_spacing.png")
|
||||||
.resolve(),
|
.absolute()
|
||||||
image_width=265,
|
.resolve(),
|
||||||
image_height=199,
|
image_width=265,
|
||||||
firstgid=1,
|
image_height=199,
|
||||||
margin=1,
|
firstgid=1,
|
||||||
spacing=1,
|
margin=1,
|
||||||
name="tile_set_image",
|
spacing=1,
|
||||||
tile_count=48,
|
name="tile_set_image",
|
||||||
tiled_version="1.6.0",
|
tile_count=48,
|
||||||
tile_height=32,
|
tiled_version="1.6.0",
|
||||||
tile_width=32,
|
tile_height=32,
|
||||||
version="1.6",
|
tile_width=32,
|
||||||
type="tileset",
|
version="1.6",
|
||||||
),
|
type="tileset",
|
||||||
49: tileset.Tileset(
|
),
|
||||||
columns=1,
|
49: tileset.Tileset(
|
||||||
image=Path(Path(__file__).parent / "../../images/tile_04.png")
|
columns=1,
|
||||||
.absolute()
|
image=Path(Path(__file__).parent / "../../images/tile_04.png")
|
||||||
.resolve(),
|
.absolute()
|
||||||
image_width=32,
|
.resolve(),
|
||||||
image_height=32,
|
image_width=32,
|
||||||
firstgid=49,
|
image_height=32,
|
||||||
margin=0,
|
firstgid=49,
|
||||||
spacing=0,
|
margin=0,
|
||||||
name="tile_set_image_for_template",
|
spacing=0,
|
||||||
tile_count=1,
|
name="tile_set_image_for_template",
|
||||||
tiled_version="1.7.1",
|
tile_count=1,
|
||||||
tile_height=32,
|
tiled_version="1.7.1",
|
||||||
tile_width=32,
|
tile_height=32,
|
||||||
version="1.6",
|
tile_width=32,
|
||||||
type="tileset",
|
version="1.6",
|
||||||
),
|
type="tileset",
|
||||||
50: tileset.Tileset(
|
),
|
||||||
columns=0,
|
50: tileset.Tileset(
|
||||||
margin=0,
|
columns=0,
|
||||||
spacing=0,
|
margin=0,
|
||||||
name="tile_set_single_image",
|
spacing=0,
|
||||||
grid=tileset.Grid(orientation="orthogonal", width=1, height=1),
|
name="tile_set_single_image",
|
||||||
tiles={
|
grid=tileset.Grid(orientation="orthogonal", width=1, height=1),
|
||||||
0: tileset.Tile(
|
tiles={
|
||||||
id=0,
|
0: tileset.Tile(
|
||||||
image=Path(Path(__file__).parent / "../../images/tile_02.png")
|
id=0,
|
||||||
.absolute()
|
image=Path(Path(__file__).parent / "../../images/tile_02.png")
|
||||||
.resolve(),
|
.absolute()
|
||||||
image_height=32,
|
.resolve(),
|
||||||
image_width=32,
|
image_height=32,
|
||||||
width=32,
|
image_width=32,
|
||||||
height=32
|
width=32,
|
||||||
)
|
height=32,
|
||||||
},
|
)
|
||||||
tile_count=1,
|
},
|
||||||
tiled_version="1.7.1",
|
tile_count=1,
|
||||||
tile_height=32,
|
tiled_version="1.7.1",
|
||||||
tile_width=32,
|
tile_height=32,
|
||||||
firstgid=50,
|
tile_width=32,
|
||||||
type="tileset",
|
firstgid=50,
|
||||||
version="1.6",
|
type="tileset",
|
||||||
),
|
version="1.6",
|
||||||
},
|
),
|
||||||
properties={
|
},
|
||||||
"bool property - true": True,
|
properties={
|
||||||
"color property": common_types.Color(73, 252, 255, 255),
|
"bool property - true": True,
|
||||||
"file property": Path("../../../../../../var/log/syslog"),
|
"color property": common_types.Color(73, 252, 255, 255),
|
||||||
"float property": 1.23456789,
|
"file property": Path("../../../../../../var/log/syslog"),
|
||||||
"int property": 13,
|
"float property": 1.23456789,
|
||||||
"string property": "Hello, World!!",
|
"int property": 13,
|
||||||
},
|
"string property": "Hello, World!!",
|
||||||
)
|
},
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,85 +1,91 @@
|
|||||||
{ "backgroundcolor":"#ff0004",
|
{ "backgroundcolor":"#ff0004",
|
||||||
"compressionlevel":0,
|
"compressionlevel":0,
|
||||||
"height":6,
|
"height":6,
|
||||||
"infinite":false,
|
"infinite":false,
|
||||||
"layers":[
|
"layers":[
|
||||||
{
|
{
|
||||||
"draworder":"topdown",
|
"draworder":"topdown",
|
||||||
"id":2,
|
"id":2,
|
||||||
"name":"Object Layer 1",
|
"name":"Object Layer 1",
|
||||||
"objects":[
|
"objects":[
|
||||||
{
|
{
|
||||||
"id":2,
|
"id":2,
|
||||||
"template":"template-rectangle.json",
|
"properties":[
|
||||||
"x":98.4987608686521,
|
{
|
||||||
"y":46.2385012811358
|
"name":"test",
|
||||||
},
|
"type":"string",
|
||||||
{
|
"value":"hello"
|
||||||
"id":6,
|
}],
|
||||||
"template":"template-tile-spritesheet.json",
|
"template":"template-rectangle.json",
|
||||||
"x":46,
|
"x":98.4987608686521,
|
||||||
"y":136.666666666667
|
"y":46.2385012811358
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id":7,
|
"id":6,
|
||||||
"template":"template-tile-image.json",
|
"template":"template-tile-spritesheet.json",
|
||||||
"x":141.333333333333,
|
"x":46,
|
||||||
"y":148
|
"y":136.666666666667
|
||||||
}],
|
},
|
||||||
"opacity":1,
|
{
|
||||||
"type":"objectgroup",
|
"id":7,
|
||||||
"visible":true,
|
"template":"template-tile-image.json",
|
||||||
"x":0,
|
"x":141.333333333333,
|
||||||
"y":0
|
"y":148
|
||||||
}],
|
}],
|
||||||
"nextlayerid":3,
|
"opacity":1,
|
||||||
"nextobjectid":8,
|
"type":"objectgroup",
|
||||||
"orientation":"orthogonal",
|
"visible":true,
|
||||||
"properties":[
|
"x":0,
|
||||||
{
|
"y":0
|
||||||
"name":"bool property - true",
|
}],
|
||||||
"type":"bool",
|
"nextlayerid":3,
|
||||||
"value":true
|
"nextobjectid":8,
|
||||||
},
|
"orientation":"orthogonal",
|
||||||
{
|
"properties":[
|
||||||
"name":"color property",
|
{
|
||||||
"type":"color",
|
"name":"bool property - true",
|
||||||
"value":"#ff49fcff"
|
"type":"bool",
|
||||||
},
|
"value":true
|
||||||
{
|
},
|
||||||
"name":"file property",
|
{
|
||||||
"type":"file",
|
"name":"color property",
|
||||||
"value":"..\/..\/..\/..\/..\/..\/var\/log\/syslog"
|
"type":"color",
|
||||||
},
|
"value":"#ff49fcff"
|
||||||
{
|
},
|
||||||
"name":"float property",
|
{
|
||||||
"type":"float",
|
"name":"file property",
|
||||||
"value":1.23456789
|
"type":"file",
|
||||||
},
|
"value":"..\/..\/..\/..\/..\/..\/var\/log\/syslog"
|
||||||
{
|
},
|
||||||
"name":"int property",
|
{
|
||||||
"type":"int",
|
"name":"float property",
|
||||||
"value":13
|
"type":"float",
|
||||||
},
|
"value":1.23456789
|
||||||
{
|
},
|
||||||
"name":"string property",
|
{
|
||||||
"type":"string",
|
"name":"int property",
|
||||||
"value":"Hello, World!!"
|
"type":"int",
|
||||||
}],
|
"value":13
|
||||||
"renderorder":"right-down",
|
},
|
||||||
"tiledversion":"1.9.0",
|
{
|
||||||
"tileheight":32,
|
"name":"string property",
|
||||||
"tilesets":[
|
"type":"string",
|
||||||
{
|
"value":"Hello, World!!"
|
||||||
"firstgid":1,
|
}],
|
||||||
"source":"tileset.json"
|
"renderorder":"right-down",
|
||||||
},
|
"tiledversion":"1.9.2",
|
||||||
{
|
"tileheight":32,
|
||||||
"firstgid":49,
|
"tilesets":[
|
||||||
"source":"tile_set_image_for_template.json"
|
{
|
||||||
}],
|
"firstgid":1,
|
||||||
"tilewidth":32,
|
"source":"tileset.json"
|
||||||
"type":"map",
|
},
|
||||||
"version":"1.9",
|
{
|
||||||
"width":8
|
"firstgid":49,
|
||||||
|
"source":"tile_set_image_for_template.json"
|
||||||
|
}],
|
||||||
|
"tilewidth":32,
|
||||||
|
"type":"map",
|
||||||
|
"version":"1.9",
|
||||||
|
"width":8
|
||||||
}
|
}
|
||||||
@@ -1,18 +1,22 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?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>
|
<properties>
|
||||||
<property name="bool property - true" type="bool" value="true"/>
|
<property name="bool property - true" type="bool" value="true"/>
|
||||||
<property name="color property" type="color" value="#ff49fcff"/>
|
<property name="color property" type="color" value="#ff49fcff"/>
|
||||||
<property name="file property" type="file" value="../../../../../../var/log/syslog"/>
|
<property name="file property" type="file" value="../../../../../../var/log/syslog"/>
|
||||||
<property name="float property" type="float" value="1.23456789"/>
|
<property name="float property" type="float" value="1.23456789"/>
|
||||||
<property name="int property" type="int" value="13"/>
|
<property name="int property" type="int" value="13"/>
|
||||||
<property name="string property" value="Hello, World!!"/>
|
<property name="string property" value="Hello, World!!"/>
|
||||||
</properties>
|
</properties>
|
||||||
<tileset firstgid="1" source="tileset.tsx"/>
|
<tileset firstgid="1" source="tileset.tsx"/>
|
||||||
<tileset firstgid="49" source="tile_set_image_for_template.tsx"/>
|
<tileset firstgid="49" source="tile_set_image_for_template.tsx"/>
|
||||||
<objectgroup id="2" name="Object Layer 1">
|
<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">
|
||||||
<object id="6" template="template-tile-spritesheet.tx" x="46" y="136.667"/>
|
<properties>
|
||||||
<object id="7" template="template-tile-image.tx" x="141.333" y="148"/>
|
<property name="test" value="hello"/>
|
||||||
</objectgroup>
|
</properties>
|
||||||
</map>
|
</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>
|
||||||
|
</map>
|
||||||
|
|||||||
Reference in New Issue
Block a user