Skip to content

Commit a8d6f4f

Browse files
Added Automatic / Manual root positioning
1 parent 44efec4 commit a8d6f4f

File tree

6 files changed

+83
-36
lines changed

6 files changed

+83
-36
lines changed

Aseprite-Exporter.lua

Lines changed: 81 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ function Export(activeSprite, rootLayer, fileName, fileNameTemplate, dlgData)
3737
ExportSpineJsonStart(fileName, dlgData)
3838
end
3939

40+
if dlgData.setRootPostion == true and dlgData.rootPostionMethod == "automatic" then
41+
for _, layer in ipairs(rootLayer.layers) do
42+
if layer.name == "root" then
43+
RootPositon = layer.cels[1].position
44+
break
45+
end
46+
end
47+
app.alert("Automatic RootPosition is x:" .. RootPositon.x .. " y:" .. RootPositon.y)
48+
end
49+
4050
ExportSpriteLayers(activeSprite, rootLayer, fileName, fileNameTemplate, dlgData)
4151

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

52-
if layer.isGroup then
53-
local previousVisibility = layer.isVisible
54-
layer.isVisible = true
62+
if layerName ~= "root" then
63+
if layer.isGroup then
64+
local previousVisibility = layer.isVisible
65+
layer.isVisible = true
5566

56-
if dlgData.groupsAsSkins == true then
57-
_fileNameTemplate = app.fs.joinPath(layerName, _fileNameTemplate)
58-
end
59-
60-
ExportSpriteLayers(activeSprite, layer, fileName, _fileNameTemplate, dlgData)
67+
if dlgData.groupsAsSkins == true then
68+
_fileNameTemplate = app.fs.joinPath(layerName, _fileNameTemplate)
69+
end
6170

62-
layer.isVisible = previousVisibility
63-
else
64-
layer.isVisible = true
71+
ExportSpriteLayers(activeSprite, layer, fileName, _fileNameTemplate, dlgData)
6572

66-
local layerParentName
67-
if pcall(function () layerParentName = layer.parent.name end) then
68-
_fileNameTemplate = _fileNameTemplate:gsub("{layergroup}", layerParentName)
73+
layer.isVisible = previousVisibility
6974
else
70-
_fileNameTemplate = _fileNameTemplate:gsub("{layergroup}", "default")
71-
end
72-
73-
_fileNameTemplate = _fileNameTemplate:gsub("{layername}", layerName)
75+
layer.isVisible = true
7476

75-
if #layer.cels ~= 0 then
76-
if dlgData.exportSpriteSheet then
77-
ExportSpriteSheet(activeSprite, layer, _fileNameTemplate, dlgData)
77+
local layerParentName
78+
if pcall(function () layerParentName = layer.parent.name end) then
79+
_fileNameTemplate = _fileNameTemplate:gsub("{layergroup}", layerParentName)
80+
else
81+
_fileNameTemplate = _fileNameTemplate:gsub("{layergroup}", "default")
7882
end
7983

80-
if dlgData.exportSpineSheet == true then
81-
ExportSpineJsonParse(activeSprite, layer, _fileNameTemplate, dlgData)
84+
_fileNameTemplate = _fileNameTemplate:gsub("{layername}", layerName)
85+
86+
if #layer.cels ~= 0 then
87+
if dlgData.exportSpriteSheet then
88+
ExportSpriteSheet(activeSprite, layer, _fileNameTemplate, dlgData)
89+
end
90+
91+
if dlgData.exportSpineSheet == true then
92+
ExportSpineJsonParse(activeSprite, layer, _fileNameTemplate, dlgData)
93+
end
94+
95+
LayerCount = LayerCount + 1
8296
end
8397

84-
LayerCount = LayerCount + 1
98+
layer.isVisible = false
8599
end
86-
87-
layer.isVisible = false
88100
end
89101
end
90102
end
@@ -139,8 +151,21 @@ function ExportSpineJsonParse(activeSprite, layer, fileNameTemplate, dlgData)
139151
local realPostionX = layerCelX + layerCelWidth / 2
140152
local realPositionY = layerCelY + layerCelHeight / 2
141153

142-
local spriteX = realPostionX - dlgData.rootPositionX
143-
local spriteY = dlgData.rootPositionY - realPositionY
154+
local spriteX
155+
local spriteY
156+
157+
if dlgData.setRootPostion == true then
158+
if dlgData.rootPostionMethod == "automatic" then
159+
spriteX = realPostionX - RootPositon.x
160+
spriteY = RootPositon.y - realPositionY
161+
else
162+
spriteX = realPostionX - dlgData.rootPositionX
163+
spriteY = dlgData.rootPositionY - realPositionY
164+
end
165+
else
166+
spriteX = realPostionX
167+
spriteY = realPositionY
168+
end
144169

145170
if dlgData.groupsAsSkins == true then
146171
fileNameTemplate = fileNameTemplate:gsub("\\", "/")
@@ -341,9 +366,13 @@ dlg:check{
341366
}
342367
dlg:check{
343368
id = "setRootPostion",
344-
label = "Set Root position",
369+
label = "Set Root position:",
345370
selected = true,
346371
onclick = function()
372+
dlg:modify{
373+
id = "rootPostionMethod",
374+
visible = dlg.data.setRootPostion
375+
}
347376
dlg:modify{
348377
id = "rootPositionX",
349378
visible = dlg.data.setRootPostion
@@ -354,17 +383,35 @@ dlg:check{
354383
}
355384
end
356385
}
386+
dlg:combobox{
387+
id = "rootPostionMethod",
388+
label = " Root position method:",
389+
option = "automatic",
390+
options = {"manual", "automatic"},
391+
onchange = function()
392+
dlg:modify{
393+
id = "rootPositionX",
394+
visible = dlg.data.rootPostionMethod == "manual"
395+
}
396+
dlg:modify{
397+
id = "rootPositionY",
398+
visible = dlg.data.rootPostionMethod == "manual"
399+
}
400+
end
401+
}
357402
dlg:number{
358403
id = "rootPositionX",
359-
label = " Root Postion X:",
404+
label = " Root Postion X:",
360405
text = "0",
361-
decimals = 0
406+
decimals = 0,
407+
visible = false
362408
}
363409
dlg:number{
364410
id = "rootPositionY",
365-
label = " Root Postion Y:",
411+
label = " Root Postion Y:",
366412
text = "0",
367-
decimals = 0
413+
decimals = 0,
414+
visible = false
368415
}
369416
dlg:separator{
370417
id = "separator4",
@@ -444,7 +491,7 @@ dlg:button{id = "confirm", text = "Confirm"}
444491
dlg:button{id = "cancel", text = "Cancel"}
445492
dlg:show()
446493

447-
if not dlg.data.confirm then
494+
if not dlg.data.confirm then
448495
app.alert("Settings were not confirmed, script aborted.")
449496
return
450497
end

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Aseprite-Exporter
22
---
33
### Showcase
4-
![showcase](media/showcase-v2.3.png)
4+
![showcase](media/showcase-v2.6.png)
55

66
### Features
77
- Configurable output path

example/SpineTest.spine

10 Bytes
Binary file not shown.

example/SpriteTest.aseprite

66 Bytes
Binary file not shown.

example/SpriteTest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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 } } } }] }
1+
{ "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 } } } } }

media/showcase-v2.6.png

23.5 KB
Loading

0 commit comments

Comments
 (0)