From 67d261ab378fa9166ee6e0c31b7cb4e32a019925 Mon Sep 17 00:00:00 2001 From: garret Date: Sun, 25 Feb 2024 23:01:13 +0000 Subject: get rid of dependencycontrol bullshit there is no sense in me keeping it around when all it does is add faff to writing the script add useless noise to the filenames/paths and enforces its opinions upon me which i dont agree with and all for absolutely ZERO reason since i don't even have a feed in the first place if you want to take my scripts and package them into a dependencycontrol feed, you are more than welcome to do so, provided you comply with the terms of the licence. but your life is going to be a little bit harder i'm afraid, sorry about that. i will keep all the script_namespace, depctrl registration and such around for the time being (removing it is >effort) --- ctrl-c-ctrl-v.lua | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 ctrl-c-ctrl-v.lua (limited to 'ctrl-c-ctrl-v.lua') diff --git a/ctrl-c-ctrl-v.lua b/ctrl-c-ctrl-v.lua new file mode 100644 index 0000000..04c994d --- /dev/null +++ b/ctrl-c-ctrl-v.lua @@ -0,0 +1,90 @@ +script_name = "Consistency Assistant" +script_description = "ctrl-c ctrl-v and now ctrl-o" +script_version = "1.2.0" +script_author = "garret" +script_namespace = "garret.ctrl-c-ctrl-v" + +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 + +--inspect = require "inspect" + +-- it looks more complicated than it is because of all the aegisub.log()s +local function main(sub, is_recursion) + local clipboard = {} + for i = 1, #sub do + local line = sub[i] + if line.class == "dialogue" then + local op, name = line.effect:match("ctrl%-([cvo]) ?([%S]*)") + if op == "o" and parser ~= "nil" then -- o = open. check for parser or it wont work + clipboard["__imports"] = clipboard["__imports"] or {} -- declare field + clipboard["__imports"][name] = import(line.text) + elseif line.comment ~= true then + if op == "c" then + aegisub.log(5, 5, "ctrl-c " .. name .. ": " .. line.text .. "\n") + clipboard[name] = clipboard[name] or {} + table.insert(clipboard[name], line) + elseif op == "v" and is_recursion ~= true then -- don't want to affect the imported files (useless) + -- have to specifically check ~= true because normally it'd be sel, which is a table of numbers (not nil/false) + local file, slash, capture = name:match("([^%s/]+)(/?)([%S]*)") -- match filename/capture + local clippings -- names = anything not a space or a / + aegisub.log(5, file.."/"..capture.."\n") + aegisub.log(5, "slash: "..slash.."\n") + if slash ~= "" and parser ~= nil then + clippings = clipboard["__imports"][file][capture] + aegisub.log(5, "clippings = clipboard[\"__imports\"][\""..file.."\"][\""..capture.."\"]\n") + else + clippings = clipboard[file] or {line} -- error handling if the clipboard doesnt exist or parser isnt there + aegisub.log(5, "clippings = clipboard[\""..file.."\"]\n") + end + aegisub.log(5, "ctrl-v " .. name .. ": " .. line.text .. "\n") +-- aegisub.log(5, inspect(clippings).."\n") + line.text = clippings[1].text + sub[i] = line + table.remove(clippings, 1) + end + end + end + aegisub.progress.set(i / #sub * 100) + end +-- aegisub.log(5, inspect(clipboard).."\n") + return clipboard +end + +function import(path) +--local function import(path) + if parser then + aegisub.log(5, "recursing\n") + local f = io.open(aegisub.decode_path(path), "r") + local sub = parser.parse_file(f).events + f:close() + local clipboard = main(sub, true) + aegisub.log(5, "recursion complete\n") + return clipboard + else + aegisub.log(1, "You don't appear to have myaa.ASSParser, which is required for including other files.\n") + aegisub.log(1, "The script will continue, but any includes you've specified won't work.\n") + return {} + end +end + +if haveDepCtrl then + depctrl:registerMacro(main) +else + aegisub.register_macro(script_name, script_description, main) +end -- cgit v1.2.3-70-g09d2