aboutsummaryrefslogtreecommitdiffstats
path: root/macros/garret.a-b.lua
blob: b57b4f815a15f85e121586a7933f383eb65b4100 (plain) (blame)
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
script_name = "A-B"
script_description = "makes checking pre-timing possible."
script_author = "garret"
script_version = "3.0.0"
script_namespace = "garret.a-b"

local haveDepCtrl, DependencyControl, depctrl = pcall(require, "l0.DependencyControl")
if haveDepCtrl then
    depctrl = DependencyControl {
        --feed="TODO",
    }
end

local function switch_indicator(i)
    if i == "a" then
        return "b"
    elseif i == "b" then
        return "a"
    end
end

local function strip_tags(text)
    return text:gsub("{[^}]-}","")
end

local function get_indicator(letter, actor)
    local indicator
    if actor == "" then
        indicator = letter
    else
    indicator = actor.." "..letter
    end
    return indicator
end

local function main(sub, sel)
    local i = "a"
    for _,li in ipairs(sel) do
        local line = sub[li]
        local indicator = get_indicator(i, line.actor)

        if line.text == "" then
            line.text = indicator
        elseif strip_tags(line.text) == "" then
            line.text = line.text .. indicator -- apply tags
        end

        sub[li] = line
        i = switch_indicator(i)
    end
    aegisub.set_undo_point(script_name)
end

if haveDepCtrl then
    depctrl:registerMacro(main)
else
    aegisub.register_macro(script_name, script_description, main)
end