Add Tiled custom types JSON support#314
Conversation
|
It would be much better to not even require exporting custom Tiled types as separate files at all, since this info is already embedded into a .tiled-project file. This is instantly auto-saved whenever you edit custom types, without requiring a separate export, and it's stored as a JSON (I think it's the same format as the exported JSON), so it would be a much better workflow. You just have to recognize a tiled-project file as a Unity asset, then read which folders it references so its settings are applied only to tmx/tsx files under those folders (normally it would be placed at the project's root, like directly under Assets/, to encompass the entire project). This is far better (more discoverable, auto-updated) than hiding config in project settings. You could later move all project config into that asset's importer. See more info in #311, item 4:
This PR could be a first step, but ideally, reading the tiled-project is the best workflow. |
Overview
This PR adds support for importing custom class and enum definitions exported from Tiled's Custom Types Editor.
SuperTiled2Unity already imports custom properties serialized directly in
.tmx,.tsx, and template files. With Tiled custom classes, default member properties can live in the custom type definition instead of being duplicated into every asset that uses the class. Unless a value is overridden, or the asset is exported with Tiled's "Resolve object types and properties" option, ST2U may not see those class defaults during import.This change lets users assign Tiled's exported
propertytypes.jsonfile in SuperTiled2Unity Project Settings. During import, ST2U can then load the same custom class defaults and enum metadata that Tiled uses in the editor.What Changed
Custom Types JSONfield to SuperTiled2Unity Project Settings.propertyTypeswrappers.storageType,values, andvaluesAsFlags.propertyTypeon imported custom properties.stringorint.Example
The screenshots below use a small sample custom type setup to demonstrate the import path.
In Tiled, the sample defines one class,
TestClass, with a red class color and three default members: one integer member, one flag enum member, and one regular enum member. The two enum definitions are string-backed, withTestEnum1using flags andTestEnum2using a single selected value.The exported
propertytypes.jsonfile is assigned in the newCustom Types JSONfield in SuperTiled2Unity Project Settings.After refreshing, the Custom Properties Viewer shows the loaded class defaults, the class color, the enum-backed member
propertyTypevalues, and the enum definitions loaded from the JSON file.Compatibility
.tmx,.tsx, and template files continue to work.Testing
Manually tested with a Tiled Custom Types JSON export containing:
Verified in Unity that:
propertytypes.jsoncan be assigned in the new settingObject Types XMLsetting remains availablepropertyTypeAlso checked:
git diff --check HEAD~1 HEAD