-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKristalLayers.js
More file actions
43 lines (36 loc) · 1.32 KB
/
KristalLayers.js
File metadata and controls
43 lines (36 loc) · 1.32 KB
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
// @ts-check
function addKristalLayersTo(/** @type {TileMap} */map) {
const tryAddLayer = function (/** @type {string} */ name, /** @type {string} */ color) {
for (let i = 0; i < map.layers.length; i++) {
const layer = map.layers[i];
if (layer.isObjectLayer && layer.name == name) {return}
}
let layer = new ObjectGroup(name)
if (color) layer.color = tiled.color(color)
map.addLayer(layer)
}
tryAddLayer("collision", "#0000FF")
tryAddLayer("paths", "#FF0000")
tryAddLayer("objects", "#FF00FF")
tryAddLayer("controllers", "#00C000")
tryAddLayer("markers", "#7F00FF")
tryAddLayer("battleareas", "#00FF00")
}
let action = tiled.registerAction("CreateKristalLayers", function(action) {
const asset = tiled.activeAsset
if (!asset || !asset.isTileMap) {
tiled.alert("Not a tile map!"); return;
}
const map = /** @type {TileMap} */ (asset)
addKristalLayersTo(map)
})
tiled.assetCreated.connect(function(asset) {
if (!asset.isTileMap) return
const map = /** @type {TileMap} */ (asset)
if (map.tileHeight == 40 && map.tileWidth == 40) addKristalLayersTo(map)
})
action.shortcut = "Ctrl+K"
action.text = "Create Kristal layers"
tiled.extendMenu("Map", [
{action: "CreateKristalLayers", before: "MapProperties"}
])