Kiamo2/YATI

Option to import TSX files as an external TileSet resource

Closed this issue · 6 comments

It would be useful to be able to import a list or folder of TSX Tilesets into a single Godot file, and let TileMaps reference that, instead of embedding a unique TileSet into each TileMap. I have many small maps in my project (one per screen), and the thousands of duplicate embedded TileSets adds up to 50 MB. Using an external shared TileSet would cut that down to 20 KB.

Great plugin by the way, thanks!

This should be achievable by creating a (dummy) .tmx which refers/includes all your .tsx files and importing that.
By option 'Save Tileset To' the resulting big Godot tileset could be exported to a .res file and used otherwise.

There's two issues with this approach:

  • The external TileSet needs to be manually assigned to each imported layer. I can fix this with a _post_process script.
  • The TileSet source indexes won't match unless every map contains a tile from every set. Tiled seems to use the order the tiles were added to the map, so assuming that's consistent, I should be able to use a preset template file in Tiled to solve this.

I'd still suggest that it would be more convenient (and probably safer) if the plugin kept track of the source indexes, maybe by automatically logging them in a data file, or reading a custom property from Tiled that labels each TSX with a source index number.

The proposal with the custom property in Tiled appeares to me as a good idea.
I'll implement this in the next release which is planned for Godot 4.3 after it's stable release.

To be sure that I'm implementing this in a useful way...
The custom property on the TSX should be reflected in the Atlas ID (i.e. that's meant by you with 'source index number')?

Right, the id of the TileSetSource / TileSetAtlasSource within the TileSet. Currently this is determined by the order of TileSet.add_source() calls, but there's an optional second argument for specifying the index. There's also TileSet.set_source_id().

The TileSet editor claims there's a property called "ID" under the "Atlas" section, but that just seems to be a placeholder name in the UI, and the order is only exposed to scripting through methods on the TileSet.

I did a little more testing, and Tiled does currently still seem to support re-ordering the sources by editing the TSX externally. So the UI for changing the source order is gone, but the stable behavior is still there for now.

Should be now fixed with release 1.6.8 / 2.0.0.
The custom property (type int) is called 'godot_atlas_id' and if added to a tileset it gets the number.
But beware: If a source indexes is already assigned errors may pop up