Custom types from JavaScript

I have a custom map format exported via a JS plugin, and I’m trying to take advantage of custom types so I can do more editing directly in Tiled.

Currently when I access a property that holds an enum value, I get an object with typeId, typeName, and value. I want to get the string value of the enum, but I can’t find a way to do that yet. “value” is numeric, while I would’ve expected it to be the string value of the enum because I chose “Save as String” under the enum definition.

What does “typeId” map to? Is there somewhere that I can access the enum members or info about the type?

It is not currently possible* to get information about custom types via scripts, as there’s no API for custom types. This is a planned feature.

* it’s technically possible if you parse the user’s .tiled-project file yourself, but then you’ll have to be very careful to watch for changes to this file.

It’ll be nice to have an API for this but in the meantime I just realized I can export a JSON file describing the types, and typeId corresponds to those. That’s good enough for me.

1 Like