advanced-spritesheet-export/abase-layer.lua

55 lines
1.4 KiB
Lua
Raw Normal View History

2024-07-31 02:58:23 +00:00
-- Functions for modifying layers recursively based on configuration flags
local p = require "abase-properties"
2024-07-30 01:25:14 +00:00
-- Deletes any layers with the 'ignored' property.
local function DeleteLayers(spr, layers)
for _, layer in ipairs(layers) do
2024-07-31 02:58:23 +00:00
if p.IsIgnored(layer) then
2024-07-30 01:25:14 +00:00
spr:deleteLayer(layer)
elseif layer.isGroup then
DeleteLayers(spr, layer.layers)
2024-07-30 01:25:14 +00:00
end
end
end
-- Flattens any layers that have the 'exportedAsSprite' property.
-- Should be called after deleteLayers.
local function FlattenLayers(layers)
for _, layer in ipairs(layers) do
2024-07-30 01:25:14 +00:00
if not layer.isGroup then
goto continue
end
2024-07-31 02:58:23 +00:00
if p.IsMerged(layer) then
2024-07-30 01:25:14 +00:00
app.range.layers = {layer}
app.command.FlattenLayers(false)
else
-- recurse
FlattenLayers(layer.layers)
2024-07-30 01:25:14 +00:00
end
::continue::
end
end
-- Makes all layers visible.
-- This should be called after deleteLayers and flattenLayers
local function RevealLayers(layers)
for _, layer in ipairs(layers) do
2024-07-30 01:25:14 +00:00
if layer.isGroup then
RevealLayers(layer.layers)
2024-07-30 01:25:14 +00:00
end
if not layer.isVisible then
layer.isVisible = true
end
end
end
local export = {
DeleteLayers = DeleteLayers,
FlattenLayers = FlattenLayers,
RevealLayers = RevealLayers,
2024-07-30 01:25:14 +00:00
}
return export