forked from TypesettingTools/Myaamori-Aegisub-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
myaa.Bear.moon
218 lines (188 loc) · 7.42 KB
/
myaa.Bear.moon
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
export script_name = "Bear"
export script_description = "Stuff for Bear^4"
export script_version = "0.0.1"
export script_author = "Myaamori"
export script_namespace = "myaa.Bear"
DependencyControl = require 'l0.DependencyControl'
depctrl = DependencyControl {
{
{"l0.Functional", version: "0.6.0", url: "https://github.com/TypesettingTools/Functional",
feed: "https://raw.githubusercontent.com/TypesettingTools/Functional/master/DependencyControl.json"}
{"a-mo.LineCollection", version: "1.3.0", url: "https://github.com/TypesettingTools/Aegisub-Motion",
feed: "https://raw.githubusercontent.com/TypesettingTools/Aegisub-Motion/DepCtrl/DependencyControl.json"},
{"a-mo.Line", version: "1.5.3", url: "https://github.com/TypesettingTools/Aegisub-Motion",
feed: "https://raw.githubusercontent.com/TypesettingTools/Aegisub-Motion/DepCtrl/DependencyControl.json"},
{"l0.ASSFoundation", version: "0.5.0", url: "https://github.com/TypesettingTools/ASSFoundation",
feed: "https://raw.githubusercontent.com/TypesettingTools/ASSFoundation/master/DependencyControl.json"},
{"a-mo.ConfigHandler", version: "1.1.4", url: "https://github.com/TypesettingTools/Aegisub-Motion",
feed: "https://raw.githubusercontent.com/TypesettingTools/Aegisub-Motion/DepCtrl/DependencyControl.json"},
}
}
F, LineCollection, Line, ASS, ConfigHandler = depctrl\requireModules!
findall = (s, c) ->
indices = {}
for i = 1, #s
if s\sub(i, i) == c
table.insert indices, i
return indices
process = (sub, sel, result) ->
lines = LineCollection sub, sel
start_angle = result.startAngle
end_angle = result.finalAngle
start_blur = result.startBlur
end_blur = result.finalBlur
accel = result.gravity
bounces = result.bounces
bounce_size = result.bounceHeight
anim_duration = result.charAnimDuration
delay = result.animDelay
blur_intact = result.leaveBlur
lines_added = 0
lines\runCallback ((lines, line, i) ->
ass = ASS\parse line
line\getPropertiesFromStyle!
str = ass\copy!\stripTags!\getString!
copy = ass\copy!
end_time = line.start_time + delay * (#str - 1) + anim_duration
for j, charline in ipairs ass\splitAtIntervals 1, 4, true
charass = charline.ASS
start_frame = aegisub.frame_from_ms charline.start_time
end_frame = aegisub.frame_from_ms end_time
pos = charass\getPosition!
for frame = start_frame, end_frame + 1
cur_time = aegisub.ms_from_frame(frame) - charline.start_time
p = math.max(0, math.min(1, (cur_time - delay * (j - 1)) / anim_duration))
if p <= 0
continue
curve = p * bounces * math.pi
init_p = math.max(0, math.min(1, p * bounces * 2))
copy = Line charline, lines
copy.start_time = aegisub.ms_from_frame frame
if p >= 1
copy.end_time = line.end_time
else
copy.end_time = aegisub.ms_from_frame (frame + 1)
copy\interpolateTransforms cur_time
copyass = ASS\parse copy
angle = ASS\createTag "angle", (1 - init_p) * start_angle + init_p * end_angle
alpha = ASS\createTag "alpha", (1 - init_p) * 255 + init_p * 0
pos = copyass\getPosition!
pos\add 0, -bounce_size * math.abs(math.sin(curve)) * math.pow((1 - p), accel)
tags = {pos, angle, alpha}
blurtags = copyass\getTags {"blur"}
if #blurtags == 0 or not blur_intact
blur = ASS\createTag "blur", (1 - init_p) * start_blur + init_p * end_blur
table.insert tags, blur
copyass\replaceTags tags
copyass\commit!
lines_added += 1
lines\addLine copy, nil, true, line.number + lines_added
if p >= 1
break
line.comment = true
), true
lines\replaceLines!
lines\insertLines!
return lines\getSelection!
dialog = {
main: {
animDelayLabel: {
class: "label", label: "Animation start delay:",
x: 0, y: 0, width: 1, height: 1
},
animDelay: {
class: "intedit",
value: 20, config: true, min: 1,
x: 1, y: 0, width: 1, height: 1, hint: "The gap in time of the start of the animation between each character (ms)"
},
charAnimDurationLabel: {
class: "label", label: "Character animation duration:",
x: 0, y: 1, width: 1, height: 1
},
charAnimDuration: {
class: "intedit",
value: 500, config: true, min: 0,
x: 1, y: 1, width: 1, height: 1, hint: "The duration of the animation for each character (ms)"
},
startAngleLabel: {
class: "label", label: "Start angle:",
x: 0, y: 2, width: 1, height: 1
},
startAngle: {
class: "floatedit",
value: 15, config: true,
x: 1, y: 2, width: 1, height: 1, hint: "The initial angle of each character (degrees)"
},
finalAngleLabel: {
class: "label", label: "Final angle:",
x: 0, y: 3, width: 1, height: 1
},
finalAngle: {
class: "floatedit",
value: 0, config: true,
x: 1, y: 3, width: 1, height: 1, hint: "The final angle of each character (degrees)"
},
startBlurLabel: {
class: "label", label: "Start blur:",
x: 0, y: 4, width: 1, height: 1
},
startBlur: {
class: "floatedit",
value: 3, config: true,
x: 1, y: 4, width: 1, height: 1, hint: "The initial blur of each character"
},
finalBlurLabel: {
class: "label", label: "Final blur:",
x: 0, y: 5, width: 1, height: 1
},
finalBlur: {
class: "floatedit",
value: 1, config: true,
x: 1, y: 5, width: 1, height: 1, hint: "The final blur of each character"
},
leaveBlur: {
class: "checkbox", label: "Don't overwrite blur",
value: true, config: true,
x: 0, y: 6, width: 2, height: 1, hint: "Leaves the blur intact if already specified on the line"
},
bouncesLabel: {
class: "label", label: "Bounces:",
x: 0, y: 7, width: 1, height: 1
},
bounces: {
class: "intedit",
value: 2, config: true, min: 1,
x: 1, y: 7, width: 1, height: 1, hint: "The number of times each character should bounce"
},
bounceHeightLabel: {
class: "label", label: "Bounce height:",
x: 0, y: 8, width: 1, height: 1
},
bounceHeight: {
class: "intedit",
value: 30, config: true, min: 1,
x: 1, y: 8, width: 1, height: 1, hint: "The height of the bounces"
},
gravityLabel: {
class: "label", label: "Gravity:",
x: 0, y: 9, width: 1, height: 1
},
gravity: {
class: "floatedit",
value: 1.2, config: true, min: 0,
x: 1, y: 9, width: 1, height: 1, hint: "How quickly the bounce height should decrease (1 = linear, 0 = no decrease)"
},
}
}
show_dialog = (sub, sel) ->
options = ConfigHandler dialog, depctrl.configFile, false, script_version, depctrl.configDig
options\read!
options\updateInterface "main"
button, result = aegisub.dialog.display dialog.main
if button
options\updateConfiguration result, "main"
options\write!
return process sub, sel, result
depctrl\registerMacros {
{"Make next episode title", "", show_dialog}
}