-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathzah.clipmove.lua
53 lines (42 loc) · 1.74 KB
/
zah.clipmove.lua
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
--If you have a \move tag and rectangular \clip tag in the same line, running this will make the same movement on the clip.
script_name = "Transform clip from move"
script_description = "Use move tag in the line to transform rect clip"
script_author = "Zahuczky"
script_version = "1.0.0"
function ugoke(sub, sel, act)
for si,li in ipairs(sel) do
line = sub[li]
--parse move from line
local move = line.text:match("\\move%(([^%)]+)%)")
if move then
x1, y1, x2, y2, t1, t2 = move:match("(-?[0-9.]+),+(-?[0-9.]+),+(-?[0-9.]+),+(-?[0-9.]+),+(-?[0-9.]+),+(-?[0-9.]+)")
x1 = tonumber(x1)
y1 = tonumber(y1)
x2 = tonumber(x2)
y2 = tonumber(y2)
t1 = tonumber(t1)
t2 = tonumber(t2)
else
aegisub.log("No move tag found in line.")
aegisub.cancel()
end
--parse rectangular clip from line
local clip = line.text:match("\\clip%(([^%)]+)%)")
if clip then
x1c, y1c, x2c, y2c = clip:match("(-?[0-9.]+),+(-?[0-9.]+),+(-?[0-9.]+),+(-?[0-9.]+)")
x1c = tonumber(x1c)
y1c = tonumber(y1c)
x2c = tonumber(x2c)
y2c = tonumber(y2c)
else
aegisub.log("No rectangular clip found in line.")
aegisub.cancel()
end
local xmove = x2 - x1
local ymove = y2 - y1
local transform = "\\t(" .. t1 .. "," .. t2 .. ",\\clip(" .. x1c + xmove .. "," .. y1c + ymove .. "," .. x2c + xmove .. "," .. y2c + ymove .. "))"
line.text = line.text:gsub("(\\clip%(([^%)]+)%))", "%1"..transform)
sub[li] = line
end
end
aegisub.register_macro(script_name, script_description, ugoke)