-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
On tileset click, go to layer #3256
Comments
This is not currently possible, since Tiled has no concept of associating tilesets with layers. It's also not currently possible with scripting, because scripting has no way to react to the selected tile/tileset changing, except as part of a scripted Tool. If a signal like |
I had a quick look, and actually there are undocumented tiled.mapEditor.tilesetsView.currentTileChanged.connect(() => {
tiled.log(tiled.mapEditor.tilesetsView.selectedTiles);
}); The feature might still make sense as a built-in, but it should be possible to select a layer by name based on a custom tile or tileset property. |
Just how many undocumented signals are out there? I even checked TilesetsView hoping there was a signal like that. 🤣 My # 1 request for Tiled: document the signals available xP |
Right, so I've actually tried to do this in adding the missing "changed" signals in 0c7b83d, but this one is kind of an "accidental signal", that wasn't intentionally exposed to the scripts. It just happens to be part of the |
@bjorn Thank you. Promising. Is this where I can get started on scripting? https://doc.mapeditor.org/en/stable/reference/scripting/ From a cursory glance, I injected what you wrote and it seems like it would do trick ... but alas.. nothing? |
Well, what I wrote was just a start, and it just logs to the Console some debug print of which tiles are selected each time the current tile changes. To be actually useful, you'd have to:
|
tiled.mapEditor.tilesetsView.currentTileChanged.connect(() => {
tiled.log(tiled.mapEditor.tilesetsView.selectedTiles);
tiled.log(tiled.mapEditor.tilesetsView.selectedTiles.length);
let layerName = tiled.mapEditor.tilesetsView.selectedTiles[0].property("layer");
tiled.log(layerName);
tiled.log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
}); output:
How can get the layer name if this custom property I am trying to fetch won't be returned? What am I doing wrong? UpdateEven doing |
|
AH. Ah. I see. You're getting the tile. I need to learn to read. I was doing the layers (tileset) property and getting nothing. I amended the tileset and did the same.. I see. I see. I can just do |
Yep! Just make sure you check that the activeAsset.isTileMap before you try to do anything with its layers. Also, watch out for that issue I mentioned where the tiled.mapEditor.tilesetsView.currentTileChanged.connect(() => {
tiled.log( tiled.mapEditor.tilesetsView.selectedTiles[0].id );
}); consistently shows me the ID of the tile I previously clicked rather than the tile I just clicked... |
Yeah. I'm getting it now. I see. And yeah, that's interesting. Look at the API, https://www.mapeditor.org/docs/scripting/classes/layer.html looks like I have to get the layer and select it, too. Hmm more work to do it seems for me. I can also do this: And I get the tileset of the tile so now all I have to do is go through the layer and select where the tileset and the layer name match... and select it! Fun. |
Yes, you'll need to iterate all the layers until you find the one you want. If you use groups, this can get complicated. Here's a recursive function that'll take care of that, plus some extra code you may find useful. let map = tiled.activeAsset;
if(!map.isTileMap)
return;
let targetName = /* read the name from the selected tile property, as you figured out in earlier posts */;
function findLayer(curLayer) {
if(curLayer.isGroupLayer || curLayer.isTileMap) {
let numLayers = curLayer.layerCount;
for(let layerID = 0; layerID < numLayers; layerID++) {
let found = findLayer(curLayer.layerAt(layerID));
if(found)
return found;
}
} else if(curLayer.name == targetName)
return curLayer;
return null;
}
let layer = findLayer(map);
if(layer) //only change the layer if a match was found
map.currentLayer = layer; |
Yeah. I was looking for You may close this issue if need be. |
Right, something I hadn't realized (and this was an accidentally exposed signal, remember?). Maybe it works better if you connect to the other accidental signal,
Alright, I'll close this issue. The synchronization could also be implemented in the other direction, so that when you change the layer ( Btw, since this kind of functionality seems useful to other people as well, you should consider publishing your extension. :-) |
Let's say you have a orthogonal 2D tile map. Two layers, background and foreground with two tilesets. One for each layer that will always stay in their respective layer.
Is there a way on Tiled to make it so when you click on, for example, the background tileset, for Tiled to automatically go to the "Background" layer? One less click. Less work.
The text was updated successfully, but these errors were encountered: