From 8074e6ddb06899a3f359fd8db47a70133471829b Mon Sep 17 00:00:00 2001 From: garret Date: Sun, 17 Nov 2024 01:28:33 +0000 Subject: mark the shenanigans proof-of-concept as such --- shenanigans-poc.lua | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++ shenanigans.lua | 81 ----------------------------------------------------- 2 files changed, 81 insertions(+), 81 deletions(-) create mode 100644 shenanigans-poc.lua delete mode 100644 shenanigans.lua diff --git a/shenanigans-poc.lua b/shenanigans-poc.lua new file mode 100644 index 0000000..bce22fc --- /dev/null +++ b/shenanigans-poc.lua @@ -0,0 +1,81 @@ +script_name = "Import Shenanigans" +script_description = "imports shenanigans" +script_author = "garret" +script_version = "0.1.1" +script_namespace = "garret.shenanigans" + +local SHENAN_PATTERN = "shenan ([^;]*)" + +local haveDepCtrl, DependencyControl, depctrl = pcall(require, "l0.DependencyControl") +local parser +if haveDepCtrl then + depctrl = DependencyControl({ + --feed="TODO", + { + { + "myaa.ASSParser", + version = "0.0.4", -- very sketch about this + url = "http://github.com/TypesettingTools/Myaamori-Aegisub-Scripts", + feed = "https://raw.githubusercontent.com/TypesettingTools/Myaamori-Aegisub-Scripts/master/DependencyControl.json", + optional = true, + }, + }, + }) + parser = depctrl:requireModules() +end + +local function main(sub) + local imports = {} + local i = 1 + + -- using a while/repeat until loop instead of a for here, so i can fuck around with the number + -- i do this to skip past shenanigans that've already been added without deleting them + + repeat + local line = sub[i] + if line.class == "dialogue" then + if line.effect == "import" then + local f = io.open(aegisub.decode_path(line.text), "r") + local imported_sub = parser.parse_file(f).events + f:close() + + for _, imported_line in ipairs(imported_sub) do + if imported_line.class == "dialogue" then + local name = imported_line.effect:match(SHENAN_PATTERN) + if name then + imports[name] = imports[name] or {} -- declare if not present + table.insert(imports[name], imported_line) + end + end + end + elseif line.effect ~= "" then + aegisub.log(5, i..": has effect: "..line.effect) + local name = line.effect:match(SHENAN_PATTERN) + local shenans = imports[name] + if shenans == nil then + + elseif shenans ~= "done" then + for idx, val in ipairs(shenans) do + sub.insert(i + idx, val) + end + sub.delete(sub, i) + i = i + #shenans - 1 + imports[name] = "done" + elseif shenans == "done" then + aegisub.log(5, "deleting "..line.text) + sub.delete(sub, i) + i = i - 1 -- the next line has now moved up 1, so we need to move up 1 as well + -- something about 2 hard problems + end + end + end + if i >= #sub then i = #sub end -- otherwise you can get out of range errors + i = i + 1 + until i == #sub + 1 +end + +if haveDepCtrl then + depctrl:registerMacro(main) +else + aegisub.register_macro(script_name, script_description, main) +end diff --git a/shenanigans.lua b/shenanigans.lua deleted file mode 100644 index bce22fc..0000000 --- a/shenanigans.lua +++ /dev/null @@ -1,81 +0,0 @@ -script_name = "Import Shenanigans" -script_description = "imports shenanigans" -script_author = "garret" -script_version = "0.1.1" -script_namespace = "garret.shenanigans" - -local SHENAN_PATTERN = "shenan ([^;]*)" - -local haveDepCtrl, DependencyControl, depctrl = pcall(require, "l0.DependencyControl") -local parser -if haveDepCtrl then - depctrl = DependencyControl({ - --feed="TODO", - { - { - "myaa.ASSParser", - version = "0.0.4", -- very sketch about this - url = "http://github.com/TypesettingTools/Myaamori-Aegisub-Scripts", - feed = "https://raw.githubusercontent.com/TypesettingTools/Myaamori-Aegisub-Scripts/master/DependencyControl.json", - optional = true, - }, - }, - }) - parser = depctrl:requireModules() -end - -local function main(sub) - local imports = {} - local i = 1 - - -- using a while/repeat until loop instead of a for here, so i can fuck around with the number - -- i do this to skip past shenanigans that've already been added without deleting them - - repeat - local line = sub[i] - if line.class == "dialogue" then - if line.effect == "import" then - local f = io.open(aegisub.decode_path(line.text), "r") - local imported_sub = parser.parse_file(f).events - f:close() - - for _, imported_line in ipairs(imported_sub) do - if imported_line.class == "dialogue" then - local name = imported_line.effect:match(SHENAN_PATTERN) - if name then - imports[name] = imports[name] or {} -- declare if not present - table.insert(imports[name], imported_line) - end - end - end - elseif line.effect ~= "" then - aegisub.log(5, i..": has effect: "..line.effect) - local name = line.effect:match(SHENAN_PATTERN) - local shenans = imports[name] - if shenans == nil then - - elseif shenans ~= "done" then - for idx, val in ipairs(shenans) do - sub.insert(i + idx, val) - end - sub.delete(sub, i) - i = i + #shenans - 1 - imports[name] = "done" - elseif shenans == "done" then - aegisub.log(5, "deleting "..line.text) - sub.delete(sub, i) - i = i - 1 -- the next line has now moved up 1, so we need to move up 1 as well - -- something about 2 hard problems - end - end - end - if i >= #sub then i = #sub end -- otherwise you can get out of range errors - i = i + 1 - until i == #sub + 1 -end - -if haveDepCtrl then - depctrl:registerMacro(main) -else - aegisub.register_macro(script_name, script_description, main) -end -- cgit v1.2.3-70-g09d2