Is it possible to force Tiled to output a Custom Property even when default value is selected?

I am using tiled 1.10 and have defined some custom classes with custom properties. I save my Tiled maps as JSON and parse them with a simple Python Script.

An issue I am having is that Tiled does not include custom properties in an object definition in the saved json file, if the default value for that property was selected.

Is it possible to force Tiled to always output custom property values, even when the default is chosen? I suspect the “right way” to solve this is to parse the default values from the project script, but that is going to overcomplicate things in this case.

Edit: I found this ( Is there a way to have all properties included in exported json - Tiled Forum (mapeditor.org) ) but the thread ends without finding a solution.

1 Like

This has been added to the list of fixes going into 1.11:

Tiled 1.11 Milestone · GitHub

2 Likes

Looking forward to this.

Note that there might be a subtle difference between what you want and what will be included in the next release.

Tiled makes a distinction between saving and exporting.

If I understand correctly, class member values will be added to files when selecting the export menu option, not the save menu option.

This is correct. Resolving property values is only available as an export option. Using it on Save would wreck one’s working files and remove the ability to “update” the default values when they change, since it’s through them being unset that Tiled knows you want the default value.

I want to have my own map format, so that I can be sure that my extensions where applied when saving the level. (if the extensions weren’t activated, the map format would not be registered).

This can be achieved easily by registering a custom map format, and using the tmj format as a writer:

    tiled.mapFormatForFile("test.tmj").write(map, fileName);

By not implementing the read function, the format doesn’t show up in the Open, Save and Save As, only in the Export and Export As dialogs. Great.

Ideally, I’d like to enforce resolved properties for my format. That way, don’t have to implement the defaults in my game.

I don’t think there is a way to check whether resolve option is enabled, right? (let alone set it).

If there was a way, I could trigger an error dialog saying “please enable this option”

One hacky way I could think of is to create a temp object which I know to contain default props, calling .resolvedProperties() on it, and check whether one of those properties is empty.

But if there were a better way, that would be nice

There is no way to access that setting via scripts, which is rather annoying for custom formats. You can, however, write your custom format such that it makes a copy of the map with all the properties resolved, and exports that.

I don’t understand why you’d have this at all though? Is it not enough to set the “resolve object types and properties” setting in Tiled? It only needs to be enabled once, and it’ll apply on all subsequent exports (it’s only in 1.11 that it’ll affect nested custom types though, in 1.10.x and earlier it only affects top-level properties). It’s not like you have to check that the setting is enabled every time you save.

Of course, script access to this setting would still be nice in general, and would also provide a way for you to force the setting on.

It only needs to be enabled once

… I’m planning to use Tiled as the public level editor for enthusiast players: Level Editor · ninovanhooff/wheelsprung Wiki · GitHub

People don’t read instructions, so I can’t count on people having that option enabled even if I put it in the manual.

You can, however, write your custom format such that it makes a copy of the map with all the properties resolved, and exports that.

This would involve crawling through the map and copying everything into a new object, right? : resolvedProperties, but also className, x, y, width, height etc, etc.
It would also involve digging through the map’s tilesets to get the default className for tiles etc.

Yeah, it would be a hefty script.

Which is why I think exposing the export settings to scripting (ideally allowing them to be set as well) would be a much better solution. And you wouldn’t need a custom format, you could just have a script that runs on launch (or even on tiled.assetAboutToBeSaved, if you’re worried your users might change the setting) and enables that export option.

I feel like expecting users to use a custom export or option-changing script is a bigger ask than changing a setting though xP

1 Like