Problem with editing exported tilesets

Hello!

In my project, I use exported tilesets in JSON format. But I’ve found two problems/bugs here. I’m using the latest snapshot version of Tiled.

The first one is with an exported tileset with terrain information.Once I click the ‘Edit Tileset’ button, the new tab opens with the tileset, and I can edit the terrain as I want. But the problem is when I save the tileset, both by ctrl+S and ‘Save as’, selecting .JSON extension: the file is saved as a .tsx file. Even when using ‘save as’, and selecting JSON as extension, the process will warn me that the file has a different file-format.

The second one is regarding custom tile properties. Adding custom properties in an exported tileset, by first clicking ‘Edit Tileset’, and then saving the file, overwrites to a tsx file, but keeping the json extension. In this process, the tileset is automatically embedded. Once I export the tileset again (as a JSON), the custom property is nowhere to be found in the file. And checking in the tileset editor, indeed the custom property is gone.

The first problem, seems not to happen when first embedding the tileset, but as explained, this can’t be done with the second problem, since the custom tile property will disappear on exporting.

I hope this is clear, and could be fixed :slight_smile:

The second problem is now fixed (the part where the tileset gets automatically embedded):

It will be included in the next snapshot build (just triggered).

I’ll have to check your other issues later.

This bugfix covers the part where custom tile properties are lost:

Now I think we have only one remaining issue, which is that you’re getting a tsx file even when saving as JSON. Could it be that you’re only changing the file extension, but leaving the file type on “Tiled tileset files” rather than choosing “Json tileset files”? Since it’s that file type selector that determines the format it will try to save in.

I don’t think that’s the case here. When I edit an external tileset (which already is saved as a JSON) and for example add new terrain information, I can use File->Save As, and from the save window choose ‘save as JSON’. In this case, the file indeed saves as a JSON file. However should I use File->Save (or ctrl+S as shortcut), the existing JSON content is overwritten with tsx content, while keeping the json extension.

Here a small video-example of my steps: https://www.dropbox.com/s/rjx9u5f8whbbd80/example.webm?dl=0
Here I open the ground.json exported tileset. Edit the terrain info by deleting a terrain, and then save the tileset. At returning to the text editor, it shows the file contents has been changed to tsx format.

Been debugging this for a while now, and I finally found the reason, though unfortunately a solution is not immediately clear to me…

The reason is that when you open a map that uses a tileset, that tileset is loaded alongside (in libtiled), through a different process than when the tileset would be opened directly. This process does not remember what the file format of the tileset was. Then, when you press the Edit button for the tileset (or open the file manually, it doesn’t matter), Tiled realizes that it already loaded this particular file, and just opens the editor view for it. However, it still does not know what the original file format was, causing it to default to TSX when you save the file.

Maybe I should remove the defaulting to TSX format, but that doesn’t really help. I’ll need to modify the thing in such a way that the original file format is remembered. Maybe moving the relevant members from the TilesetDocument class to the Tileset class.

Fixed pushed and new snapshot build triggered:

It was rather involved, so please let me know about any new or remaining strange behavior.

Thanks for trying out the development snapshots and reporting these issues!

I’ll keep an eye on it! And thanks to you for your work :slight_smile:

1 Like