forked from PKGaspi/AsepriteScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_combinations.lua
More file actions
173 lines (151 loc) · 4.88 KB
/
export_combinations.lua
File metadata and controls
173 lines (151 loc) · 4.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
--[[
Description: An Aseprite script to export all combinations of layers inside
groups.
Usage: Keep your layers organized in groups. For every group there is, only one
layer at a time will be exported, with one layer of every other group. All
possible combinations will be exported.
About: Made by Gaspi. Commissioned by AnomuraGame.
- Web: https://gaspi.games/
- Twitter: @_Gaspi
--]]
-- Import main.
local err = dofile("main.lua")
if err ~= 0 then return err end
-- Variable to keep track of number of current combination.
local combination = 0
local currently_visible_layers = {}
local function exportCombinations(sprite, g, output_path, data)
if #g == 0 then
-- os.execute("mkdir \"" .. Dirname(output_path) .. "\"")
local combination_text = table.concat(currently_visible_layers, "-")
local filename = output_path:gsub("{combination}", combination_text)
if data.spritesheet then
app.command.ExportSpriteSheet{
ui=false,
askOverwrite=false,
type=SpriteSheetType.HORIZONTAL,
columns=0,
rows=0,
width=0,
height=0,
bestFit=false,
textureFilename=filename,
dataFilename="",
dataFormat=SpriteSheetDataFormat.JSON_HASH,
borderPadding=0,
shapePadding=0,
innerPadding=0,
trim=data.trim,
mergeDuplicates=data.mergeDuplicates,
extrude=false,
openGenerated=false,
layer="",
tag="",
splitLayers=false,
listLayers=layer,
listTags=true,
listSlices=true,
}
else
sprite:saveCopyAs(filename)
end
combination = combination + 1
return
end
local groups = CopyTable(g)
-- Ignore isolated layers
while groups[1] ~= nil and not groups[1].isGroup do
table.remove(groups, 1)
end
if groups[1] == nil then return end
local changing_group = groups[1]
table.remove(groups, 1)
for _, layer in ipairs(changing_group.layers) do
layer.isVisible = true
local idx = table.insert(currently_visible_layers, layer.name)
exportCombinations(sprite, groups, output_path, data)
layer.isVisible = false
table.remove(currently_visible_layers, idx)
end
end
-- Open main dialog.
local dlg = Dialog("Export combinations")
dlg:file{
id = "directory",
label = "Output directory:",
filename = Sprite.filename,
open = false
}
dlg:entry{
id = "filename",
label = "File name format:",
text = "{spritename}_{combination}"
}
dlg:combobox{
id = 'format',
label = 'Export Format:',
option = 'png',
options = {'png', 'gif', 'jpg'}
}
dlg:slider{id = 'scale', label = 'Export Scale:', min = 1, max = 10, value = 1}
dlg:check{
id = "spritesheet",
label = "Export as spritesheet:",
selected = false,
onclick = function()
-- Show this options only if spritesheet is checked.
dlg:modify{
id = "trim",
visible = dlg.data.spritesheet
}
dlg:modify{
id = "mergeDuplicates",
visible = dlg.data.spritesheet
}
end
}
dlg:check{
id = "trim",
label = " Trim:",
selected = false,
visible = false
}
dlg:check{
id = "mergeDuplicates",
label = " Merge duplicates:",
selected = false,
visible = false
}
dlg:check{id = "save", label = "Save sprite:", selected = false}
dlg:button{id = "ok", text = "Export"}
dlg:button{id = "cancel", text = "Cancel", onclick = function() dlg:close() end}
dlg:show()
if not dlg.data.ok then return 0 end
-- Get path and filename
local output_path = Dirname(dlg.data.directory)
local filename = dlg.data.filename
if output_path == nil then
local dlg = MsgDialog("Error", "No output directory was specified.")
dlg:show()
return 1
end
if not string.find(filename, "{combination}") then
-- combination format is mandatory. Append to string.
filename = filename .. "_{combination}"
end
filename = filename:gsub("{spritename}",
RemoveExtension(Basename(Sprite.filename)))
filename = filename .. '.' .. dlg.data.format
-- Finally, perform everything.
Sprite:resize(Sprite.width * dlg.data.scale, Sprite.height * dlg.data.scale)
local layers_visibility_data = HideLayers(Sprite)
exportCombinations(Sprite, Sprite.layers, output_path .. filename, dlg.data)
RestoreLayersVisibility(Sprite, layers_visibility_data)
Sprite:resize(Sprite.width / dlg.data.scale, Sprite.height / dlg.data.scale)
-- Save the original file if specified
if dlg.data.save then Sprite:saveAs(dlg.data.directory) end
-- Success dialog.
local dlg =
MsgDialog("Success!", "Exported " .. combination .. " combinations.")
dlg:show()
return 0