-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkristal_export.lua
More file actions
74 lines (68 loc) · 1.73 KB
/
kristal_export.lua
File metadata and controls
74 lines (68 loc) · 1.73 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
local function exportFrame(sprite, frame_n, output)
local tempsprite = Sprite(sprite)
repeat
if frame_n == 1 then
tempsprite:deleteFrame(2)
else
tempsprite:deleteFrame(1)
frame_n = frame_n - 1
end
until #tempsprite.frames == 1
-- sanity check (trust me it's more annoying with out this)
if #tempsprite.frames ~= 1 then
tempsprite:close()
error("More than one frame left somehow?")
end
tempsprite:saveCopyAs(output)
tempsprite:close()
end
local function export(sprite, directory)
for _, tag in ipairs(sprite.tags) do
local count = 1
if tag.aniDir ~= AniDir.REVERSE then
for j=tag.fromFrame.frameNumber,tag.toFrame.frameNumber do
local file_name = tag.name .. "_" .. count .. ".png"
count = count + 1
exportFrame(sprite, j, directory .. file_name)
end
end
if tag.aniDir == AniDir.PING_PONG or tag.aniDir == AniDir.PING_PONG_REVERSE or tag.aniDir == AniDir.REVERSE then
for j=tag.toFrame.frameNumber,tag.fromFrame.frameNumber,-1 do
local file_name = tag.name .. "_" .. count .. ".png"
count = count + 1
exportFrame(sprite, j, directory .. file_name)
end
end
end
end
local function dirname(str)
return str:match("(.*[/\\])")
end
if #app.sprite.tags == 0 then
local dlg = Dialog{ title = "Error!" }
dlg:label{text = "Need at least one tag in order to export!"}
dlg:button{
text="OK", onclick=function()
dlg:close()
end, focus = true}
dlg:show()
return
end
local dlg = Dialog()
dlg:entry{ id="target_dir",
label="Target Directory",
text=dirname(app.sprite.filename)}
dlg:button {
text="Start",
onclick=function()
export(app.sprite, dlg.data.target_dir)
dlg:close()
end
}
dlg:button {
text="Cancel",
onclick=function()
dlg:close()
end
}
dlg:show{ wait=false }