-
Notifications
You must be signed in to change notification settings - Fork 3
/
SelectLayerTiles.js
62 lines (54 loc) · 1.89 KB
/
SelectLayerTiles.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* Select Layer Tiles by eishiya, last updated 8 Sep 2024
Adds an action to the Layer context menu to select
all of the selected Tile Layers' non-empty tiles.
This opens up various workflows, such as quickly filling the shape
of a layer with shift+bucket fill, "saving" selections as layers,
and being able to quickly use a layer as a faux mask.
*/
const selectLayerTiles = tiled.registerAction("SelectLayerTiles", function(action) {
let map = tiled.activeAsset;
if(!map || !map.isTileMap)
return;
let layersSelected = 0;
for(let layer of map.selectedLayers) {
if(!layer.isTileLayer)
continue;
if(layersSelected = 0)
map.selectedArea.set(layer.region());
else
map.selectedArea.add(layer.region());
}
});
selectLayerTiles.text = "Select Layer Tiles";
//Only enable the action while the currentLayer is a TileLayer:
selectLayerTiles.previousAsset = null;
selectLayerTiles.updateActive = function() {
if(selectLayerTiles.previousAsset && selectLayerTiles.previousAsset.isTileMap) {
selectLayerTiles.previousAsset.selectedLayersChanged.disconnect(selectLayerTiles.updateActive);
}
let asset = tiled.activeAsset;
if(asset && asset.isTileMap) {
selectLayerTiles.previousAsset = asset;
asset.selectedLayersChanged.connect(selectLayerTiles.updateActive);
let tileLayersFound = false;
for(let layer of asset.selectedLayers) {
if(layer.isTileLayer) {
tileLayersFound = true;
break;
}
}
if(tileLayersFound)
selectLayerTiles.enabled = true;
else
selectLayerTiles.enabled = false;
} else {
selectLayerTiles.enabled = false;
}
}
selectLayerTiles.updateActive();
tiled.activeAssetChanged.connect(selectLayerTiles.updateActive);
//Add this action to the Layers panel context menu:
tiled.extendMenu("LayerView.Layers", [
{ action: "SelectLayerTiles", before: "LayerProperties" },
{ separator: true }
]);