Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for nested class types #265

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

FrankieF
Copy link

What?

Adds supports for nested custom type importing.

Why?

Tiled supports nested custom objects, but when imported with SuperTiled2Unity the object is put in a property with type class and the values are lost. In place of nested custom types we could just define each field on each custom property, but it is easier to use nested custom properties.
For example

  • Character
    • CharacterDataId
    • FacingDirection
  • StrollingCharacter
    • Character (this includes the fields defined above)
      • CharacterDataId
      • FacingDirection
    • WalkDistanceX
    • WalkDistanceY

Now Character can be reused in many custom types in Tiled, but this data is not imported into Unity correctly.

How?

Adds a new CustomProperty type called ClassCustomProperty which contains a dictionary of values. When searching for a CustomProperty a new method GetCustomProperty is used which takes a key parameter. Regular CustomProperty ignore this parameter and return themselves, but the new ClassCustomProperty will search it's dictionary for the correct property.

Anything Else?

I'm aware this is not an ideal solution and the code is a little ugly. I saw on other PRs you are currently changing the code and converting this to use Unity's package manager system. I was unsure if this part of the code was affected. I'm more than happy to update the PR with any feedback or to change it to match your new code changes.

I think a better solution would have been to convert CustomProperty to some kind of holder class where the key is supplied and the holder finds the customer property. This would allow things like dictionary or list properties, but I do not think Tiled supports those things and it felt like overkill here.

I've also never used this XML library before so please let me know if there is a better way then calling Get Descendants.

@FrankieF
Copy link
Author

FrankieF commented Mar 2, 2024

Any updates or thoughts?

@Seanba
Copy link
Owner

Seanba commented Mar 11, 2024

Hi there, @FrankieF. I'm sorry I haven't looked at this yet.
One of the things I have planned to work on "soon" is a complete revamp of the custom properties in ST2U.
I'd like to go with something that (automatically) generates C# classes from the Tiled project properties.
That should make it a lot easier to work with custom properties in your Unity project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants