Skip to content

Commit

Permalink
Added Automatic / Manual root positioning
Browse files Browse the repository at this point in the history
  • Loading branch information
RampantDespair committed Jul 21, 2023
1 parent 44efec4 commit a8d6f4f
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 36 deletions.
115 changes: 81 additions & 34 deletions Aseprite-Exporter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ function Export(activeSprite, rootLayer, fileName, fileNameTemplate, dlgData)
ExportSpineJsonStart(fileName, dlgData)
end

if dlgData.setRootPostion == true and dlgData.rootPostionMethod == "automatic" then
for _, layer in ipairs(rootLayer.layers) do
if layer.name == "root" then
RootPositon = layer.cels[1].position
break
end
end
app.alert("Automatic RootPosition is x:" .. RootPositon.x .. " y:" .. RootPositon.y)
end

ExportSpriteLayers(activeSprite, rootLayer, fileName, fileNameTemplate, dlgData)

if dlgData.exportSpineSheet == true then
Expand All @@ -49,42 +59,44 @@ function ExportSpriteLayers(activeSprite, rootLayer, fileName, fileNameTemplate,
local _fileNameTemplate = fileNameTemplate
local layerName = layer.name

if layer.isGroup then
local previousVisibility = layer.isVisible
layer.isVisible = true
if layerName ~= "root" then
if layer.isGroup then
local previousVisibility = layer.isVisible
layer.isVisible = true

if dlgData.groupsAsSkins == true then
_fileNameTemplate = app.fs.joinPath(layerName, _fileNameTemplate)
end

ExportSpriteLayers(activeSprite, layer, fileName, _fileNameTemplate, dlgData)
if dlgData.groupsAsSkins == true then
_fileNameTemplate = app.fs.joinPath(layerName, _fileNameTemplate)
end

layer.isVisible = previousVisibility
else
layer.isVisible = true
ExportSpriteLayers(activeSprite, layer, fileName, _fileNameTemplate, dlgData)

local layerParentName
if pcall(function () layerParentName = layer.parent.name end) then
_fileNameTemplate = _fileNameTemplate:gsub("{layergroup}", layerParentName)
layer.isVisible = previousVisibility
else
_fileNameTemplate = _fileNameTemplate:gsub("{layergroup}", "default")
end

_fileNameTemplate = _fileNameTemplate:gsub("{layername}", layerName)
layer.isVisible = true

if #layer.cels ~= 0 then
if dlgData.exportSpriteSheet then
ExportSpriteSheet(activeSprite, layer, _fileNameTemplate, dlgData)
local layerParentName
if pcall(function () layerParentName = layer.parent.name end) then
_fileNameTemplate = _fileNameTemplate:gsub("{layergroup}", layerParentName)
else
_fileNameTemplate = _fileNameTemplate:gsub("{layergroup}", "default")
end

if dlgData.exportSpineSheet == true then
ExportSpineJsonParse(activeSprite, layer, _fileNameTemplate, dlgData)
_fileNameTemplate = _fileNameTemplate:gsub("{layername}", layerName)

if #layer.cels ~= 0 then
if dlgData.exportSpriteSheet then
ExportSpriteSheet(activeSprite, layer, _fileNameTemplate, dlgData)
end

if dlgData.exportSpineSheet == true then
ExportSpineJsonParse(activeSprite, layer, _fileNameTemplate, dlgData)
end

LayerCount = LayerCount + 1
end

LayerCount = LayerCount + 1
layer.isVisible = false
end

layer.isVisible = false
end
end
end
Expand Down Expand Up @@ -139,8 +151,21 @@ function ExportSpineJsonParse(activeSprite, layer, fileNameTemplate, dlgData)
local realPostionX = layerCelX + layerCelWidth / 2
local realPositionY = layerCelY + layerCelHeight / 2

local spriteX = realPostionX - dlgData.rootPositionX
local spriteY = dlgData.rootPositionY - realPositionY
local spriteX
local spriteY

if dlgData.setRootPostion == true then
if dlgData.rootPostionMethod == "automatic" then
spriteX = realPostionX - RootPositon.x
spriteY = RootPositon.y - realPositionY
else
spriteX = realPostionX - dlgData.rootPositionX
spriteY = dlgData.rootPositionY - realPositionY
end
else
spriteX = realPostionX
spriteY = realPositionY
end

if dlgData.groupsAsSkins == true then
fileNameTemplate = fileNameTemplate:gsub("\\", "/")
Expand Down Expand Up @@ -341,9 +366,13 @@ dlg:check{
}
dlg:check{
id = "setRootPostion",
label = "Set Root position",
label = "Set Root position:",
selected = true,
onclick = function()
dlg:modify{
id = "rootPostionMethod",
visible = dlg.data.setRootPostion
}
dlg:modify{
id = "rootPositionX",
visible = dlg.data.setRootPostion
Expand All @@ -354,17 +383,35 @@ dlg:check{
}
end
}
dlg:combobox{
id = "rootPostionMethod",
label = " Root position method:",
option = "automatic",
options = {"manual", "automatic"},
onchange = function()
dlg:modify{
id = "rootPositionX",
visible = dlg.data.rootPostionMethod == "manual"
}
dlg:modify{
id = "rootPositionY",
visible = dlg.data.rootPostionMethod == "manual"
}
end
}
dlg:number{
id = "rootPositionX",
label = " Root Postion X:",
label = " Root Postion X:",
text = "0",
decimals = 0
decimals = 0,
visible = false
}
dlg:number{
id = "rootPositionY",
label = " Root Postion Y:",
label = " Root Postion Y:",
text = "0",
decimals = 0
decimals = 0,
visible = false
}
dlg:separator{
id = "separator4",
Expand Down Expand Up @@ -444,7 +491,7 @@ dlg:button{id = "confirm", text = "Confirm"}
dlg:button{id = "cancel", text = "Cancel"}
dlg:show()

if not dlg.data.confirm then
if not dlg.data.confirm then
app.alert("Settings were not confirmed, script aborted.")
return
end
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Aseprite-Exporter
---
### Showcase
![showcase](media/showcase-v2.3.png)
![showcase](media/showcase-v2.6.png)

### Features
- Configurable output path
Expand Down
Binary file modified example/SpineTest.spine
Binary file not shown.
Binary file modified example/SpriteTest.aseprite
Binary file not shown.
2 changes: 1 addition & 1 deletion example/SpriteTest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{ "skeleton": { "images": "./sprite/", "audio": "./sound/" }, "bones": [ { "name": "root" } ], "slots": [ { "name": "square2", "bone": "root", "attachment": "square2" }, { "name": "square", "bone": "root", "attachment": "square" }], "skins": [ { "name": "default", "attachments": { "square2": { "SpriteTest-default-square2": { "x": 12.00, "y": -4.00, "width": 8, "height": 8 } } } }, { "name": "weapon-blue", "attachments": { "square": { "square": { "name": "blue/SpriteTest-blue-square", "x": 4.00, "y": -4.00, "width": 8, "height": 8 } } } }, { "name": "weapon-green", "attachments": { "square": { "square": { "name": "green/SpriteTest-green-square", "x": 4.00, "y": -4.00, "width": 8, "height": 8 } } } }, { "name": "weapon-red", "attachments": { "square": { "square": { "name": "red/SpriteTest-red-square", "x": 4.00, "y": -4.00, "width": 8, "height": 8 } } } }] }
{ "skeleton": { "images": "./sprite/", "audio": "./sound/" }, "bones": [ { "name": "root" } ], "slots": [ { "name": "square2", "bone": "root", "attachment": "square2" }, { "name": "square", "bone": "root", "attachment": "square" }], "skins": { "default": { "square2": { "SpriteTest-default-square2": { "x": -3.00, "y": 3.00, "width": 8, "height": 8 } } , "square": { "SpriteTest-green-square": { "x": -11.00, "y": 3.00, "width": 8, "height": 8 } } , "square": { "SpriteTest-red-square": { "x": -11.00, "y": 3.00, "width": 8, "height": 8 } } , "square": { "SpriteTest-blue-square": { "x": -11.00, "y": 3.00, "width": 8, "height": 8 } } } } }
Binary file added media/showcase-v2.6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a8d6f4f

Please sign in to comment.