More work on kara templater, misc. additions to Lua includes
Originally committed to SVN as r970.
This commit is contained in:
parent
88639cf70c
commit
fbe1aa65d2
3 changed files with 63 additions and 2 deletions
|
@ -42,10 +42,12 @@ include("karaskel.lua")
|
|||
|
||||
-- Find and parse/prepare all karaoke template lines
|
||||
function parse_templates(meta, styles, subs)
|
||||
local templates = { once = {}, line = {}, syl = {}, char = {}, furi = {} }
|
||||
for i = 1, #subs do
|
||||
local templates = { once = {}, line = {}, syl = {}, char = {}, furi = {}, styles = {} }
|
||||
local i = 1
|
||||
while i <= #subs do
|
||||
aegisub.progress.set((i-1) / #subs * 100)
|
||||
local l = subs[i]
|
||||
i = i + 1
|
||||
if l.class == "dialogue" and l.comment then
|
||||
local fx, mods = string.headtail(l.effect)
|
||||
fx = fx:lower()
|
||||
|
@ -54,6 +56,11 @@ function parse_templates(meta, styles, subs)
|
|||
elseif fx == "template" then
|
||||
parse_template(meta, styles, l, templates, mods)
|
||||
end
|
||||
templates.styles[l.style] = true
|
||||
elseif l.class == "dialogue" and l.effect == "fx" then
|
||||
-- this is a previously generated effect line, remove it
|
||||
i = i - 1
|
||||
subs.delete(i)
|
||||
end
|
||||
end
|
||||
aegisub.progress.set(100)
|
||||
|
@ -226,7 +233,48 @@ function apply_templates(meta, styles, subs, templates)
|
|||
|
||||
-- run all run-once code snippets
|
||||
for k, t in pairs(templates.once) do
|
||||
assert(t.code, "WTF, a 'once' template without code?")
|
||||
local f, err = loadstring(t.code, "template code once")
|
||||
if not f then
|
||||
aegisub.debug.out(2, "Failed to parse Lua code: %s\nCode that failed to parse: %s\n\n", err, t.code)
|
||||
else
|
||||
setfenv(f, tenv)
|
||||
local res, err = pcall(f)
|
||||
if not res then
|
||||
aegisub.debug.out(2, "Runtime error in template code: %s\nCode producing error: %s\n\n", err, t.code)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- start processing lines
|
||||
local i, n = 1, #subs
|
||||
while i < n do
|
||||
local l = subs[i]
|
||||
i = i + 1
|
||||
if l.class == "dialogue" and ((l.effect == "" and not l.comment) or (l.effect == "karaoke" and l.comment)) then
|
||||
-- make a karaoke source line off it
|
||||
l.comment = true
|
||||
l.effect = "karaoke"
|
||||
subs[i] = l
|
||||
-- and then run it through the templates
|
||||
apply_line(meta, styles, subs, l, templates, tenv)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function apply_line(meta, styles, subs, line, templates, tenv)
|
||||
-- apply all line templates
|
||||
for k, t in pairs(templates.line) do
|
||||
end
|
||||
-- loop over syllables
|
||||
for i = 0, line.karaoke.n do
|
||||
local syl = line.karaoke[i]
|
||||
-- apply syllable templates
|
||||
|
||||
-- apply character templates
|
||||
end
|
||||
-- loop over furigana
|
||||
for i = 1, line.furi.n do
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -103,6 +103,7 @@ function karaskel.preproc_line(subs, meta, styles, line)
|
|||
end
|
||||
|
||||
line.text_stripped = ""
|
||||
line.duration = line.end_time - line.start_time
|
||||
|
||||
local curx = 0
|
||||
local worksyl = { }
|
||||
|
@ -168,6 +169,7 @@ function karaskel.preproc_line(subs, meta, styles, line)
|
|||
worksyl.style = line.styleref
|
||||
|
||||
-- And add new data to worksyl
|
||||
worksyl.i = line.kara.n
|
||||
worksyl.text_stripped = syltext
|
||||
worksyl.width = aegisub.text_extents(line.styleref, syltext)
|
||||
curx = curx + aegisub.text_extents(line.styleref, prespace)
|
||||
|
|
|
@ -168,3 +168,14 @@ function clamp(val, min, max)
|
|||
return val
|
||||
end
|
||||
end
|
||||
|
||||
-- Interpolate between two numbers
|
||||
function interpolate(pct, min, max)
|
||||
if pct <= 0 then
|
||||
return min
|
||||
elseif pct >= 1 then
|
||||
return max
|
||||
else
|
||||
return pct * (max - min) + min
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue