mapeditor / mapeditor/tiled

Scripting: Make it easier to modify an Asset in scripted exporters

Open
#3,986 3 comments 0 reactions 1 assignee Claimed by @SIDDHAARTHAA View on GitHub
Dominant language
C++
Stars
12.9k
Forks
2k
Avg merge
4h 27m
Merged PRs (30d)
8

Description

The Asset you get as an argument to `MapFormat.write()` and `TilesetFormap.write()` is read-only, which makes it difficult to make temporary last-second changes to the map/tileset. Theoretically one could try to use the assetAboutToBeSaved signals to trigger such changes instead, and undo them after the asset is saved, but no such signals fire on export (see #3984), and a script may need to do substantial changes that might not be easily Undoable, all this makes for unwieldy, overcomplicated scripts.

There are two possible solutions I see:
1. Make the argument Asset editable. When any export options are applied, it's already a copy, so it could safely be made editable. However, this means a copy would need to be made even when otherwise the original would be passed in, even if the export format doesn't need to make changes to it. Most likely only a minority of custom formats need to make changes to their Asset, so this seems wasteful.
2. Add `Asset.clone()`, which creates a deep clone of the Asset. This isn't as intuitive, but it would have wider applications than just export formats, and avoids making unnecessary copies of the saved Asset. If this approach is taken, the `write()` methods' documentation should mention it as a way to get a modifiable copy of the Asset if one is needed.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.