Do you want to work on this issue?
You can request for a bounty in order to promote it!
User-editable Tile Stamp storage #3273
eishiya posted onGitHub
Currently, Tile Stamps are stored in a custom JSON format that cannot be opened for editing in Tiled. To modify a stamp even slightly, you have to stamp it on a map, make your changes, create a new stamp from this, and then delete the old stamp. This can get quite annoying. If you want to make versions of stamps using a different tileset, you have to stamp all of them on my map one by one, replace the tileset, and then make new stamps one by one.
I propose using Tiled maps (JSON/TMJ or TMX) to store stamps instead. Each map would contain a stamp, including all of its variants. To distinguish between different variants, each should be stored in a top-level group. Any groups within these groups would just be ignored, the inner structure of the stamp can be treated as just a flat arrangement of layers, as is currently done for Automapping layers. The probability of each variant would be stored in a custom float probability
property on the group. The base stamp's name can be stored as a name
custom property on the map (filenames can't store every possible name, which is presumably why the current format has a name
property). If no name
is set, perhaps the first variant's name could be used.
Here's an example of what such a map might look like:
Since each variant is a separate group, there is no ambiguity with determining which variant a given tile belongs to, so Stamps consisting of disjoint tiles would work just fine with this. When the stamps are loaded, they should be trimmed, so that the empty space around them in the map doesn't affect their position. When the stamp files are written, the stamps should be arranged in rows according to their bounding box, with 1-2 tiles of space between them, so that they don't overlap each other. This makes for a much more pleasant editing experience. Another option is to size the map to the size of the largest stamp and use layer offsets on the groups to position the stamps, which would reduce the amount of empty cells in the layers, but I think this would be more confusing for users not used to working with offset layers.
Additional features that this format could enable without any extra UI for the Tile Stamps panel:
- Naming individual variants (edit the group names)
- Bulk editing of stamp probabilities (select multiple groups at once, edit the probability property)
- Reordering variants (reorder the groups)
If Tiled ever makes it easier to copy entire layers or groups of layers from one map to another, or if a user has a script to aid with this, this system would also make it easier to move variants between different stamps or to convert a variant into its own stamp, which could solve #2982.
In addition, this format could enable setting per-stamp anchors as a pair of custom properties on the group, or with a special layer within the group. This could be even more flexible than the Stamp Brush option suggested in #3250, as the anchor could be placed anywhere within the stamp, rather than being confined to one of nine positions relative to the centre of the stamp. If done with a special layer, then this could be a layer with a custom bool property anchor
set to true
, and the centre of its bounding box would be the anchor (ideally the user would place one tile, but this seems like a robust way to deal with "weird" anchors, and is presumably similar to how Tiled deals with anchors currently). I think this would be the most intuitive method, and it would keep the anchor in place even if the whole stamp is moved within the map. Using a pair of custom properties to store the anchor would require deciding whether the point is a map coordinate or a coordinate relative to the stamp's bounding box, and would need to be manually updated if the user moves the stamp.
To aid in editing, an "Edit Stamp" option should be added to the right-click menu that would open the stamp's map in Tiled and possibly select the bottom-most Tile Layer in the chosen stamp's/variant's group, and with the stamp centred in view.
Edit: An implied requirement for this would be that Tiled needs to watch the stamps directory and reload stamps when files in it change, so that updated stamps are available as soon as the user saves the stamp-map. That change on its own could actually enable most of the rest of this request via a custom map format, though of course that would not be as convenient and feature-rich as a native implementation.
Edit2: If #814 is implemented, it would be desirable to save stamps with deliberately empty "erase here" cells. Perhaps these editable maps could use the Automapping MatchType Empty tiles for this, possibly with a requirement that these have to be the exact tiles from the built-in tileset (so MatchType Empty tiles from other tilesets would just count as regular tiles). Another option is something akin to a "regions" layer like Automapping used to have, but using the Empty tile would be more flexible, allowing a stamp to erase from one layer while not touching that cell in another.