advanced-spritesheet-export/abase-layer.lua
2024-07-30 22:58:23 -04:00

55 lines
1.4 KiB
Lua

-- Functions for modifying layers recursively based on configuration flags
local p = require "abase-properties"
-- Deletes any layers with the 'ignored' property.
local function DeleteLayers(spr, layers)
for _, layer in ipairs(layers) do
if p.IsIgnored(layer) then
spr:deleteLayer(layer)
elseif layer.isGroup then
DeleteLayers(spr, layer.layers)
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
if not layer.isGroup then
goto continue
end
if p.IsMerged(layer) then
app.range.layers = {layer}
app.command.FlattenLayers(false)
else
-- recurse
FlattenLayers(layer.layers)
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
if layer.isGroup then
RevealLayers(layer.layers)
end
if not layer.isVisible then
layer.isVisible = true
end
end
end
local export = {
DeleteLayers = DeleteLayers,
FlattenLayers = FlattenLayers,
RevealLayers = RevealLayers,
}
return export