tiled icon indicating copy to clipboard operation
tiled copied to clipboard

Scripting: Set fileName when using TilesetFormat.read() or MapFormat.read()

Open eishiya opened this issue 1 year ago • 5 comments

A common task in scripted MapFormats is to read an external tileset from file and assign it to the newly created TileMap. There are two ways to open a Tileset from a file:

  • tiled.open(), which opens the Tileset as a document in Tiled. This is not usually desirable, and takes extra code to close the tab afterwards, and extra work to only close the document if the user didn't already have it open.
  • TilesetFormat.read(), which doesn't open a tab... but also doesn't set the Tileset's fileName, so when that Tileset is added to a map, it becomes embedded.

It's easy to miss the unintentional proliferation of tileset clones this causes. Here's an example from the forum of this unintentional embedding. Unless there's some specific reason not to, I think TilesetFormat.read() and TilemapFormat.read() should set the Asset's fileName, which should hopefully fix this embedding issue. Why is this not set in the first place?

Of course, sometimes it's desirable to create an embedded tileset on purpose. For this and other purposes, I think Tileset.clone() and TileMap.clone() would be good additions - the clones should have an empty fileName.

If there is a reason that TilesetFormat/TileMapFormat.read don't set the fileName, then the API should provide methods to open files, maintain their link to their file, but without opening a document tab for them, e.g. tiled.openSilently(), or tiled.open(path, silent?).

eishiya avatar Nov 05 '22 04:11 eishiya