From a85c477e0895705e2898cdf4045e11b547995c27 Mon Sep 17 00:00:00 2001 From: odrling Date: Fri, 2 Aug 2019 22:14:28 +0200 Subject: [PATCH] [duetto-meika] dos2unix (sorry that was bugging me) --- duetto-meika.lua | 114 +++++++++++++++++++++++------------------------ 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/duetto-meika.lua b/duetto-meika.lua index 4d2d430..50cf6e5 100644 --- a/duetto-meika.lua +++ b/duetto-meika.lua @@ -1,57 +1,57 @@ -local tr = aegisub.gettext - -script_name = tr"DUETTO MEIKA" -script_description = tr"changes the styles of a line where there is a marker" -script_author = "amoethyst" - -function duetto(subs, sel) - styles = {} - - -- create the style map - for _, line in ipairs(subs) do - if line.class == "style" then - styles[line.name] = line - end - end - - -- duetto~ - for _, i in ipairs(sel) do - line = subs[i] - - current_style = styles[line.style] - -- match every `s:` marker - for style_name in line.text:gmatch("{s:([^}]*)}") do - if style_name ~= current_style.name then - - style = styles[style_name] - -- build the tags to use the new style - style_string = "{" - if current_style.color1 ~= style.color1 then - style_string = style_string .. "\\c" .. style.color1 - end - if current_style.color2 ~= style.color2 then - style_string = style_string .. "\\2c" .. style.color2 - end - if current_style.color3 ~= style.color3 then - style_string = style_string .. "\\3c" .. style.color3 - end - if current_style.color4 ~= style.color4 then - style_string = style_string .. "\\4c" .. style.color4 - end - style_string = style_string .. "}" - - -- set style - line.text = line.text:gsub("{s:" .. style_name .. "}", style_string, 1) - current_style = style - else - -- remove marker to not break everything - line.text = line.text:gsub("{s:" .. style_name .. "}", "", 1) - end - end - subs[i] = line - end - - aegisub.set_undo_point(script_name) -end - -aegisub.register_macro(script_name, script_description, duetto) +local tr = aegisub.gettext + +script_name = tr"DUETTO MEIKA" +script_description = tr"changes the styles of a line where there is a marker" +script_author = "amoethyst" + +function duetto(subs, sel) + styles = {} + + -- create the style map + for _, line in ipairs(subs) do + if line.class == "style" then + styles[line.name] = line + end + end + + -- duetto~ + for _, i in ipairs(sel) do + line = subs[i] + + current_style = styles[line.style] + -- match every `s:` marker + for style_name in line.text:gmatch("{s:([^}]*)}") do + if style_name ~= current_style.name then + + style = styles[style_name] + -- build the tags to use the new style + style_string = "{" + if current_style.color1 ~= style.color1 then + style_string = style_string .. "\\c" .. style.color1 + end + if current_style.color2 ~= style.color2 then + style_string = style_string .. "\\2c" .. style.color2 + end + if current_style.color3 ~= style.color3 then + style_string = style_string .. "\\3c" .. style.color3 + end + if current_style.color4 ~= style.color4 then + style_string = style_string .. "\\4c" .. style.color4 + end + style_string = style_string .. "}" + + -- set style + line.text = line.text:gsub("{s:" .. style_name .. "}", style_string, 1) + current_style = style + else + -- remove marker to not break everything + line.text = line.text:gsub("{s:" .. style_name .. "}", "", 1) + end + end + subs[i] = line + end + + aegisub.set_undo_point(script_name) +end + +aegisub.register_macro(script_name, script_description, duetto)