-
Notifications
You must be signed in to change notification settings - Fork 24
/
remove-unused-tilesets.js
47 lines (40 loc) · 1.12 KB
/
remove-unused-tilesets.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
/// <reference types="@mapeditor/tiled-api" />
/*
* remove-unused-tilesets.js
*
* Example action that removes all unused tilesets.
*
* Uncomment the connection to assetAboutToBeSaved to remove unused tilesets
* automatically on save.
*/
/**
* @param {TileMap} map
*/
function removeUnusedTilesets(map) {
const usedTilesets = map.usedTilesets();
const unusedTilesets = map.tilesets.filter(tileset => !usedTilesets.includes(tileset));
if (unusedTilesets.length > 0) {
tiled.log(`Removing ${unusedTilesets.length} unused tilesets...`);
map.macro("Remove Unused Tilesets", function () {
for (const t of unusedTilesets)
map.removeTileset(t);
});
}
}
const removeUnusedTilesetsAction = tiled.registerAction("RemoveUnusedTilesets", () => {
const map = tiled.activeAsset;
if (!map.isTileMap) {
tiled.error("Not a tile map!");
return;
}
removeUnusedTilesets(map);
});
removeUnusedTilesetsAction.text = "Remove Unused Tilesets";
tiled.extendMenu("Map", [
{ action: "RemoveUnusedTilesets" },
]);
// tiled.assetAboutToBeSaved.connect(asset => {
// if (asset.isTileMap) {
// removeUnusedTilesets(asset);
// }
// });