Skip to content

Commit

Permalink
KaraTemplater: Fold generated output
Browse files Browse the repository at this point in the history
  • Loading branch information
petzku committed Apr 21, 2023
1 parent 0533423 commit c205594
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/0x.KaraTemplater.moon
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,37 @@ apply_templates = (subs, lines, components, tenv) ->
tenv.orgline = nil
aegisub.progress.set 100 * i / #lines

fold_output = (subs) ->
parse_line_fold = (line) ->
return if not line.extra

info = line.extra["_aegi_folddata"]
return if not info

side, collapsed, id = info\match "^(%d+);(%d+);(%d+)$"
return {:side, :collapsed, :id}

-- find a free fold ID to use
maxid = 0
for i, line in ipairs subs
fold = parse_line_fold line
maxid = math.max(maxid, fold.id or 0) if fold

-- find first and last lines of output
local firstfx, lastfx, fr, to
for i, line in ipairs subs
continue unless line.effect and line.effect == "fx"
fr, firstfx = i, line if not firstfx
to, lastfx = i, line

-- generate fold between the two
firstfx.extra or= {}
lastfx.extra or= {}
firstfx.extra["_aegi_folddata"] = "0;1;#{maxid+1}"
lastfx.extra["_aegi_folddata"] = "1;1;#{maxid+1}"
subs[fr] = firstfx
subs[to] = lastfx

-- Entry point
main = (subs, sel, active) ->
math.randomseed os.time!
Expand Down Expand Up @@ -1006,6 +1037,9 @@ main = (subs, sel, active) ->
task 'Applying templates...'
apply_templates subs, lines, components, tenv

task 'Folding output...'
fold_output subs

aegisub.set_undo_point 'apply karaoke template'

remove_fx_main = (subs, _sel, _active) ->
Expand Down

0 comments on commit c205594

Please sign in to comment.