bitcraft / pytmx

Python library to read Tiled Map Editor's TMX maps.
GNU Lesser General Public License v3.0
384 stars 81 forks source link

Template Support #171

Open JiffyRob opened 1 year ago

JiffyRob commented 1 year ago

It looks like pytmx can't load templates.

When an object with a template is loaded, I see a TiledObject.template attribute which corresponds to the path of the template's .tx file (relative to the path of the map), but there does not seem to be a way to get any meaningful data out of it without parsing the file separately, which (a) could generate a mess, and (b) really seems like it should be part of pytmx, since it takes care of everything else.

The desired behavior would either be replacing the TiledObject.template attribute with a TiledTemplate object or similar, or straight up overriding the object's attributes (most intuitive, in my opinion).

Theoretically, adding support would not be too difficult. I'd be willing to try an implement it myself if necessary, but this seems to be a pretty simple feature to not have around. Am I missing something?

Here's my current tiled project as a test case. The assets are from here (CC0).

JiffyRob commented 1 year ago

I found a (partial) workaround - after you create the object and set your attributes, right click it and hit 'detach'. This will decouple it from the template and load all the inherited attributes directly. In order to "re-couple" it to the template you have to select it in the project view, right click the object in question, and select "replace with