Add looping support for line templates. Produce multiple whole lines here, instead of multiple copies of each syllable one after another on the same line.

Originally committed to SVN as r1553.
This commit is contained in:
Niels Martin Hansen 2007-09-03 13:39:03 +00:00
parent 62ded21ece
commit fda44c93a5

View file

@ -443,44 +443,48 @@ function apply_line(meta, styles, subs, line, templates, tenv)
-- Apply all line templates -- Apply all line templates
aegisub.debug.out(5, "Running line templates\n") aegisub.debug.out(5, "Running line templates\n")
for t in matching_templates(templates.line, line, tenv) do for t in matching_templates(templates.line, line, tenv) do
if t.code then tenv.j = 0
aegisub.debug.out(5, "Code template, %s\n", t.code) while tenv.j < t.loops do
tenv.line = line tenv.j = tenv.j + 1
run_code_template(t, tenv) if t.code then
else aegisub.debug.out(5, "Code template, %s\n", t.code)
aegisub.debug.out(5, "Line template, pre = '%s', t = '%s'\n", t.pre, t.t) tenv.line = line
applied_templates = true run_code_template(t, tenv)
local newline = table.copy(line) else
tenv.line = newline aegisub.debug.out(5, "Line template, pre = '%s', t = '%s'\n", t.pre, t.t)
newline.layer = t.layer applied_templates = true
newline.text = "" local newline = table.copy(line)
if t.pre ~= "" then tenv.line = newline
newline.text = newline.text .. run_text_template(t.pre, tenv, varctx) newline.layer = t.layer
end newline.text = ""
if t.t ~= "" then if t.pre ~= "" then
for i = 1, line.kara.n do newline.text = newline.text .. run_text_template(t.pre, tenv, varctx)
local syl = line.kara[i] end
tenv.syl = syl if t.t ~= "" then
set_ctx_syl(varctx, line, syl) for i = 1, line.kara.n do
newline.text = newline.text .. run_text_template(t.t, tenv, varctx) local syl = line.kara[i]
if t.addtext then tenv.syl = syl
if t.keeptags then set_ctx_syl(varctx, line, syl)
newline.text = newline.text .. syl.text newline.text = newline.text .. run_text_template(t.t, tenv, varctx)
else if t.addtext then
newline.text = newline.text .. syl.text_stripped if t.keeptags then
newline.text = newline.text .. syl.text
else
newline.text = newline.text .. syl.text_stripped
end
end end
end end
end
else
-- hmm, no main template for the line... put original text in
if t.keeptags then
newline.text = newline.text .. line.text
else else
newline.text = newline.text .. line.text_stripped -- hmm, no main template for the line... put original text in
if t.keeptags then
newline.text = newline.text .. line.text
else
newline.text = newline.text .. line.text_stripped
end
end end
newline.effect = "fx"
subs.append(newline)
end end
newline.effect = "fx"
subs.append(newline)
end end
end end
aegisub.debug.out(5, "Done running line templates\n\n") aegisub.debug.out(5, "Done running line templates\n\n")