Skip to content

Scripting: Allow specifying layer types for which a Tool should be enabled #3248

@eishiya

Description

@eishiya

Scripted Tools can be set to enabled or disabled, but in most cases, this just needs to react to the currently selected layer(s) without much complex logic. We have Tool.updateEnabledState() in which to make these decisions, but it would be great to offload this work to Tiled and just specify what kinds of layers the tool should be enabled or disabled on. Tiled already handles similar logic with Tool.usesSelectedTiles, which prevents the tool from changing when the user picks a tile in a tileset.

In #3246, it was suggested to have boolean properies like allowForObjectLayers, allowForTileLayers. I think it might be better to specify a single property like activateOn: ObjectGroup | ImageLayer | GroupLayer, so that its absence can less ambiguously mean "active for all layers".

It would be cool to have an additional property that decides whether to activate the tool when any of the selected layers are valid vs requiring all selected layers to be valid. Or I guess there can be one default behaviour, and if someone wants it different, they can override it in their script using the usual (tedious) method.

If Tileset tools are ever added, this could be expanded with Tileset as an additional acceptable item.

Metadata

Metadata

Assignees

Labels

featureIt's a feature, not a bug.

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions