* 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()
end
local function ToggleIgnore()
local layer = app.layer
local function toggleIgnoreLayer(layer)
if (layer.properties(extKey).ignored) then
layer.properties(extKey).ignored = false
else
@ -30,8 +29,17 @@ local function ToggleIgnore()
colorUtils.SetColorFromRoot(layer)
end
local function ToggleExportAsSprite()
local layer = app.layer
-- Toggle ignore for all selected layers
-- 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
layer.properties(extKey).exportedAsSprite = false
else
@ -40,6 +48,14 @@ local function ToggleExportAsSprite()
colorUtils.SetColorFromRoot(layer)
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 = {
ExportSpritesheetAdvanced = ExportSpritesheetAdvanced,
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.
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 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)
plugin:newCommand{
id="ABASEExportSpritesheetAdvanced",
title="Export Spritesheet (Advanced)",
group="file_export_1",
onclick=function()
cmd.ExportSpritesheetAdvanced()
end,
onenabled=function()
return app.activeSprite ~= nil
end
}
-- New menu UI elements
plugin:newMenuSeparator{
group="layer_popup_merge"
}
plugin:newMenuSeparator{
group="layer_popup_merge"
}
plugin:newMenuSeparator{
group="layer_merge"
}
plugin:newMenuSeparator{
group="layer_merge"
}
plugin:newMenuGroup{
id="abase_layer_settings",
title="Advanced Export",
group="layer_merge",
}
plugin:newMenuGroup{
id="abase_layer_settings",
title="Advanced Export",
group="layer_merge",
}
plugin:newMenuGroup{
id="abase_layer_settings_popup",
title="Advanced Export",
group="layer_popup_merge",
}
plugin:newMenuGroup{
id="abase_layer_settings_popup",
title="Advanced Export",
group="layer_popup_merge",
}
-- Menu plumbing for export command
plugin:newCommand{
id="ABASEExportSpritesheetAdvanced",
title="Export Spritesheet (Advanced)",
group="file_export_1",
onclick=cmd.ExportSpritesheetAdvanced,
onenabled=function()
return app.activeSprite ~= nil
end,
}
plugin:newCommand{
id="ABASEToggleIgnoreLayer",
title="Toggle Ignore",
group="abase_layer_settings",
onclick=function()
cmd.ToggleIgnore()
end
}
-- Menu plumbing for ToggleIgnore
plugin:newCommand{
id="ABASEToggleIgnoreLayer",
title="Toggle Ignore",
group="abase_layer_settings",
onclick=cmd.ToggleIgnore,
}
plugin:newCommand{
id="ABASEToggleIgnoreLayerPopup",
title="Toggle Ignore",
group="abase_layer_settings_popup",
onclick=function()
cmd.ToggleIgnore()
end
}
plugin:newCommand{
id="ABASEToggleIgnoreLayerPopup",
title="Toggle Ignore",
group="abase_layer_settings_popup",
onclick=cmd.ToggleIgnore,
}
plugin:newCommand{
id="ABASEToggleExportAsSprite",
title="Toggle Merge Group",
group="abase_layer_settings",
onclick=function()
if app.layer.isGroup then
cmd.ToggleExportAsSprite()
end
end,
onenabled=function()
return app.layer.isGroup
end
}
-- Menu plumbing for ToggleExportAsSprite
plugin:newCommand{
id="ABASEToggleExportAsSprite",
title="Toggle Merge Group",
group="abase_layer_settings",
onclick=cmd.ToggleExportAsSprite,
onenabled=IsLayerSelectionMergable,
}
plugin:newCommand{
id="ABASEToggleExportAsSpritePopup",
title="Toggle Merge Group",
group="abase_layer_settings_popup",
onclick=function()
if app.layer.isGroup then
cmd.ToggleExportAsSprite()
end
end,
onenabled=function()
return app.layer.isGroup
end
}
plugin:newCommand{
id="ABASEToggleExportAsSpritePopup",
title="Toggle Merge Group",
group="abase_layer_settings_popup",
onclick=cmd.ToggleExportAsSprite,
onenabled=IsLayerSelectionMergable,
}
app.events:on(
"aftercommand",
function(ev)
if (ev.name == "NewLayer") then
listeners.RecolorLayers()
end
end
)
-- Event hooks
app.events:on(
"aftercommand",
function(ev)
if (ev.name == "NewLayer") then
listeners.RecolorLayers()
end
end
)
end

View File

@ -2,7 +2,7 @@
"name": "advanced-spritesheets",
"displayName": "Advanced Spritesheets",
"description": "Improved spritesheet export functionality for Aseprite.",
"version": "0.0.6",
"version": "0.0.11",
"author": { "name": "Anna Wiggins",
"email": "annabunches@gmail.com",
"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.
* Export groups as a single sprite.
* Configure layer settings via Layer menu, right click menu, or keyboard shortcut.
## Usage