-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReduce Frames.lua
More file actions
61 lines (52 loc) · 1.68 KB
/
Reduce Frames.lua
File metadata and controls
61 lines (52 loc) · 1.68 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
-- This example shows how to move the selected cels by a specific delta X/Y value.
local spr = app.activeSprite
if not spr then return app.alert "No active sprite" end
local dlg = Dialog()
function previewText(d)
local boxes = ""
for i = 1, 25 do
if i > d.offset and (i-d.offset) % d.step == 1 then
boxes = boxes .. "■"
else
boxes = boxes .. "□"
end
end
return boxes
end
dlg
:label{ id="help", label="", text="Set step size for deleting selected frames" }
:label{ id="frame_count", label="frames selected:", text=tostring(#app.range.frames) }
:separator{ }
:slider{
id="step",
label="Step size:",
value="2",
min="2",
max="20",
onchange=function()
dlg:modify { id="preview", text=previewText(dlg.data)}
end, focus=true }
:slider{ id="offset", label="Start offset:", value="0", min="0", max="10", onchange=function() dlg:modify { id="preview", text=previewText(dlg.data)} end }
:check{ id="update_duration", label="Update duration:", text="", selected=false }
:label{ id="preview", label="Delete Preview:", text=previewText(dlg.data) }
:button{ id="ok", text="&OK", focus=true }
:button{ text="&Cancel" }
:show()
local data = dlg.data
if not data.ok then return end
app.transaction(
function()
local frames = app.range.frames
local step = data.step
local offset = data.offset
-- delete from right to left
-- since left to right shifts everything over to the right after each delete
for i = #frames, 1, -1 do
if i > offset and (i-offset) % step == 1 then
spr:deleteFrame(frames[i]);
elseif data.update_duration then
frames[i].duration = frames[i].duration * step
end
end
end
)