@@ -37,6 +37,16 @@ function Export(activeSprite, rootLayer, fileName, fileNameTemplate, dlgData)
37
37
ExportSpineJsonStart (fileName , dlgData )
38
38
end
39
39
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
+
40
50
ExportSpriteLayers (activeSprite , rootLayer , fileName , fileNameTemplate , dlgData )
41
51
42
52
if dlgData .exportSpineSheet == true then
@@ -49,42 +59,44 @@ function ExportSpriteLayers(activeSprite, rootLayer, fileName, fileNameTemplate,
49
59
local _fileNameTemplate = fileNameTemplate
50
60
local layerName = layer .name
51
61
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
55
66
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
61
70
62
- layer .isVisible = previousVisibility
63
- else
64
- layer .isVisible = true
71
+ ExportSpriteLayers (activeSprite , layer , fileName , _fileNameTemplate , dlgData )
65
72
66
- local layerParentName
67
- if pcall (function () layerParentName = layer .parent .name end ) then
68
- _fileNameTemplate = _fileNameTemplate :gsub (" {layergroup}" , layerParentName )
73
+ layer .isVisible = previousVisibility
69
74
else
70
- _fileNameTemplate = _fileNameTemplate :gsub (" {layergroup}" , " default" )
71
- end
72
-
73
- _fileNameTemplate = _fileNameTemplate :gsub (" {layername}" , layerName )
75
+ layer .isVisible = true
74
76
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" )
78
82
end
79
83
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
82
96
end
83
97
84
- LayerCount = LayerCount + 1
98
+ layer . isVisible = false
85
99
end
86
-
87
- layer .isVisible = false
88
100
end
89
101
end
90
102
end
@@ -139,8 +151,21 @@ function ExportSpineJsonParse(activeSprite, layer, fileNameTemplate, dlgData)
139
151
local realPostionX = layerCelX + layerCelWidth / 2
140
152
local realPositionY = layerCelY + layerCelHeight / 2
141
153
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
144
169
145
170
if dlgData .groupsAsSkins == true then
146
171
fileNameTemplate = fileNameTemplate :gsub (" \\ " , " /" )
@@ -341,9 +366,13 @@ dlg:check{
341
366
}
342
367
dlg :check {
343
368
id = " setRootPostion" ,
344
- label = " Set Root position" ,
369
+ label = " Set Root position: " ,
345
370
selected = true ,
346
371
onclick = function ()
372
+ dlg :modify {
373
+ id = " rootPostionMethod" ,
374
+ visible = dlg .data .setRootPostion
375
+ }
347
376
dlg :modify {
348
377
id = " rootPositionX" ,
349
378
visible = dlg .data .setRootPostion
@@ -354,17 +383,35 @@ dlg:check{
354
383
}
355
384
end
356
385
}
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
+ }
357
402
dlg :number {
358
403
id = " rootPositionX" ,
359
- label = " Root Postion X:" ,
404
+ label = " Root Postion X:" ,
360
405
text = " 0" ,
361
- decimals = 0
406
+ decimals = 0 ,
407
+ visible = false
362
408
}
363
409
dlg :number {
364
410
id = " rootPositionY" ,
365
- label = " Root Postion Y:" ,
411
+ label = " Root Postion Y:" ,
366
412
text = " 0" ,
367
- decimals = 0
413
+ decimals = 0 ,
414
+ visible = false
368
415
}
369
416
dlg :separator {
370
417
id = " separator4" ,
@@ -444,7 +491,7 @@ dlg:button{id = "confirm", text = "Confirm"}
444
491
dlg :button {id = " cancel" , text = " Cancel" }
445
492
dlg :show ()
446
493
447
- if not dlg .data .confirm then
494
+ if not dlg .data .confirm then
448
495
app .alert (" Settings were not confirmed, script aborted." )
449
496
return
450
497
end
0 commit comments