Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scripting: Added MapEditor.currentBrushChanged signal #4005

Merged
merged 1 commit into from
Jul 18, 2024

Conversation

bjorn
Copy link
Member

@bjorn bjorn commented Jul 11, 2024

So scripts can respond to brush changes. If they are careful, they can also adjust the brush, though this will trigger another currentBrushChanged call.

@franciscod
Copy link

I was just looking for this on the Scripting API. Hope this gets merged soon!

(Trying to have that when you pick a tile on the tileset, a layer on the map gets selected depending on a property on the tile)

@franciscod
Copy link

franciscod commented Jul 17, 2024

I've cloned this branch, built tiled and with the new signal my extension works as I wanted!

With this, if there's a layer property (set to a layer name) on a tile you select on the tileset, the layer with the matching name gets selected (and all others get deselected).

var selectLayerOfTileWhenBrushChanged = function() {
	var asset = tiled.activeAsset
	if (!asset.isTileMap) {
		return
	}
	var brushLayer = tiled.mapEditor.currentBrush.layers[0]
	if (brushLayer.size.height != 1 || brushLayer.size.width != 1) {
		return
	}

	var tile = brushLayer.tileAt(0, 0)
	var tileLayer = tile.property('layer')
	if (!tileLayer) {
		return
	}

	for (var i = 0; i < asset.layerCount; i++) {
		var layer = asset.layers[i]
		var shouldSelect = layer.name == tileLayer
		layer.selected = shouldSelect
	}
}

tiled.mapEditor.currentBrushChanged.connect(selectLayerOfTileWhenBrushChanged)

So scripts can respond to brush changes. If they are careful, they can
also adjust the brush, though this will trigger another
`currentBrushChanged` call.
@bjorn bjorn merged commit 29aa44b into mapeditor:master Jul 18, 2024
13 of 14 checks passed
@bjorn bjorn deleted the current-brush-changed branch July 18, 2024 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants