* Add ability to apply settings to multiple selected layers at once.

* Clean up plugin plumbing.
This commit is contained in:
Anna Rose 2024-07-30 21:10:43 -04:00
parent 82e1ab7523
commit 128258cd62
5 changed files with 94 additions and 83 deletions

View File

@ -20,8 +20,7 @@ local function ExportSpritesheetAdvanced()
spr:close() spr:close()
end end
local function ToggleIgnore() local function toggleIgnoreLayer(layer)
local layer = app.layer
if (layer.properties(extKey).ignored) then if (layer.properties(extKey).ignored) then
layer.properties(extKey).ignored = false layer.properties(extKey).ignored = false
else else
@ -30,8 +29,17 @@ local function ToggleIgnore()
colorUtils.SetColorFromRoot(layer) colorUtils.SetColorFromRoot(layer)
end end
local function ToggleExportAsSprite() -- Toggle ignore for all selected layers
local layer = app.layer -- TODO: should this behavior change when selected layers start with mixed state?
local function ToggleIgnore()
for _, layer in ipairs(app.range.layers) do
toggleIgnoreLayer(layer)
end
end
local function toggleExportAsSpriteLayer(layer)
if not layer.isGroup then return end
if (layer.properties(extKey).exportedAsSprite) then if (layer.properties(extKey).exportedAsSprite) then
layer.properties(extKey).exportedAsSprite = false layer.properties(extKey).exportedAsSprite = false
else else
@ -40,6 +48,14 @@ local function ToggleExportAsSprite()
colorUtils.SetColorFromRoot(layer) colorUtils.SetColorFromRoot(layer)
end end
-- Toggle Merge on Export for all selected group layers
-- TODO: should this behavior change when selected layers start with mixed state?
local function ToggleExportAsSprite()
for _, layer in ipairs(app.range.layers) do
toggleExportAsSpriteLayer(layer)
end
end
local export = { local export = {
ExportSpritesheetAdvanced = ExportSpritesheetAdvanced, ExportSpritesheetAdvanced = ExportSpritesheetAdvanced,
ToggleIgnore = ToggleIgnore, ToggleIgnore = ToggleIgnore,

View File

@ -1,4 +1,4 @@
-- Functions for modifying a sprite -- Functions for modifying a sprite's layers based on configuration flags
-- Deletes any layers with the 'ignored' property. -- Deletes any layers with the 'ignored' property.
local function DeleteLayers(spr, layers) local function DeleteLayers(spr, layers)

View File

@ -3,91 +3,85 @@ extKey = "annabunches/abase" -- this must come before we require 'abase-commands
local cmd = require "abase-commands" local cmd = require "abase-commands"
local listeners = require "abase-listeners" local listeners = require "abase-listeners"
function IsLayerSelectionMergable()
for _, layer in ipairs(app.range.layers) do
if layer.isGroup then return true end
end
return false
end
function init(plugin) function init(plugin)
plugin:newCommand{ -- New menu UI elements
id="ABASEExportSpritesheetAdvanced", plugin:newMenuSeparator{
title="Export Spritesheet (Advanced)", group="layer_popup_merge"
group="file_export_1", }
onclick=function()
cmd.ExportSpritesheetAdvanced()
end,
onenabled=function()
return app.activeSprite ~= nil
end
}
plugin:newMenuSeparator{ plugin:newMenuSeparator{
group="layer_popup_merge" group="layer_merge"
} }
plugin:newMenuSeparator{ plugin:newMenuGroup{
group="layer_merge" id="abase_layer_settings",
} title="Advanced Export",
group="layer_merge",
}
plugin:newMenuGroup{ plugin:newMenuGroup{
id="abase_layer_settings", id="abase_layer_settings_popup",
title="Advanced Export", title="Advanced Export",
group="layer_merge", group="layer_popup_merge",
} }
plugin:newMenuGroup{ -- Menu plumbing for export command
id="abase_layer_settings_popup", plugin:newCommand{
title="Advanced Export", id="ABASEExportSpritesheetAdvanced",
group="layer_popup_merge", title="Export Spritesheet (Advanced)",
} group="file_export_1",
onclick=cmd.ExportSpritesheetAdvanced,
onenabled=function()
return app.activeSprite ~= nil
end,
}
plugin:newCommand{ -- Menu plumbing for ToggleIgnore
id="ABASEToggleIgnoreLayer", plugin:newCommand{
title="Toggle Ignore", id="ABASEToggleIgnoreLayer",
group="abase_layer_settings", title="Toggle Ignore",
onclick=function() group="abase_layer_settings",
cmd.ToggleIgnore() onclick=cmd.ToggleIgnore,
end }
}
plugin:newCommand{ plugin:newCommand{
id="ABASEToggleIgnoreLayerPopup", id="ABASEToggleIgnoreLayerPopup",
title="Toggle Ignore", title="Toggle Ignore",
group="abase_layer_settings_popup", group="abase_layer_settings_popup",
onclick=function() onclick=cmd.ToggleIgnore,
cmd.ToggleIgnore() }
end
}
plugin:newCommand{ -- Menu plumbing for ToggleExportAsSprite
id="ABASEToggleExportAsSprite", plugin:newCommand{
title="Toggle Merge Group", id="ABASEToggleExportAsSprite",
group="abase_layer_settings", title="Toggle Merge Group",
onclick=function() group="abase_layer_settings",
if app.layer.isGroup then onclick=cmd.ToggleExportAsSprite,
cmd.ToggleExportAsSprite() onenabled=IsLayerSelectionMergable,
end }
end,
onenabled=function()
return app.layer.isGroup
end
}
plugin:newCommand{ plugin:newCommand{
id="ABASEToggleExportAsSpritePopup", id="ABASEToggleExportAsSpritePopup",
title="Toggle Merge Group", title="Toggle Merge Group",
group="abase_layer_settings_popup", group="abase_layer_settings_popup",
onclick=function() onclick=cmd.ToggleExportAsSprite,
if app.layer.isGroup then onenabled=IsLayerSelectionMergable,
cmd.ToggleExportAsSprite() }
end
end,
onenabled=function()
return app.layer.isGroup
end
}
app.events:on( -- Event hooks
"aftercommand", app.events:on(
function(ev) "aftercommand",
if (ev.name == "NewLayer") then function(ev)
listeners.RecolorLayers() if (ev.name == "NewLayer") then
end listeners.RecolorLayers()
end end
) end
)
end end

View File

@ -2,7 +2,7 @@
"name": "advanced-spritesheets", "name": "advanced-spritesheets",
"displayName": "Advanced Spritesheets", "displayName": "Advanced Spritesheets",
"description": "Improved spritesheet export functionality for Aseprite.", "description": "Improved spritesheet export functionality for Aseprite.",
"version": "0.0.6", "version": "0.0.11",
"author": { "name": "Anna Wiggins", "author": { "name": "Anna Wiggins",
"email": "annabunches@gmail.com", "email": "annabunches@gmail.com",
"url": "https://annabunches.net" }, "url": "https://annabunches.net" },

View File

@ -10,6 +10,7 @@ To install, go to Aseprite's Settings -> Extensions -> Add Extension, and select
* Choose which layers to export, regardless of visibility. * Choose which layers to export, regardless of visibility.
* Export groups as a single sprite. * Export groups as a single sprite.
* Configure layer settings via Layer menu, right click menu, or keyboard shortcut.
## Usage ## Usage