diff --git a/Aseprite-Exporter.lua b/Aseprite-Exporter.lua index 771f995..689cd0a 100644 --- a/Aseprite-Exporter.lua +++ b/Aseprite-Exporter.lua @@ -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 @@ -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 @@ -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("\\", "/") @@ -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 @@ -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", @@ -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 diff --git a/README.md b/README.md index 70c28bd..c9f6e14 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Aseprite-Exporter --- ### Showcase -![showcase](media/showcase-v2.3.png) +![showcase](media/showcase-v2.6.png) ### Features - Configurable output path diff --git a/example/SpineTest.spine b/example/SpineTest.spine index e53f61d..c7078e5 100644 Binary files a/example/SpineTest.spine and b/example/SpineTest.spine differ diff --git a/example/SpriteTest.aseprite b/example/SpriteTest.aseprite index 9b45f2c..f902a4b 100644 Binary files a/example/SpriteTest.aseprite and b/example/SpriteTest.aseprite differ diff --git a/example/SpriteTest.json b/example/SpriteTest.json index b26b11d..c76c8db 100644 --- a/example/SpriteTest.json +++ b/example/SpriteTest.json @@ -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 } } } }] } \ No newline at end of file +{ "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 } } } } } \ No newline at end of file diff --git a/media/showcase-v2.6.png b/media/showcase-v2.6.png new file mode 100644 index 0000000..dcaffe7 Binary files /dev/null and b/media/showcase-v2.6.png differ