mapeditor / mapeditor/tiled

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

Open
#3,517 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
12.9k
Forks
2k
Avg merge
4h 27m
Merged PRs (30d)
8

Description

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?).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Trace TilesetFormat.read() and MapFormat.read() to determine how loaded assets receive fileName, then inspect the proposed Tileset.clone() and TileMap.clone() API behavior. Confirm whether reads should preserve external links and clones should clear fileName; no file or test path is named in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, javascript
Domain
api, developer-experience, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.