* 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 init(plugin) function IsLayerSelectionMergable()
plugin:newCommand{ for _, layer in ipairs(app.range.layers) do
id="ABASEExportSpritesheetAdvanced", if layer.isGroup then return true end
title="Export Spritesheet (Advanced)",
group="file_export_1",
onclick=function()
cmd.ExportSpritesheetAdvanced()
end,
onenabled=function()
return app.activeSprite ~= nil
end end
} return false
end
plugin:newMenuSeparator{
group="layer_popup_merge" function init(plugin)
} -- New menu UI elements
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{
} id="abase_layer_settings",
title="Advanced Export",
plugin:newMenuGroup{ group="layer_merge",
id="abase_layer_settings_popup", }
title="Advanced Export",
group="layer_popup_merge", plugin:newMenuGroup{
} id="abase_layer_settings_popup",
title="Advanced Export",
plugin:newCommand{ group="layer_popup_merge",
id="ABASEToggleIgnoreLayer", }
title="Toggle Ignore",
group="abase_layer_settings", -- Menu plumbing for export command
onclick=function() plugin:newCommand{
cmd.ToggleIgnore() id="ABASEExportSpritesheetAdvanced",
end title="Export Spritesheet (Advanced)",
} group="file_export_1",
onclick=cmd.ExportSpritesheetAdvanced,
plugin:newCommand{ onenabled=function()
id="ABASEToggleIgnoreLayerPopup", return app.activeSprite ~= nil
title="Toggle Ignore", end,
group="abase_layer_settings_popup", }
onclick=function()
cmd.ToggleIgnore() -- Menu plumbing for ToggleIgnore
end plugin:newCommand{
} id="ABASEToggleIgnoreLayer",
title="Toggle Ignore",
plugin:newCommand{ group="abase_layer_settings",
id="ABASEToggleExportAsSprite", onclick=cmd.ToggleIgnore,
title="Toggle Merge Group", }
group="abase_layer_settings",
onclick=function() plugin:newCommand{
if app.layer.isGroup then id="ABASEToggleIgnoreLayerPopup",
cmd.ToggleExportAsSprite() title="Toggle Ignore",
end group="abase_layer_settings_popup",
end, onclick=cmd.ToggleIgnore,
onenabled=function() }
return app.layer.isGroup
end -- Menu plumbing for ToggleExportAsSprite
} plugin:newCommand{
id="ABASEToggleExportAsSprite",
plugin:newCommand{ title="Toggle Merge Group",
id="ABASEToggleExportAsSpritePopup", group="abase_layer_settings",
title="Toggle Merge Group", onclick=cmd.ToggleExportAsSprite,
group="abase_layer_settings_popup", onenabled=IsLayerSelectionMergable,
onclick=function() }
if app.layer.isGroup then
cmd.ToggleExportAsSprite() plugin:newCommand{
end id="ABASEToggleExportAsSpritePopup",
end, title="Toggle Merge Group",
onenabled=function() group="abase_layer_settings_popup",
return app.layer.isGroup onclick=cmd.ToggleExportAsSprite,
end onenabled=IsLayerSelectionMergable,
} }
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