From 391242d5b1df9b92801eb7d71020e269aa449568 Mon Sep 17 00:00:00 2001 From: Ghegghe Date: Mon, 15 May 2023 18:40:54 +0200 Subject: [PATCH 01/15] add remove text function in script cleanup --- ua.ScriptCleanup.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ua.ScriptCleanup.lua b/ua.ScriptCleanup.lua index a5b5903..d0b0fa2 100644 --- a/ua.ScriptCleanup.lua +++ b/ua.ScriptCleanup.lua @@ -153,6 +153,11 @@ function cleanlines(subs,sel) if res.ctrans then text=text:gsub(ATAG,function(tg) return cleantr(tg) end) end if res.inline2 then repeat text,r=text:gsub("(.)"..ATAG.."(.-{%*?\\)","%1%2") until r==0 elseif res.inline then text=text:gsub("(.)"..ATAG,"%1") end + if res.text then + text=text:gsub("^.-{","{") + text=text:gsub("}.-{","}{") + text=text:gsub("}([^}]+)$","}") + end if res.alphacol then text=text @@ -672,8 +677,9 @@ GUI={ {x=3,y=10,class="checkbox",name="nostyle2",label="Except Def.",hint="Delete unused styles except Default"}, {x=2,y=11,class="checkbox",name="inline",label="Remove inline tags"}, {x=3,y=11,class="checkbox",name="inline2",label="Except last",hint="Remove inline tags except the last one"}, -{x=2,y=12,width=2,class="checkbox",name="nocom",label="Remove comments from lines",hint="Removes {comments} (not tags)"}, -{x=2,y=13,width=2,class="checkbox",name="notag",label="Remove all {\\tags} from selected lines"}, +{x=2,y=12,class="checkbox",name="text",label="Remove text"}, +{x=2,y=13,width=2,class="checkbox",name="nocom",label="Remove comments from lines",hint="Removes {comments} (not tags)"}, +{x=2,y=14,width=2,class="checkbox",name="notag",label="Remove all {\\tags} from selected lines"}, {x=4,y=0,height=14,class="label",label="| \n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|"}, From e2ab0bdde8377c4c9904e29875b152f82a4236d9 Mon Sep 17 00:00:00 2001 From: Ghegghe Date: Mon, 12 Jun 2023 22:54:34 +0200 Subject: [PATCH 02/15] add p tag in tag selection --- ua.ScriptCleanup.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ua.ScriptCleanup.lua b/ua.ScriptCleanup.lua index d0b0fa2..cbe2ed5 100644 --- a/ua.ScriptCleanup.lua +++ b/ua.ScriptCleanup.lua @@ -315,6 +315,7 @@ function killemall(subs,sel) if res.anna then trgt=killtag("an",trgt) end if res.align then trgt=killtag("a",trgt) end if res.wrap then trgt=killtag("q",trgt) end + if res.mask then trgt=killtag("p",trgt) end if res["return"] then trgt=trgt:gsub("\\r.+([\\}])","%1") end if res.kara then trgt=trgt:gsub("\\[Kk][fo]?[%d%.]+([\\}])","%1") end if res.ital then repeat trgt,r=trgt:gsub("\\i[01]?([\\}])","%1") until r==0 end @@ -681,7 +682,7 @@ GUI={ {x=2,y=13,width=2,class="checkbox",name="nocom",label="Remove comments from lines",hint="Removes {comments} (not tags)"}, {x=2,y=14,width=2,class="checkbox",name="notag",label="Remove all {\\tags} from selected lines"}, -{x=4,y=0,height=14,class="label",label="| \n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|"}, +{x=4,y=0,height=15,class="label",label="| \n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|"}, {x=5,y=0,class="checkbox",name="skill",label="[start]",value=true}, {x=6,y=0,class="checkbox",name="ikill",label="[inline]",value=true,hint="only kill, not hide"}, @@ -701,6 +702,7 @@ GUI={ {x=5,y=11,class="checkbox",name="under",label="u"}, {x=5,y=12,class="checkbox",name="stri",label="s"}, {x=5,y=13,class="checkbox",name="wrap",label="q"}, +{x=5,y=14,class="checkbox",name="mask",label="p"}, {x=6,y=1,class="checkbox",name="bee",label="be"}, {x=6,y=2,class="checkbox",name="color1",label="c, 1c"}, From a481add820ebe1dc63f9a782e1b45570f74cdc7b Mon Sep 17 00:00:00 2001 From: Ghegghe Date: Sat, 24 Jun 2023 01:11:20 +0200 Subject: [PATCH 03/15] add teleport function without rounding mask --- ua.Relocator.lua | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/ua.Relocator.lua b/ua.Relocator.lua index 2e6a95d..fe27904 100644 --- a/ua.Relocator.lua +++ b/ua.Relocator.lua @@ -5,12 +5,12 @@ script_name="Hyperdimensional Relocator" script_description="Advanced metamorphosis of multidimensional coordinates" script_author="reanimated" script_url="http://unanimated.hostfree.pw/ts/relocator.lua" -script_version="4.5.2" +script_version="4.5.3" script_namespace="ua.Relocator" local haveDepCtrl,DependencyControl,depRec=pcall(require,"l0.DependencyControl") if haveDepCtrl then - script_version="4.5.2" + script_version="4.5.3" depRec=DependencyControl{feed="https://raw.githubusercontent.com/unanimated/luaegisub/master/DependencyControl.json"} end @@ -42,8 +42,8 @@ function relocator(subs,sel,act) hyperconfig={ {x=12,y=0,width=2,class="label",label="Teleport "}, - {x=12,y=1,width=4,class="floatedit",name="eks",hint="X"}, - {x=12,y=2,width=4,class="floatedit",name="wai",hint="Y"}, + {x=12,y=1,width=6,class="floatedit",name="eks",hint="X"}, + {x=12,y=2,width=6,class="floatedit",name="wai",hint="Y"}, {x=0,y=0,width=3,class="label",label="&Repositioning Field"}, {x=0,y=1,width=2,class="dropdown",name="posi",value="clip to frz",items=Repositioning}, @@ -100,13 +100,14 @@ function relocator(subs,sel,act) {x=15,y=5,class="checkbox",name="tpexp",label="exp",hint="expand rectangular clip in opposite directions"}, {x=13,y=5,width=2,class="checkbox",name="tpmask",label="mask"}, {x=14,y=0,width=2,class="checkbox",name="warp",label="&Warp",hint="Warped Teleport"}, - {x=12,y=6,width=4,class="checkbox",name="autopos",label="pos with tags missing",value=true,hint="Teleport position when \\pos tags missing"}, + {x=12,y=6,width=2,class="checkbox",name="autopos",label="pos WTS",value=true,hint="Teleport position when \\pos tags missing"}, + {x=14,y=6,width=2,class="checkbox",name="tpmaskNoRound",label="Mask no round",value=false,hint="Teleport mask without rounding"}, {x=0,y=7,width=3,class="checkbox",name="space",label="SpaceTravel &Guide", hint="The Typesetter's Guide to the Hyperdimensional Relocator."}, {x=8,y=7,width=2,class="checkbox",name="rpt",label="Repeat",hint="Repeat with last settings (any function)"}, {x=10,y=7,width=3,class="checkbox",name="save",label="Save config",hint="Save current configuration"}, - {x=13,y=7,width=3,class="label",label="[Incarnation "..script_version.."]"} + {x=13,y=7,width=4,class="label",label="[Incarnation "..script_version.."]"} } loadconfig() if remember then @@ -2542,6 +2543,13 @@ function teleport(subs,sel) text=text:gsub("(}m )"..draw,"%1"..draw2) end + if res.tpmaskNoRound then + draw=text:match("}m ([^{]+)") + draw2=draw:gsub("([%d.-]+) ([%d.-]+)",function(a,b) return a+xx+fx.." "..b+yy+fy end) + draw=esc(draw) + text=text:gsub("(}m )"..draw,"%1"..draw2) + end + if text~=line.text then relocated=relocated+1 end text=roundpar(text,2) line.text=text @@ -3425,6 +3433,7 @@ function tpres() res.tporg=false res.tpclip=false res.tpmask=false + res.tpmaskNoRound=false res.warp=false res.autopos=true res.eks=0 From 76c9ed6e62699e4b6bc3833f1bcb7a9d56cd80a8 Mon Sep 17 00:00:00 2001 From: Ghegghe Date: Mon, 10 Jul 2023 18:26:06 +0200 Subject: [PATCH 04/15] removed redoundant function --- ua.Relocator.lua | 23 +++++++---------------- ua.ScriptCleanup.lua | 4 ++-- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/ua.Relocator.lua b/ua.Relocator.lua index fe27904..864a7e9 100644 --- a/ua.Relocator.lua +++ b/ua.Relocator.lua @@ -5,12 +5,12 @@ script_name="Hyperdimensional Relocator" script_description="Advanced metamorphosis of multidimensional coordinates" script_author="reanimated" script_url="http://unanimated.hostfree.pw/ts/relocator.lua" -script_version="4.5.3" +script_version="4.5.2.2" script_namespace="ua.Relocator" local haveDepCtrl,DependencyControl,depRec=pcall(require,"l0.DependencyControl") if haveDepCtrl then - script_version="4.5.3" + script_version="4.5.2" depRec=DependencyControl{feed="https://raw.githubusercontent.com/unanimated/luaegisub/master/DependencyControl.json"} end @@ -42,8 +42,8 @@ function relocator(subs,sel,act) hyperconfig={ {x=12,y=0,width=2,class="label",label="Teleport "}, - {x=12,y=1,width=6,class="floatedit",name="eks",hint="X"}, - {x=12,y=2,width=6,class="floatedit",name="wai",hint="Y"}, + {x=12,y=1,width=4,class="floatedit",name="eks",hint="X"}, + {x=12,y=2,width=4,class="floatedit",name="wai",hint="Y"}, {x=0,y=0,width=3,class="label",label="&Repositioning Field"}, {x=0,y=1,width=2,class="dropdown",name="posi",value="clip to frz",items=Repositioning}, @@ -98,16 +98,15 @@ function relocator(subs,sel,act) {x=12,y=4,class="checkbox",name="tpc1",label="c1",value=true,hint="affect top left corner of rectangular clip"}, {x=12,y=5,class="checkbox",name="tpc2",label="c2",value=true,hint="affect bottom right corner of rectangular clip"}, {x=15,y=5,class="checkbox",name="tpexp",label="exp",hint="expand rectangular clip in opposite directions"}, - {x=13,y=5,width=2,class="checkbox",name="tpmask",label="mask"}, + {x=13,y=5,class="checkbox",name="tpmask",label="mask",value=false,hint="Teleport mask without rounding"}, {x=14,y=0,width=2,class="checkbox",name="warp",label="&Warp",hint="Warped Teleport"}, - {x=12,y=6,width=2,class="checkbox",name="autopos",label="pos WTS",value=true,hint="Teleport position when \\pos tags missing"}, - {x=14,y=6,width=2,class="checkbox",name="tpmaskNoRound",label="Mask no round",value=false,hint="Teleport mask without rounding"}, + {x=12,y=6,width=4,class="checkbox",name="autopos",label="pos with tags missing",value=true,hint="Teleport position when \\pos tags missing"}, {x=0,y=7,width=3,class="checkbox",name="space",label="SpaceTravel &Guide", hint="The Typesetter's Guide to the Hyperdimensional Relocator."}, {x=8,y=7,width=2,class="checkbox",name="rpt",label="Repeat",hint="Repeat with last settings (any function)"}, {x=10,y=7,width=3,class="checkbox",name="save",label="Save config",hint="Save current configuration"}, - {x=13,y=7,width=4,class="label",label="[Incarnation "..script_version.."]"} + {x=13,y=7,width=3,class="label",label="[Incarnation "..script_version.."]"} } loadconfig() if remember then @@ -2537,13 +2536,6 @@ function teleport(subs,sel) end if res.tpmask then - draw=text:match("}m ([^{]+)") - draw2=draw:gsub("([%d.-]+) ([%d.-]+)",function(a,b) return round(a+xx+fx).." "..round(b+yy+fy) end) - draw=esc(draw) - text=text:gsub("(}m )"..draw,"%1"..draw2) - end - - if res.tpmaskNoRound then draw=text:match("}m ([^{]+)") draw2=draw:gsub("([%d.-]+) ([%d.-]+)",function(a,b) return a+xx+fx.." "..b+yy+fy end) draw=esc(draw) @@ -3433,7 +3425,6 @@ function tpres() res.tporg=false res.tpclip=false res.tpmask=false - res.tpmaskNoRound=false res.warp=false res.autopos=true res.eks=0 diff --git a/ua.ScriptCleanup.lua b/ua.ScriptCleanup.lua index cbe2ed5..182c749 100644 --- a/ua.ScriptCleanup.lua +++ b/ua.ScriptCleanup.lua @@ -3,12 +3,12 @@ script_name="Script Cleanup" script_description="Garbage disposal and elimination of incriminating evidence" script_author="unanimated" -script_version="5.0" +script_version="5.0.1" script_namespace="ua.ScriptCleanup" local haveDepCtrl,DependencyControl,depRec=pcall(require,"l0.DependencyControl") if haveDepCtrl then - script_version="5.0.0" + script_version="5.0.1" depRec=DependencyControl{feed="https://raw.githubusercontent.com/unanimated/luaegisub/master/DependencyControl.json"} end From 6ecba289f55c8de8be295b090647e65b9eab1b4a Mon Sep 17 00:00:00 2001 From: Ghegghe Date: Tue, 11 Jul 2023 14:07:28 +0200 Subject: [PATCH 05/15] feat: remove textless lines, with comment ignore options --- ua.ScriptCleanup.lua | 121 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 100 insertions(+), 21 deletions(-) diff --git a/ua.ScriptCleanup.lua b/ua.ScriptCleanup.lua index 182c749..a64731f 100644 --- a/ua.ScriptCleanup.lua +++ b/ua.ScriptCleanup.lua @@ -3,12 +3,12 @@ script_name="Script Cleanup" script_description="Garbage disposal and elimination of incriminating evidence" script_author="unanimated" -script_version="5.0.1" +script_version="5.0.2" script_namespace="ua.ScriptCleanup" local haveDepCtrl,DependencyControl,depRec=pcall(require,"l0.DependencyControl") if haveDepCtrl then - script_version="5.0.1" + script_version="5.0.2" depRec=DependencyControl{feed="https://raw.githubusercontent.com/unanimated/luaegisub/master/DependencyControl.json"} end @@ -158,7 +158,7 @@ function cleanlines(subs,sel) text=text:gsub("}.-{","}{") text=text:gsub("}([^}]+)$","}") end - + if res.alphacol then text=text :gsub("alpha&(%x%x)&","alpha&H%1&") @@ -630,6 +630,76 @@ if text=="" then return orig end return text end +-- Ghegghe functions + +function removeTextlessLines(subs, sel, keepInlineComments, ignoreCommentedLines) + progress("Deleting empty lines") + noe_sel = {} + + for s = #sel, 1, -1 do + line = subs[ sel[ s ] ].text + + isDeletable = true + if not (ignoreCommentedLines and subs[ sel[ s ] ].comment) then + line=line:gsub("\\","\\\\") + line=line:gsub("\a","\\a") + line=line:gsub("\b","\\b") + line=line:gsub("\f","\\f") + line=line:gsub("\n","\\n") + line=line:gsub("\r","\\r") + line=line:gsub("\t","\\t") + line=line:gsub("\v","\\v") + line=line:gsub("\"","\\\"") + line=line:gsub("\'","\\\'") + + isComment = true + iLine = 1 + while iLine <= line:len() do + if isDeletable then + if line:sub(iLine, iLine) == '{' then + -- check the tag field + while line:sub(iLine, iLine) ~= '}' do + iLine = iLine + 1 + if iLine == line:len() + 1 then + -- broken tag field + isDeletable = false + break + elseif line:sub(iLine, iLine) == '\\' then + -- tags + isComment = false + end + end + if keepInlineComments and isComment then + -- ignore line + isDeletable = false + break + end + else + -- return if there is some text in the line + isDeletable = false + break + end + iLine = iLine + 1 + else + break + end + end + else + isDeletable = false + end + + if isDeletable then + for z, i in ipairs(noe_sel) do + noe_sel[ z ] = i - 1 + end + subs.delete( sel[ s ] ) + else + table.insert( noe_sel, sel[ s ] ) + end + end + + return noe_sel +end function cleanup(subs,sel,act) ADD=aegisub.dialog.display @@ -640,19 +710,19 @@ STAG="^{>?\\[^}]-}" if act==0 then act=sel[1] end chng=0 kleen=0 GUI={ -{x=0,y=0,class="checkbox",name="nots",label="Remove TS timecodes",hint="Removes timecodes like {TS 12:36}"}, -{x=0,y=1,class="checkbox",name="clear_a",label="Clear Actor field"}, -{x=0,y=2,class="checkbox",name="clear_e",label="Clear Effect field"}, -{x=0,y=3,class="checkbox",name="layers",label="Raise dialogue layer by 5"}, -{x=0,y=4,class="checkbox",name="cleantag",label="Clean up tags",hint="Fixes duplicates, \\\\, \\}, }{, and other garbage"}, -{x=0,y=5,class="checkbox",name="ctrans",label="Clean up transforms"}, -{x=0,y=6,class="checkbox",name="overlap",label="Fix 1-frame gaps/overlaps"}, -{x=0,y=7,class="checkbox",name="nocomline",label="Delete commented lines"}, -{x=0,y=8,class="checkbox",name="noempty",label="Delete empty lines"}, -{x=0,y=9,class="checkbox",name="alphacol",label="Try to fix alpha / colour tags"}, -{x=0,y=10,class="checkbox",name="spaces",label="Fix start/end/double spaces"}, -{x=0,y=12,class="checkbox",name="info",label="Print info"}, -{x=0,y=13,class="checkbox",name="all",label="ALL OF THE ABOVE"}, +{x=0,y=0,width=2,class="checkbox",name="nots",label="Remove TS timecodes",hint="Removes timecodes like {TS 12:36}"}, +{x=0,y=1,width=2,class="checkbox",name="clear_a",label="Clear Actor field"}, +{x=0,y=2,width=2,class="checkbox",name="clear_e",label="Clear Effect field"}, +{x=0,y=3,width=2,class="checkbox",name="layers",label="Raise dialogue layer by 5"}, +{x=0,y=4,width=2,class="checkbox",name="cleantag",label="Clean up tags",hint="Fixes duplicates, \\\\, \\}, }{, and other garbage"}, +{x=0,y=5,width=2,class="checkbox",name="ctrans",label="Clean up transforms"}, +{x=0,y=6,width=2,class="checkbox",name="overlap",label="Fix 1-frame gaps/overlaps"}, +{x=0,y=7,width=2,class="checkbox",name="nocomline",label="Delete commented lines"}, +{x=0,y=8,width=2,class="checkbox",name="noempty",label="Delete empty lines"}, +{x=0,y=9,width=2,class="checkbox",name="alphacol",label="Try to fix alpha / colour tags"}, +{x=0,y=10,width=2,class="checkbox",name="spaces",label="Fix start/end/double spaces"}, +{x=0,y=12,width=2,class="checkbox",name="info",label="Print info"}, +{x=0,y=13,width=2,class="checkbox",name="all",label="ALL OF THE ABOVE"}, {x=1,y=0,class="label",label=" "}, @@ -678,11 +748,17 @@ GUI={ {x=3,y=10,class="checkbox",name="nostyle2",label="Except Def.",hint="Delete unused styles except Default"}, {x=2,y=11,class="checkbox",name="inline",label="Remove inline tags"}, {x=3,y=11,class="checkbox",name="inline2",label="Except last",hint="Remove inline tags except the last one"}, -{x=2,y=12,class="checkbox",name="text",label="Remove text"}, -{x=2,y=13,width=2,class="checkbox",name="nocom",label="Remove comments from lines",hint="Removes {comments} (not tags)"}, -{x=2,y=14,width=2,class="checkbox",name="notag",label="Remove all {\\tags} from selected lines"}, +{x=2,y=12,width=2,class="checkbox",name="nocom",label="Remove comments from lines",hint="Removes {comments} (not tags)"}, +{x=2,y=13,width=2,class="checkbox",name="notag",label="Remove all {\\tags} from selected lines"}, -{x=4,y=0,height=15,class="label",label="| \n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|"}, +{x=0,y=15,width=3,class="label",label="~ Ghegghe's functions ~"}, +{x=0,y=16,width=3,class="checkbox",name="text",label="Remove text"}, +{x=0,y=17,width=3,class="checkbox",name="removeTextlessLines",label="Remove textless lines"}, +{x=0,y=18,class="label",label=" "}, +{x=1,y=18,class="checkbox",name="textlessLinesKeepInlineComments",label="Keep comments",hint="Keeps lines with comments inside"}, +{x=1,y=19,class="checkbox",name="textlessLinesKeepCommentedLines",label="Keep commented lines",value=true,hint="Keeps commented lines"}, + +{x=4,y=0,height=19,class="label",label="| \n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|"}, {x=5,y=0,class="checkbox",name="skill",label="[start]",value=true}, {x=6,y=0,class="checkbox",name="ikill",label="[inline]",value=true,hint="only kill, not hide"}, @@ -746,7 +822,7 @@ GUI={ C=0 for key,v in ipairs(GUI) do if v.x<=3 and res[v.name] then C=1 end end if C==0 then t_error("Run Selected: Error - nothing selected",1) end if res.all then - for key,v in ipairs(GUI) do if v.x>0 and v.name then res[v.name]=false end end + for key,v in ipairs(GUI) do if v.x>0 and v.name and v.y<15 then res[v.name]=false end end cleanlines(subs,sel) sel=noemptycom(subs,sel) else cleanlines(subs,sel) @@ -755,6 +831,9 @@ GUI={ if res.nocomline then sel=nocom_line(subs,sel) end if res.noempty then sel=noempty(subs,sel) end end + if res.removeTextlessLines then + sel=removeTextlessLines(subs, sel, res.textlessLinesKeepInlineComments, res.textlessLinesKeepCommentedLines) + end table.sort(sel) if res.nostyle or res.nostyle2 then sel=nostyle(subs,sel) end end From 2fbde9479169fecd788252b216854fe1f26b2fbf Mon Sep 17 00:00:00 2001 From: Ghegghe Date: Tue, 11 Jul 2023 17:46:15 +0200 Subject: [PATCH 06/15] fix: inline comments after first brackets --- ua.ScriptCleanup.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ua.ScriptCleanup.lua b/ua.ScriptCleanup.lua index a64731f..1bf8273 100644 --- a/ua.ScriptCleanup.lua +++ b/ua.ScriptCleanup.lua @@ -652,12 +652,12 @@ function removeTextlessLines(subs, sel, keepInlineComments, ignoreCommentedLines line=line:gsub("\"","\\\"") line=line:gsub("\'","\\\'") - isComment = true iLine = 1 while iLine <= line:len() do if isDeletable then if line:sub(iLine, iLine) == '{' then -- check the tag field + isComment = true while line:sub(iLine, iLine) ~= '}' do iLine = iLine + 1 if iLine == line:len() + 1 then From 1f5e856a2b4472e465c8099e5a335b5a3bf004ac Mon Sep 17 00:00:00 2001 From: Ghegghe Date: Tue, 11 Jul 2023 22:02:22 +0200 Subject: [PATCH 07/15] fix: remove text without any inline tag --- ua.ScriptCleanup.lua | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/ua.ScriptCleanup.lua b/ua.ScriptCleanup.lua index 1bf8273..c618677 100644 --- a/ua.ScriptCleanup.lua +++ b/ua.ScriptCleanup.lua @@ -154,9 +154,25 @@ function cleanlines(subs,sel) if res.inline2 then repeat text,r=text:gsub("(.)"..ATAG.."(.-{%*?\\)","%1%2") until r==0 elseif res.inline then text=text:gsub("(.)"..ATAG,"%1") end if res.text then - text=text:gsub("^.-{","{") - text=text:gsub("}.-{","}{") - text=text:gsub("}([^}]+)$","}") + newText = '' + isInBrackets = false + + for i = 1, text:len() do + char = text:sub(i,i) + -- start to save characters + if char == '{' then + isInBrackets = true + end + -- save the character in tag + if isInBrackets then + newText = newText..char + end + -- stop to save character + if char == '}' then + isInBrackets = false + end + end + text=newText end if res.alphacol then @@ -758,7 +774,7 @@ GUI={ {x=1,y=18,class="checkbox",name="textlessLinesKeepInlineComments",label="Keep comments",hint="Keeps lines with comments inside"}, {x=1,y=19,class="checkbox",name="textlessLinesKeepCommentedLines",label="Keep commented lines",value=true,hint="Keeps commented lines"}, -{x=4,y=0,height=19,class="label",label="| \n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|"}, +{x=4,y=0,height=20,class="label",label="| \n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|"}, {x=5,y=0,class="checkbox",name="skill",label="[start]",value=true}, {x=6,y=0,class="checkbox",name="ikill",label="[inline]",value=true,hint="only kill, not hide"}, From 753406d95a7f02b263e1f7f691c840ac0c905ec0 Mon Sep 17 00:00:00 2001 From: Ghegghe Date: Thu, 13 Jul 2023 01:03:57 +0200 Subject: [PATCH 08/15] feat: NecrosCopy->Multycopy, allows to copy start tags from N lines to N lines, divided by groups --- ua.NecrosCopy.lua | 349 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 339 insertions(+), 10 deletions(-) diff --git a/ua.NecrosCopy.lua b/ua.NecrosCopy.lua index 66d1169..631fb1e 100644 --- a/ua.NecrosCopy.lua +++ b/ua.NecrosCopy.lua @@ -1,12 +1,12 @@ script_name="NecrosCopy" script_description="Copy and fax things in the shadows while lines are splitting and breaking" script_author="reanimated" -script_version="4.1" +script_version="5.0.0" script_namespace="ua.NecrosCopy" local haveDepCtrl,DependencyControl,depRec=pcall(require,"l0.DependencyControl") if haveDepCtrl then - script_version="4.1.0" + script_version="5.0.0" depRec=DependencyControl{feed="https://raw.githubusercontent.com/unanimated/luaegisub/master/DependencyControl.json"} end @@ -308,6 +308,315 @@ function necrostuff(subs,sel) trnsfrm=nil end +-- Ghegghe's stuff + +function getTableSize(t) + local count = 0 + for _ in pairs(t) do + count = count + 1 + end + return count +end + +function table.shallowCopy(table) + newTable = {} + for key, value in pairs(table) do + newTable[ key ] = value + end + return newTable +end + +-- returns the "type" of the tag +function getTagType(tag) + local tags ={ + {name="blur", tag="\\blur"}, + {name="scale_x", tag="\\fscx"}, + {name="scale_y", tag="\\fscy"}, + {name="spacing", tag="\\fsp"}, + {name="alpha", tag="\\alpha"}, + {name="move", tag="\\move"}, + {name="fade", tag="\\fade"}, + {name="clip", tag="\\clip"}, + {name="iclip", tag="\\iclip"}, + {name="outline_x", tag="\\xbord"}, + {name="outline_y", tag="\\ybord"}, + {name="outline", tag="\\bord"}, + {name="shadow_x", tag="\\xshad"}, + {name="shadow_y", tag="\\yshad"}, + {name="shadow", tag="\\shad"}, + + -- three character tags + {name="position", tag="\\pos"}, + {name="origin", tag="\\org"}, + {name="fade_simple", tag="\\fad"}, + {name="angle", tag="\\frz"}, + {name="angle_x", tag="\\frx"}, + {name="angle_y", tag="\\fry"}, + {name="shear_x", tag="\\fax"}, + {name="shear_y", tag="\\fay"}, + {name="baseline_offset", tag="\\pbo"}, + + -- two character tags + {name="fontsize", tag="\\fs"}, + {name="align", tag="\\an"}, + {name="color1", tag="\\1c"}, + {name="color2", tag="\\2c"}, + {name="color3", tag="\\3c"}, + {name="color4", tag="\\4c"}, + {name="alpha1", tag="\\1a"}, + {name="alpha2", tag="\\2a"}, + {name="alpha3", tag="\\3a"}, + {name="alpha4", tag="\\4a"}, + {name="blur_edges", tag="\\be"}, + {name="k_sweep", tag="\\kf"}, + {name="k_bord", tag="\\ko"}, + {name="fontname", tag="\\fn"}, + + -- one character tags + {name="color", tag="\\c"}, + {name="drawing", tag="\\p"}, + {name="transform", tag="\\t"}, + {name="wrapstyle", tag="\\q"}, + {name="italic", tag="\\i"}, + {name="underline", tag="\\u"}, + {name="strikeout", tag="\\s"}, + {name="bold", tag="\\b"}, + {name="k_fill", tag="\\k"}, + {name="reset", tag="\\r"}, + } + for key, value in ipairs(tags) do + if tag:match(value.tag) then + return value.name + end + end + return "no_tag" +end + +-- returns an object with the "type" of the tag and his "value" +function getTypeAndValue(tag) + local tags ={ + {name="blur", tag="\\blur"}, + {name="scale_x", tag="\\fscx"}, + {name="scale_y", tag="\\fscy"}, + {name="spacing", tag="\\fsp"}, + {name="alpha", tag="\\alpha"}, + {name="move", tag="\\move"}, + {name="fade", tag="\\fade"}, + {name="clip", tag="\\clip"}, + {name="iclip", tag="\\iclip"}, + {name="outline_x", tag="\\xbord"}, + {name="outline_y", tag="\\ybord"}, + {name="outline", tag="\\bord"}, + {name="shadow_x", tag="\\xshad"}, + {name="shadow_y", tag="\\yshad"}, + {name="shadow", tag="\\shad"}, + + -- three character tags + {name="position", tag="\\pos"}, + {name="origin", tag="\\org"}, + {name="fade_simple", tag="\\fad"}, + {name="angle", tag="\\frz"}, + {name="angle_x", tag="\\frx"}, + {name="angle_y", tag="\\fry"}, + {name="shear_x", tag="\\fax"}, + {name="shear_y", tag="\\fay"}, + {name="baseline_offset", tag="\\pbo"}, + + -- two character tags + {name="fontsize", tag="\\fs"}, + {name="align", tag="\\an"}, + {name="color1", tag="\\1c"}, + {name="color2", tag="\\2c"}, + {name="color3", tag="\\3c"}, + {name="color4", tag="\\4c"}, + {name="alpha1", tag="\\1a"}, + {name="alpha2", tag="\\2a"}, + {name="alpha3", tag="\\3a"}, + {name="alpha4", tag="\\4a"}, + {name="blur_edges", tag="\\be"}, + {name="k_sweep", tag="\\kf"}, + {name="k_bord", tag="\\ko"}, + {name="fontname", tag="\\fn"}, + + -- one character tags + {name="color", tag="\\c"}, + {name="drawing", tag="\\p"}, + {name="transform", tag="\\t"}, + {name="wrapstyle", tag="\\q"}, + {name="italic", tag="\\i"}, + {name="underline", tag="\\u"}, + {name="strikeout", tag="\\s"}, + {name="bold", tag="\\b"}, + {name="k_fill", tag="\\k"}, + {name="reset", tag="\\r"}, + } + for key, value in ipairs(tags) do + if tag:match(value.tag) then + return {type=value.tag, value=tag:gsub(value.tag, "")} + end + end + return {type="notag", value=nil} +end + +-- multicopy +function multistuff(subs, sel) + progress("MultiCopying...") + + -- create an array of selected lines + lines = {} + selSize = getTableSize(sel) + for i = 1, selSize do + lines[ i ] = subs[ sel[ i ] ] + end + + -- get tag to copy from first group + iLine = 1 + toCopyLines = {} + while iLine <= selSize and not lines[ iLine ].comment do + toCopyLines[ iLine ] = lines[ iLine ].text + iLine = iLine + 1 + end + toCopyLinesLength = iLine - 1 + + -- build GUI + multicopyGUI={ + {x=0, y=0, class="label", label="Ready to copy? groups detected: " .. toCopyLinesLength}, + {x=0, y=1, class="checkbox", value=true, label="Overwrite tags", name="overwrite"}, + {x=0, y=2, class="checkbox", value=true, label="Keep inline", name="keepInline"}, + {x=0, y=3, class="checkbox", value=true, label="Keep old tags", name="keep"}, + } + if iLine > selSize then + table.insert(multicopyGUI, {x=0, y=4, class="label", label="It's recommended to read the flight manual first"}) + end + press,checkboxes=ADD(multicopyGUI,{"Make me fly","Not today"},{ok='Make me fly',close='Not today'}) + + if press=="Not today" then + -- exit + ak() + elseif iLine > selSize then + t_error("Incorrectly formatted lines, it's recommended to read the flight manual first", true) + else + -- multicopy + iToCopyLines = 1 + + -- for all lines + while iLine <= selSize and iToCopyLines <= toCopyLinesLength do + progress("Multicopying group " .. iToCopyLines .. " / " .. toCopyLinesLength) + + -- find next group + while iLine <= selSize and lines[ iLine ].comment do + iLine = iLine + 1 + end + + if iLine <= selSize then + -- put tags in array + toCopyLine = toCopyLines[ iToCopyLines ] + + -- start to check tags + -- [type, value] + tags = {} + -- ignore the first '{' character + iToCopyLine = 2 + char = toCopyLine:sub(iToCopyLine, iToCopyLine) + + -- get the tags object + repeat + -- copy the single tag + tag = "" + repeat + tag = tag .. char + iToCopyLine = iToCopyLine + 1 + char = toCopyLine:sub(iToCopyLine, iToCopyLine) + until char == "\\" or char == "}" + table.insert(tags, getTypeAndValue(tag)) + until char == "}" + + -- copying tags + while iLine <= selSize and not lines[ iLine ].comment do + -- extract tags + line = lines[ iLine ].text + newTags = table.shallowCopy(tags) + + -- tags check + if line:sub(1, 1) == "{" then + if checkboxes.keep then + -- get the tags object + oldTags = {} + iCheck = 2 + char = line:sub(iCheck, iCheck) + repeat + -- copy the single tag + tag = "" + repeat + tag = tag .. char + iCheck = iCheck + 1 + char = line:sub(iCheck, iCheck) + until char == "\\" or char == "}" + table.insert(oldTags, getTypeAndValue(tag)) + until char == "}" + + -- join tags + if iCheck > 2 then + for _, oldValue in ipairs(oldTags) do + isReplace = false + for newKey, newValue in ipairs(newTags) do + -- replace tag if is the same + if oldValue.type == newValue.type then + -- check the value if transform + if oldValue ~= "\\t" or (oldValue.type == "\\t" and oldValue.value == newValue.value) then + isReplace = true + if not checkboxes.overwrite then + newTags[ newKey ].value = oldValue.value + end + end + end + end + -- add the old tag + if not isReplace then + table.insert(newTags, oldValue) + end + end + end + end + + -- clear the line + if checkboxes.keepInline then + line = line:gsub("^{.-}", "") + else + line = line:gsub("{.-}", "") + end + end + + -- copy tags + tag = "" + for key, value in ipairs(newTags) do + tag = tag .. value.type .. value.value + end + lines[ iLine ].text = "{" .. tag .. "}" .. line + subs[ sel[ iLine ] ]=lines[ iLine ] + + iLine = iLine + 1 + end + -- repeat with next group + iToCopyLines = iToCopyLines + 1 + end + end + + -- check if all lines were copied + if iLine < selSize then + -- more groups then copy lines + t_error("There were more groups then \"to copy\" lines.\nHowever, all the " .. toCopyLinesLength .. " \"to copy\" lines were copied in the first groups") + elseif iToCopyLines <= toCopyLinesLength then + -- more copy lines then groups + t_error("There were more \"to copy\" lines then groups.\nHowever, the first " .. iToCopyLines .. " were copied anyway") + end + + progress("Multicopying complete.") + end +end + +-- Ghegghe's end + function copytags(subs,sel) for z,i in ipairs(sel) do progress("Copypasting tags... "..z.."/"..#sel) @@ -382,7 +691,6 @@ function copycolours(subs,sel) return sel end - -- 3D shadow -- [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] function shad3(subs,sel) for z=#sel,1,-1 do @@ -424,7 +732,6 @@ function shad3(subs,sel) return sel end - -- Split into Letters -- [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] function space(subs,sel) nsel={} for z,i in ipairs(sel) do table.insert(nsel,i) end @@ -562,7 +869,6 @@ function space(subs,sel) return nsel end - -- Split by \N -- [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] [- -] function splitbreak(subs,sel) nsel={} for z,i in ipairs(sel) do table.insert(nsel,i) end @@ -797,8 +1103,6 @@ function rotxy(rot,xpos,y) return xpos,y end - - -- reanimatools ------------------------------------------------------------------------------------------------------------------------------------ function addtag(tag,text) text=text:gsub("^({\\[^}]-)}","%1"..tag.."}") return text end @@ -1168,19 +1472,43 @@ as it will restart after \N. [Un]hide lets you hide/unhide checked tags (by making them comments). Checked tags get hidden. If you don't check anything, whatever was hidden gets unhidden. Good for clips, for example.]] +multihelp=[[ +Multicopy +It allows you to copy all the start tag from N to N lines. +You can also check if you want to overwrite existent tags, +keep inline and/or old start tags from lines on which tags will be copied. + +For make this script works, you must select all the lines from which tags will be copied, +and the lines on which tags will be copied, separated at least by one commented line. + +Example: +-{\b1} (copy from) +-{\fad(300,400)} (copy from) +-commented lines (separator) +-(first group of lines (1), \b will be copied here) +-(first group of lines (2), \b will be copied here) +-commented lines (separator) +-(second group of lines (1), \fad(300,400) will be copied here) +-(second group of lines (2), \fad(300,400) will be copied here) +-(second group of lines (3), \fad(300,400) will be copied here) + +Obviously, you can copy more than one tag for group. +Having said that, have fun.]] + function necrohell() nekrohelp="http://unanimated.hostfree.pw/ts/scripts-manuals.htm#necroscopy" repeat if Pr=='clip2fax/frz' then nekrohelp=faxhelp end if Pr=='necroscopy' then nekrohelp=necrohelp end + if Pr=='multicopy' then nekrohelp=multihelp end if Pr=='copy tags/text' then nekrohelp=tagsthelp end if Pr=='copy colours' then nekrohelp=callhelp end if Pr=='3D shadow' then nekrohelp=shadehelp end if Pr=='split letters' then nekrohelp=splathelp end if Pr=='split by \\N' then nekrohelp=breakhelp end - Pr=aegisub.dialog.display({{width=32,height=10,class="textbox",value=nekrohelp},{x=36,height=10,class="label",label="NecrosCopy\nversion "..script_version}}, - {"clip2fax/frz","necroscopy","copy tags/text","copy colours","3D shadow","split letters","split by \\N","cancel"},{close='cancel'}) + Pr=aegisub.dialog.display({{width=38,height=10,class="textbox",value=nekrohelp},{x=39,height=10,class="label",label="NecrosCopy\nversion "..script_version}}, + {"clip2fax/frz","necroscopy","multicopy","copy tags/text","copy colours","3D shadow","split letters","split by \\N","cancel"},{close='cancel'}) until Pr=='cancel' end @@ -1216,12 +1544,13 @@ end {x=12,y=0,class="label",label=script_name.." v"..script_version}, {x=12,y=1,class="checkbox",name="help",label="necronomicon",hint="necrohelp"}, } - P,res=ADD(GUI,{"clip2fax/frz","necroscopy","copy tags","copy text","copy colours","3D shadow","split letters","split by \\N","split"},{cancel='split'}) + P,res=ADD(GUI,{"clip2fax/frz","necroscopy","multicopy","copy tags","copy text","copy colours","3D shadow","split letters","split by \\N","split"},{cancel='split'}) if P=="split" then ak() end if res.help then P='' necrohell() end if P=="clip2fax/frz" then if res.frz then frozt(subs,sel) else fucks(subs,sel) end end if P=="necroscopy" then reversel(subs,sel) necrostuff(subs,sel) end + if P=="multicopy" then reversel(subs,sel) multistuff(subs,sel) end if P=="copy tags" then reversel(subs,sel) copytags(subs,sel) end if P=="copy text" then reversel(subs,sel) copytext(subs,sel) end if P=="copy clip" then reversel(subs,sel) copyclip(subs,sel) end From f7defe5864a1d976621eb0b0f783afb9406e886b Mon Sep 17 00:00:00 2001 From: Ghegghe Date: Thu, 13 Jul 2023 21:52:40 +0200 Subject: [PATCH 09/15] fix: fixed issues in new functions and made some improvements --- ua.ScriptCleanup.lua | 139 +++++++++++++++++++++---------------------- 1 file changed, 67 insertions(+), 72 deletions(-) diff --git a/ua.ScriptCleanup.lua b/ua.ScriptCleanup.lua index c618677..3c1ef6d 100644 --- a/ua.ScriptCleanup.lua +++ b/ua.ScriptCleanup.lua @@ -3,12 +3,12 @@ script_name="Script Cleanup" script_description="Garbage disposal and elimination of incriminating evidence" script_author="unanimated" -script_version="5.0.2" +script_version="5.0.4" script_namespace="ua.ScriptCleanup" local haveDepCtrl,DependencyControl,depRec=pcall(require,"l0.DependencyControl") if haveDepCtrl then - script_version="5.0.2" + script_version="5.0.4" depRec=DependencyControl{feed="https://raw.githubusercontent.com/unanimated/luaegisub/master/DependencyControl.json"} end @@ -154,24 +154,23 @@ function cleanlines(subs,sel) if res.inline2 then repeat text,r=text:gsub("(.)"..ATAG.."(.-{%*?\\)","%1%2") until r==0 elseif res.inline then text=text:gsub("(.)"..ATAG,"%1") end if res.text then - newText = '' - isInBrackets = false + local newText = '' + local i = 1 - for i = 1, text:len() do - char = text:sub(i,i) + while i <= text:len() do + local char = text:sub(i, i) -- start to save characters if char == '{' then - isInBrackets = true - end - -- save the character in tag - if isInBrackets then - newText = newText..char - end - -- stop to save character - if char == '}' then - isInBrackets = false + repeat + newText = newText .. char + i = i + 1 + char = text:sub(i, i) + until char == "}" + newText = newText .. char end + i = i + 1 end + text=newText end @@ -646,77 +645,73 @@ if text=="" then return orig end return text end --- Ghegghe functions +-- Ghegghe's stuff -function removeTextlessLines(subs, sel, keepInlineComments, ignoreCommentedLines) - progress("Deleting empty lines") - noe_sel = {} +function removeTextlessLines(subs, sel, ignoreCommentedLines, keepInlineComments) + progress("Deleting textless lines...") + local newSel = {} for s = #sel, 1, -1 do - line = subs[ sel[ s ] ].text - - isDeletable = true + progress("Deleting textless lines " .. #sel - (s - 1) .. " / " .. #sel) + local hasDelete = true + local line = subs[ sel[ s ] ].text + -- ignore commented lines if not (ignoreCommentedLines and subs[ sel[ s ] ].comment) then - line=line:gsub("\\","\\\\") - line=line:gsub("\a","\\a") - line=line:gsub("\b","\\b") - line=line:gsub("\f","\\f") - line=line:gsub("\n","\\n") - line=line:gsub("\r","\\r") - line=line:gsub("\t","\\t") - line=line:gsub("\v","\\v") - line=line:gsub("\"","\\\"") - line=line:gsub("\'","\\\'") - - iLine = 1 + local iLine = 1 while iLine <= line:len() do - if isDeletable then - if line:sub(iLine, iLine) == '{' then - -- check the tag field - isComment = true - while line:sub(iLine, iLine) ~= '}' do + -- if "{" is opened + if line:sub(iLine, iLine) == "{" then + local hasTags = false + + repeat + if line:sub(iLine, iLine) == "\\" then + hasTags = true + break + end + iLine = iLine + 1 + until line:sub(iLine, iLine) == "}" or + iLine > line:len() + + if hasTags then + while line:sub(iLine, iLine) ~= "}" do iLine = iLine + 1 - if iLine == line:len() + 1 then - -- broken tag field - isDeletable = false - break - elseif line:sub(iLine, iLine) == '\\' then - -- tags - isComment = false - end end - if keepInlineComments and isComment then - -- ignore line - isDeletable = false + else + -- "{" not closed (text) or comment inline + if iLine > line:len() or keepInlineComments then + hasDelete = false break end - else - -- return if there is some text in the line - isDeletable = false - break end + + -- jump to next iLine = iLine + 1 else + -- text + hasDelete = false break - end + end end else - isDeletable = false + -- commented line + hasDelete = false end - if isDeletable then - for z, i in ipairs(noe_sel) do - noe_sel[ z ] = i - 1 + if hasDelete then + for z,i in ipairs(newSel) do + newSel[z]=i-1 end - subs.delete( sel[ s ] ) - else - table.insert( noe_sel, sel[ s ] ) - end + subs.delete(sel[s]) + else + table.insert(newSel,sel[s]) + end end - - return noe_sel + + return newSel end +-- Ghegghe's end + function cleanup(subs,sel,act) ADD=aegisub.dialog.display ak=aegisub.cancel @@ -755,7 +750,7 @@ GUI={ {x=3,y=5,class="checkbox",name="parent2",label="Except \\pos",hint="fad(e), (i)clip, move, org\n(but not t or pos)"}, {x=2,y=6,width=2,class="checkbox",name="allpers",label="Remove all perspective",hint="frx, fry, frz, fax, fay, org"}, -{x=2,y=7,width=2,class="label",label=" ~ Script Cleanup v"..script_version.." ~"}, +{x=2,y=7,width=2,class="label",label=" ~ Script Cleanup v5.0.0 ~"}, {x=2,y=8,width=2,class="checkbox",name="hspace",label="Remove hard spaces - \\h"}, {x=2,y=9,class="checkbox",name="nobreak",label="Remove line breaks"}, @@ -767,14 +762,14 @@ GUI={ {x=2,y=12,width=2,class="checkbox",name="nocom",label="Remove comments from lines",hint="Removes {comments} (not tags)"}, {x=2,y=13,width=2,class="checkbox",name="notag",label="Remove all {\\tags} from selected lines"}, -{x=0,y=15,width=3,class="label",label="~ Ghegghe's functions ~"}, +{x=0,y=15,width=3,class="label",label=" ~ Script Cleanup v"..script_version.." ~ "}, +{x=4,y=15,class="checkbox",label="ver. info"}, {x=0,y=16,width=3,class="checkbox",name="text",label="Remove text"}, -{x=0,y=17,width=3,class="checkbox",name="removeTextlessLines",label="Remove textless lines"}, -{x=0,y=18,class="label",label=" "}, -{x=1,y=18,class="checkbox",name="textlessLinesKeepInlineComments",label="Keep comments",hint="Keeps lines with comments inside"}, +{x=0,y=17,width=3,class="checkbox",name="removeTextlessLines",label="Remove textless lines",hint="Removes lines without text (tag doesn't count)"}, +{x=1,y=18,class="checkbox",name="textlessLinesKeepInlineComments",label="Keep inline comments",hint="Keeps lines with comments inside"}, {x=1,y=19,class="checkbox",name="textlessLinesKeepCommentedLines",label="Keep commented lines",value=true,hint="Keeps commented lines"}, -{x=4,y=0,height=20,class="label",label="| \n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|"}, +{x=4,y=0,height=20,class="label",label="|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|"}, {x=5,y=0,class="checkbox",name="skill",label="[start]",value=true}, {x=6,y=0,class="checkbox",name="ikill",label="[inline]",value=true,hint="only kill, not hide"}, @@ -848,7 +843,7 @@ GUI={ if res.noempty then sel=noempty(subs,sel) end end if res.removeTextlessLines then - sel=removeTextlessLines(subs, sel, res.textlessLinesKeepInlineComments, res.textlessLinesKeepCommentedLines) + sel = removeTextlessLines(subs, sel, res.textlessLinesKeepCommentedLines, res.textlessLinesKeepInlineComments) end table.sort(sel) if res.nostyle or res.nostyle2 then sel=nostyle(subs,sel) end From 1a315b811ae6d8722e4b0be761028a38894fa66a Mon Sep 17 00:00:00 2001 From: Ghegghe Date: Thu, 13 Jul 2023 22:07:16 +0200 Subject: [PATCH 10/15] :fix: removed unused functions, clean the code --- ua.NecrosCopy.lua | 291 +++++++++++++++++----------------------------- 1 file changed, 107 insertions(+), 184 deletions(-) diff --git a/ua.NecrosCopy.lua b/ua.NecrosCopy.lua index 631fb1e..fe0f00d 100644 --- a/ua.NecrosCopy.lua +++ b/ua.NecrosCopy.lua @@ -310,24 +310,16 @@ end -- Ghegghe's stuff -function getTableSize(t) - local count = 0 - for _ in pairs(t) do - count = count + 1 - end - return count -end - function table.shallowCopy(table) - newTable = {} + local newTable = {} for key, value in pairs(table) do newTable[ key ] = value end return newTable end --- returns the "type" of the tag -function getTagType(tag) +-- returns an object with the "type" of the tag and his "value" +function getTypeAndValue(tag) local tags ={ {name="blur", tag="\\blur"}, {name="scale_x", tag="\\fscx"}, @@ -386,214 +378,145 @@ function getTagType(tag) } for key, value in ipairs(tags) do if tag:match(value.tag) then - return value.name + return {type=value.tag, value=tag:gsub(value.tag, "")} end end - return "no_tag" + return nil end --- returns an object with the "type" of the tag and his "value" -function getTypeAndValue(tag) - local tags ={ - {name="blur", tag="\\blur"}, - {name="scale_x", tag="\\fscx"}, - {name="scale_y", tag="\\fscy"}, - {name="spacing", tag="\\fsp"}, - {name="alpha", tag="\\alpha"}, - {name="move", tag="\\move"}, - {name="fade", tag="\\fade"}, - {name="clip", tag="\\clip"}, - {name="iclip", tag="\\iclip"}, - {name="outline_x", tag="\\xbord"}, - {name="outline_y", tag="\\ybord"}, - {name="outline", tag="\\bord"}, - {name="shadow_x", tag="\\xshad"}, - {name="shadow_y", tag="\\yshad"}, - {name="shadow", tag="\\shad"}, - - -- three character tags - {name="position", tag="\\pos"}, - {name="origin", tag="\\org"}, - {name="fade_simple", tag="\\fad"}, - {name="angle", tag="\\frz"}, - {name="angle_x", tag="\\frx"}, - {name="angle_y", tag="\\fry"}, - {name="shear_x", tag="\\fax"}, - {name="shear_y", tag="\\fay"}, - {name="baseline_offset", tag="\\pbo"}, +function getStartTags(stags) + local tagObj = {} - -- two character tags - {name="fontsize", tag="\\fs"}, - {name="align", tag="\\an"}, - {name="color1", tag="\\1c"}, - {name="color2", tag="\\2c"}, - {name="color3", tag="\\3c"}, - {name="color4", tag="\\4c"}, - {name="alpha1", tag="\\1a"}, - {name="alpha2", tag="\\2a"}, - {name="alpha3", tag="\\3a"}, - {name="alpha4", tag="\\4a"}, - {name="blur_edges", tag="\\be"}, - {name="k_sweep", tag="\\kf"}, - {name="k_bord", tag="\\ko"}, - {name="fontname", tag="\\fn"}, - - -- one character tags - {name="color", tag="\\c"}, - {name="drawing", tag="\\p"}, - {name="transform", tag="\\t"}, - {name="wrapstyle", tag="\\q"}, - {name="italic", tag="\\i"}, - {name="underline", tag="\\u"}, - {name="strikeout", tag="\\s"}, - {name="bold", tag="\\b"}, - {name="k_fill", tag="\\k"}, - {name="reset", tag="\\r"}, - } - for key, value in ipairs(tags) do - if tag:match(value.tag) then - return {type=value.tag, value=tag:gsub(value.tag, "")} - end + local iStags = 1 + local char = stags:sub(iStags, iStags) + + if char == "{" then + -- if stag present + repeat + -- copy the single tag + local tag = "" + repeat + tag = tag .. char + iStags = iStags + 1 + char = stags:sub(iStags, iStags) + until char == "\\" or char == "}" + table.insert(tagObj, getTypeAndValue(tag)) + until char == "}" + return tagObj + else + return nil end - return {type="notag", value=nil} end --- multicopy -function multistuff(subs, sel) - progress("MultiCopying...") +-- groupcopy +function groupstuff(subs, sel) + progress("GroupCopying, fetch groups...") -- create an array of selected lines - lines = {} - selSize = getTableSize(sel) - for i = 1, selSize do + local lines = {} + for i = 1, #sel do lines[ i ] = subs[ sel[ i ] ] end - -- get tag to copy from first group - iLine = 1 - toCopyLines = {} - while iLine <= selSize and not lines[ iLine ].comment do - toCopyLines[ iLine ] = lines[ iLine ].text + -- get to copy lines from first group + local iLine = 1 + while iLine <= #sel and not lines[ iLine ].comment do iLine = iLine + 1 end - toCopyLinesLength = iLine - 1 + local toCopyLinesLength = iLine - 1 -- build GUI - multicopyGUI={ - {x=0, y=0, class="label", label="Ready to copy? groups detected: " .. toCopyLinesLength}, - {x=0, y=1, class="checkbox", value=true, label="Overwrite tags", name="overwrite"}, - {x=0, y=2, class="checkbox", value=true, label="Keep inline", name="keepInline"}, - {x=0, y=3, class="checkbox", value=true, label="Keep old tags", name="keep"}, + local groupcopyGUI={ + {x = 0, y = 0, + class = "label", label="Ready to copy? groups detected: " .. toCopyLinesLength}, + {x = 0, y = 1, + class = "checkbox", name = "overwrite", value = true, + label = "Overwrite tags", hint = "Overwrite identical tags"}, + {x = 0, y = 2, + class = "checkbox", name = "keepInline", value = true, + label = "Keep inline", hint = "Keeps inline tags in the lines where tags will be copied"}, + {x = 0, y = 3, + class = "checkbox", name = "keep", value = true, + label = "Keep old tags", hint = "Doesn't remove the start tags which doesn't match with new tags"}, } - if iLine > selSize then - table.insert(multicopyGUI, {x=0, y=4, class="label", label="It's recommended to read the flight manual first"}) + if iLine > #sel then + table.insert(groupcopyGUI, + {x = 0, y = 4, + class = "label", label = "It's recommended to read the flight manual first"}) end - press,checkboxes=ADD(multicopyGUI,{"Make me fly","Not today"},{ok='Make me fly',close='Not today'}) + local press, checkboxes = ADD( + groupcopyGUI, + {"Make me fly", "Not today"}, + {ok = 'Make me fly', close = 'Not today'}) - if press=="Not today" then + if press == "Not today" then -- exit ak() - elseif iLine > selSize then + elseif iLine > #sel then t_error("Incorrectly formatted lines, it's recommended to read the flight manual first", true) else - -- multicopy - iToCopyLines = 1 + -- groupcopy + local iToCopyLines = 1 -- for all lines - while iLine <= selSize and iToCopyLines <= toCopyLinesLength do - progress("Multicopying group " .. iToCopyLines .. " / " .. toCopyLinesLength) + while iLine <= #sel and iToCopyLines <= toCopyLinesLength do + progress("Groupcopying lines " .. iToCopyLines .. " / " .. toCopyLinesLength) -- find next group - while iLine <= selSize and lines[ iLine ].comment do + while iLine <= #sel and lines[ iLine ].comment do iLine = iLine + 1 end - if iLine <= selSize then - -- put tags in array - toCopyLine = toCopyLines[ iToCopyLines ] - - -- start to check tags + if iLine <= #sel then + -- fetch stags -- [type, value] - tags = {} - -- ignore the first '{' character - iToCopyLine = 2 - char = toCopyLine:sub(iToCopyLine, iToCopyLine) - - -- get the tags object - repeat - -- copy the single tag - tag = "" - repeat - tag = tag .. char - iToCopyLine = iToCopyLine + 1 - char = toCopyLine:sub(iToCopyLine, iToCopyLine) - until char == "\\" or char == "}" - table.insert(tags, getTypeAndValue(tag)) - until char == "}" + local toCopyTags = getStartTags(lines[ iToCopyLines ].text) -- copying tags - while iLine <= selSize and not lines[ iLine ].comment do - -- extract tags - line = lines[ iLine ].text - newTags = table.shallowCopy(tags) - - -- tags check - if line:sub(1, 1) == "{" then - if checkboxes.keep then - -- get the tags object - oldTags = {} - iCheck = 2 - char = line:sub(iCheck, iCheck) - repeat - -- copy the single tag - tag = "" - repeat - tag = tag .. char - iCheck = iCheck + 1 - char = line:sub(iCheck, iCheck) - until char == "\\" or char == "}" - table.insert(oldTags, getTypeAndValue(tag)) - until char == "}" - - -- join tags - if iCheck > 2 then - for _, oldValue in ipairs(oldTags) do - isReplace = false - for newKey, newValue in ipairs(newTags) do - -- replace tag if is the same - if oldValue.type == newValue.type then - -- check the value if transform - if oldValue ~= "\\t" or (oldValue.type == "\\t" and oldValue.value == newValue.value) then - isReplace = true - if not checkboxes.overwrite then - newTags[ newKey ].value = oldValue.value - end - end - end - end - -- add the old tag - if not isReplace then - table.insert(newTags, oldValue) + while iLine <= #sel and not lines[ iLine ].comment do + local newTags = table.shallowCopy(toCopyTags) + local oldTags = getStartTags(lines[ iLine ].text) + + if checkboxes.keep and oldTags ~= nil then + -- join tags + for _, oldValue in ipairs(oldTags) do + local isPresent = false + for newKey, newValue in ipairs(newTags) do + -- replace tag if is the same + -- transform check + if oldValue.type == newValue.type and + (oldValue ~= "\\t" or + (oldValue.type == "\\t" and + oldValue.value == newValue.value)) then + isPresent = true + -- overwrite if selected + if checkboxes.overwrite then + newTags[ newKey ].value = oldValue.value end end end + + -- add the old tag + if not isPresent then + table.insert(newTags, oldValue) + end end - - -- clear the line - if checkboxes.keepInline then - line = line:gsub("^{.-}", "") - else - line = line:gsub("{.-}", "") - end + end + + -- clear the line + if checkboxes.keepInline then + lines[ iLine ].text = lines[ iLine ].text:gsub("^{.-}", "") + else + lines[ iLine ].text = lines[ iLine ].text:gsub("{.-}", "") end -- copy tags - tag = "" + local tags = "" for key, value in ipairs(newTags) do - tag = tag .. value.type .. value.value + tags = tags .. value.type .. value.value end - lines[ iLine ].text = "{" .. tag .. "}" .. line - subs[ sel[ iLine ] ]=lines[ iLine ] + lines[ iLine ].text = "{" .. tags .. "}" .. lines[ iLine ].text + subs[ sel[ iLine ] ] = lines[ iLine ] iLine = iLine + 1 end @@ -603,7 +526,7 @@ function multistuff(subs, sel) end -- check if all lines were copied - if iLine < selSize then + if iLine < #sel then -- more groups then copy lines t_error("There were more groups then \"to copy\" lines.\nHowever, all the " .. toCopyLinesLength .. " \"to copy\" lines were copied in the first groups") elseif iToCopyLines <= toCopyLinesLength then @@ -611,7 +534,7 @@ function multistuff(subs, sel) t_error("There were more \"to copy\" lines then groups.\nHowever, the first " .. iToCopyLines .. " were copied anyway") end - progress("Multicopying complete.") + progress("Groupcopy complete.") end end @@ -1472,8 +1395,8 @@ as it will restart after \N. [Un]hide lets you hide/unhide checked tags (by making them comments). Checked tags get hidden. If you don't check anything, whatever was hidden gets unhidden. Good for clips, for example.]] -multihelp=[[ -Multicopy +grouphelp=[[ +Groupcopy It allows you to copy all the start tag from N to N lines. You can also check if you want to overwrite existent tags, keep inline and/or old start tags from lines on which tags will be copied. @@ -1501,14 +1424,14 @@ function necrohell() repeat if Pr=='clip2fax/frz' then nekrohelp=faxhelp end if Pr=='necroscopy' then nekrohelp=necrohelp end - if Pr=='multicopy' then nekrohelp=multihelp end + if Pr=='groupcopy' then nekrohelp=grouphelp end if Pr=='copy tags/text' then nekrohelp=tagsthelp end if Pr=='copy colours' then nekrohelp=callhelp end if Pr=='3D shadow' then nekrohelp=shadehelp end if Pr=='split letters' then nekrohelp=splathelp end if Pr=='split by \\N' then nekrohelp=breakhelp end Pr=aegisub.dialog.display({{width=38,height=10,class="textbox",value=nekrohelp},{x=39,height=10,class="label",label="NecrosCopy\nversion "..script_version}}, - {"clip2fax/frz","necroscopy","multicopy","copy tags/text","copy colours","3D shadow","split letters","split by \\N","cancel"},{close='cancel'}) + {"clip2fax/frz","necroscopy","groupcopy","copy tags/text","copy colours","3D shadow","split letters","split by \\N","cancel"},{close='cancel'}) until Pr=='cancel' end @@ -1544,13 +1467,13 @@ end {x=12,y=0,class="label",label=script_name.." v"..script_version}, {x=12,y=1,class="checkbox",name="help",label="necronomicon",hint="necrohelp"}, } - P,res=ADD(GUI,{"clip2fax/frz","necroscopy","multicopy","copy tags","copy text","copy colours","3D shadow","split letters","split by \\N","split"},{cancel='split'}) + P,res=ADD(GUI,{"clip2fax/frz","necroscopy","groupcopy","copy tags","copy text","copy colours","3D shadow","split letters","split by \\N","split"},{cancel='split'}) if P=="split" then ak() end if res.help then P='' necrohell() end if P=="clip2fax/frz" then if res.frz then frozt(subs,sel) else fucks(subs,sel) end end if P=="necroscopy" then reversel(subs,sel) necrostuff(subs,sel) end - if P=="multicopy" then reversel(subs,sel) multistuff(subs,sel) end + if P=="groupcopy" then reversel(subs,sel) groupstuff(subs,sel) end if P=="copy tags" then reversel(subs,sel) copytags(subs,sel) end if P=="copy text" then reversel(subs,sel) copytext(subs,sel) end if P=="copy clip" then reversel(subs,sel) copyclip(subs,sel) end From 299d0b2a86e997474277c2821218d22ea0313a03 Mon Sep 17 00:00:00 2001 From: Ghegghe Date: Fri, 14 Jul 2023 00:01:59 +0200 Subject: [PATCH 11/15] fix: gui --- ua.ScriptCleanup.lua | 182 +++++++++++++++++++++---------------------- 1 file changed, 91 insertions(+), 91 deletions(-) diff --git a/ua.ScriptCleanup.lua b/ua.ScriptCleanup.lua index 3c1ef6d..6faee2b 100644 --- a/ua.ScriptCleanup.lua +++ b/ua.ScriptCleanup.lua @@ -721,104 +721,104 @@ STAG="^{>?\\[^}]-}" if act==0 then act=sel[1] end chng=0 kleen=0 GUI={ -{x=0,y=0,width=2,class="checkbox",name="nots",label="Remove TS timecodes",hint="Removes timecodes like {TS 12:36}"}, -{x=0,y=1,width=2,class="checkbox",name="clear_a",label="Clear Actor field"}, -{x=0,y=2,width=2,class="checkbox",name="clear_e",label="Clear Effect field"}, -{x=0,y=3,width=2,class="checkbox",name="layers",label="Raise dialogue layer by 5"}, -{x=0,y=4,width=2,class="checkbox",name="cleantag",label="Clean up tags",hint="Fixes duplicates, \\\\, \\}, }{, and other garbage"}, -{x=0,y=5,width=2,class="checkbox",name="ctrans",label="Clean up transforms"}, -{x=0,y=6,width=2,class="checkbox",name="overlap",label="Fix 1-frame gaps/overlaps"}, -{x=0,y=7,width=2,class="checkbox",name="nocomline",label="Delete commented lines"}, -{x=0,y=8,width=2,class="checkbox",name="noempty",label="Delete empty lines"}, -{x=0,y=9,width=2,class="checkbox",name="alphacol",label="Try to fix alpha / colour tags"}, -{x=0,y=10,width=2,class="checkbox",name="spaces",label="Fix start/end/double spaces"}, -{x=0,y=12,width=2,class="checkbox",name="info",label="Print info"}, -{x=0,y=13,width=2,class="checkbox",name="all",label="ALL OF THE ABOVE"}, - -{x=1,y=0,class="label",label=" "}, - -{x=2,y=0,width=2,class="checkbox",name="allcol",label="Remove all colour tags"}, -{x=2,y=1,class="checkbox",name="allphas",label="Remove all alphas"}, -{x=3,y=1,class="checkbox",name="alpha14",label="Only 1a-4a"}, -{x=2,y=2,class="checkbox",name="allrot",label="Remove all rotations",hint="frx, fry, frz"}, -{x=3,y=2,class="checkbox",name="xyrot",label="Only x, y",hint="remove frx, fry"}, -{x=2,y=3,class="checkbox",name="allsize",label="Remove size/scaling",hint="fs, fscx, fscy"}, -{x=3,y=3,class="checkbox",name="scales",label="Only scaling",hint="remove fscx, fscy"}, -{x=2,y=4,class="checkbox",name="allshad",label="Remove all shadows",hint="shad, xshad, yshad"}, -{x=3,y=4,class="checkbox",name="xyshad",label="Only x, y",hint="remove xshad, yshad"}, -{x=2,y=5,class="checkbox",name="parent",label="Remove parentheses",hint="fad(e), (i)clip, pos, move, org\n(but not t)"}, -{x=3,y=5,class="checkbox",name="parent2",label="Except \\pos",hint="fad(e), (i)clip, move, org\n(but not t or pos)"}, -{x=2,y=6,width=2,class="checkbox",name="allpers",label="Remove all perspective",hint="frx, fry, frz, fax, fay, org"}, - -{x=2,y=7,width=2,class="label",label=" ~ Script Cleanup v5.0.0 ~"}, - -{x=2,y=8,width=2,class="checkbox",name="hspace",label="Remove hard spaces - \\h"}, -{x=2,y=9,class="checkbox",name="nobreak",label="Remove line breaks"}, -{x=3,y=9,class="checkbox",name="nobreak2",label="...no space",hint="Remove line breaks, leave no spaces"}, -{x=2,y=10,class="checkbox",name="nostyle",label="Delete unused styles"}, -{x=3,y=10,class="checkbox",name="nostyle2",label="Except Def.",hint="Delete unused styles except Default"}, -{x=2,y=11,class="checkbox",name="inline",label="Remove inline tags"}, -{x=3,y=11,class="checkbox",name="inline2",label="Except last",hint="Remove inline tags except the last one"}, -{x=2,y=12,width=2,class="checkbox",name="nocom",label="Remove comments from lines",hint="Removes {comments} (not tags)"}, -{x=2,y=13,width=2,class="checkbox",name="notag",label="Remove all {\\tags} from selected lines"}, +{x=0,y=0,width=3,class="checkbox",name="nots",label="Remove TS timecodes",hint="Removes timecodes like {TS 12:36}"}, +{x=0,y=1,width=3,class="checkbox",name="clear_a",label="Clear Actor field"}, +{x=0,y=2,width=3,class="checkbox",name="clear_e",label="Clear Effect field"}, +{x=0,y=3,width=3,class="checkbox",name="layers",label="Raise dialogue layer by 5"}, +{x=0,y=4,width=3,class="checkbox",name="cleantag",label="Clean up tags",hint="Fixes duplicates, \\\\, \\}, }{, and other garbage"}, +{x=0,y=5,width=3,class="checkbox",name="ctrans",label="Clean up transforms"}, +{x=0,y=6,width=3,class="checkbox",name="overlap",label="Fix 1-frame gaps/overlaps"}, +{x=0,y=7,width=3,class="checkbox",name="nocomline",label="Delete commented lines"}, +{x=0,y=8,width=3,class="checkbox",name="noempty",label="Delete empty lines"}, +{x=0,y=9,width=3,class="checkbox",name="alphacol",label="Try to fix alpha / colour tags"}, +{x=0,y=10,width=3,class="checkbox",name="spaces",label="Fix start/end/double spaces"}, +{x=0,y=12,width=3,class="checkbox",name="info",label="Print info"}, +{x=0,y=13,width=3,class="checkbox",name="all",label="ALL OF THE ABOVE"}, + +{x=4,y=0,class="label",label=" "}, + +{x=5,y=0,width=2,class="checkbox",name="allcol",label="Remove all colour tags"}, +{x=5,y=1,class="checkbox",name="allphas",label="Remove all alphas"}, +{x=6,y=1,class="checkbox",name="alpha14",label="Only 1a-4a"}, +{x=5,y=2,class="checkbox",name="allrot",label="Remove all rotations",hint="frx, fry, frz"}, +{x=6,y=2,class="checkbox",name="xyrot",label="Only x, y",hint="remove frx, fry"}, +{x=5,y=3,class="checkbox",name="allsize",label="Remove size/scaling",hint="fs, fscx, fscy"}, +{x=6,y=3,class="checkbox",name="scales",label="Only scaling",hint="remove fscx, fscy"}, +{x=5,y=4,class="checkbox",name="allshad",label="Remove all shadows",hint="shad, xshad, yshad"}, +{x=6,y=4,class="checkbox",name="xyshad",label="Only x, y",hint="remove xshad, yshad"}, +{x=5,y=5,class="checkbox",name="parent",label="Remove parentheses",hint="fad(e), (i)clip, pos, move, org\n(but not t)"}, +{x=6,y=5,class="checkbox",name="parent2",label="Except \\pos",hint="fad(e), (i)clip, move, org\n(but not t or pos)"}, +{x=5,y=6,width=2,class="checkbox",name="allpers",label="Remove all perspective",hint="frx, fry, frz, fax, fay, org"}, + +{x=5,y=7,width=2,class="label",label=" ~ Script Cleanup v5.0.0 ~"}, + +{x=5,y=8,width=2,class="checkbox",name="hspace",label="Remove hard spaces - \\h"}, +{x=5,y=9,class="checkbox",name="nobreak",label="Remove line breaks"}, +{x=6,y=9,class="checkbox",name="nobreak2",label="...no space",hint="Remove line breaks, leave no spaces"}, +{x=5,y=10,class="checkbox",name="nostyle",label="Delete unused styles"}, +{x=6,y=10,class="checkbox",name="nostyle2",label="Except Def.",hint="Delete unused styles except Default"}, +{x=5,y=11,class="checkbox",name="inline",label="Remove inline tags"}, +{x=6,y=11,class="checkbox",name="inline2",label="Except last",hint="Remove inline tags except the last one"}, +{x=5,y=12,width=2,class="checkbox",name="nocom",label="Remove comments from lines",hint="Removes {comments} (not tags)"}, +{x=5,y=13,width=2,class="checkbox",name="notag",label="Remove all {\\tags} from selected lines"}, {x=0,y=15,width=3,class="label",label=" ~ Script Cleanup v"..script_version.." ~ "}, -{x=4,y=15,class="checkbox",label="ver. info"}, +{x=5,y=15,class="checkbox",label="ver. info"}, {x=0,y=16,width=3,class="checkbox",name="text",label="Remove text"}, {x=0,y=17,width=3,class="checkbox",name="removeTextlessLines",label="Remove textless lines",hint="Removes lines without text (tag doesn't count)"}, {x=1,y=18,class="checkbox",name="textlessLinesKeepInlineComments",label="Keep inline comments",hint="Keeps lines with comments inside"}, {x=1,y=19,class="checkbox",name="textlessLinesKeepCommentedLines",label="Keep commented lines",value=true,hint="Keeps commented lines"}, -{x=4,y=0,height=20,class="label",label="|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|"}, - -{x=5,y=0,class="checkbox",name="skill",label="[start]",value=true}, -{x=6,y=0,class="checkbox",name="ikill",label="[inline]",value=true,hint="only kill, not hide"}, -{x=7,y=0,width=2,class="checkbox",name="inverse",label="[inverse/unhide]",hint="kill all except checked ones\n\n'Unhide' for 'Hide Tags'"}, -{x=7,y=1,width=2,class="checkbox",name="onlyt",label="[from \\t]",hint="remove only from transforms\n\n n/a for 'Hide Tags'"}, - -{x=5,y=1,class="checkbox",name="blur",label="blur"}, -{x=5,y=2,class="checkbox",name="border",label="bord",hint="includes xbord and ybord [not for Hide]"}, -{x=5,y=3,class="checkbox",name="shadow",label="shad",hint="includes xshad and yshad for Hide"}, -{x=5,y=4,class="checkbox",name="fsize",label="fs"}, -{x=5,y=5,class="checkbox",name="fspace",label="fsp"}, -{x=5,y=6,class="checkbox",name="scalex",label="fscx"}, -{x=5,y=7,class="checkbox",name="scaley",label="fscy"}, -{x=5,y=8,class="checkbox",name="fname",label="fn"}, -{x=5,y=9,class="checkbox",name="ital",label="i"}, -{x=5,y=10,class="checkbox",name="bold",label="b"}, -{x=5,y=11,class="checkbox",name="under",label="u"}, -{x=5,y=12,class="checkbox",name="stri",label="s"}, -{x=5,y=13,class="checkbox",name="wrap",label="q"}, -{x=5,y=14,class="checkbox",name="mask",label="p"}, - -{x=6,y=1,class="checkbox",name="bee",label="be"}, -{x=6,y=2,class="checkbox",name="color1",label="c, 1c"}, -{x=6,y=3,class="checkbox",name="color2",label="2c"}, -{x=6,y=4,class="checkbox",name="color3",label="3c"}, -{x=6,y=5,class="checkbox",name="color4",label="4c"}, -{x=6,y=6,class="checkbox",name="alpha",label="alpha"}, -{x=6,y=7,class="checkbox",name="alfa1",label="1a"}, -{x=6,y=8,class="checkbox",name="alfa2",label="2a"}, -{x=6,y=9,class="checkbox",name="alfa3",label="3a"}, -{x=6,y=10,class="checkbox",name="alfa4",label="4a"}, -{x=6,y=11,class="checkbox",name="align",label="a"}, -{x=6,y=12,class="checkbox",name="anna",label="an"}, -{x=6,y=13,class="checkbox",name="clip",label="(i)clip"}, - -{x=7,y=2,class="checkbox",name="fade",label="fad"}, -{x=7,y=3,class="checkbox",name="posi",label="pos"}, -{x=7,y=4,class="checkbox",name="move",label="move"}, -{x=7,y=5,class="checkbox",name="org",label="org"}, -{x=7,y=6,class="checkbox",name="frz",label="frz"}, -{x=7,y=7,class="checkbox",name="frx",label="frx"}, -{x=7,y=8,class="checkbox",name="fry",label="fry"}, -{x=7,y=9,class="checkbox",name="fax",label="fax"}, -{x=7,y=10,class="checkbox",name="fay",label="fay"}, -{x=7,y=11,width=2,class="checkbox",name="kara",label="k/kf/ko"}, -{x=7,y=12,class="checkbox",name="return",label="r"}, -{x=7,y=13,class="checkbox",name="trans",label="t"}, - -{x=8,y=12,height=2,class="checkbox",name="hidline",label="hide\ninline",hint='Hide ALL inline tags'}, +{x=7,y=0,height=20,class="label",label="|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|"}, + +{x=8,y=0,class="checkbox",name="skill",label="[start]",value=true}, +{x=9,y=0,class="checkbox",name="ikill",label="[inline]",value=true,hint="only kill, not hide"}, +{x=10,y=0,width=2,class="checkbox",name="inverse",label="[inverse/unhide]",hint="kill all except checked ones\n\n'Unhide' for 'Hide Tags'"}, +{x=10,y=1,width=2,class="checkbox",name="onlyt",label="[from \\t]",hint="remove only from transforms\n\n n/a for 'Hide Tags'"}, + +{x=8,y=1,class="checkbox",name="blur",label="blur"}, +{x=8,y=2,class="checkbox",name="border",label="bord",hint="includes xbord and ybord [not for Hide]"}, +{x=8,y=3,class="checkbox",name="shadow",label="shad",hint="includes xshad and yshad for Hide"}, +{x=8,y=4,class="checkbox",name="fsize",label="fs"}, +{x=8,y=5,class="checkbox",name="fspace",label="fsp"}, +{x=8,y=6,class="checkbox",name="scalex",label="fscx"}, +{x=8,y=7,class="checkbox",name="scaley",label="fscy"}, +{x=8,y=8,class="checkbox",name="fname",label="fn"}, +{x=8,y=9,class="checkbox",name="ital",label="i"}, +{x=8,y=10,class="checkbox",name="bold",label="b"}, +{x=8,y=11,class="checkbox",name="under",label="u"}, +{x=8,y=12,class="checkbox",name="stri",label="s"}, +{x=8,y=13,class="checkbox",name="wrap",label="q"}, +{x=8,y=14,class="checkbox",name="mask",label="p"}, + +{x=9,y=1,class="checkbox",name="bee",label="be"}, +{x=9,y=2,class="checkbox",name="color1",label="c, 1c"}, +{x=9,y=3,class="checkbox",name="color2",label="2c"}, +{x=9,y=4,class="checkbox",name="color3",label="3c"}, +{x=9,y=5,class="checkbox",name="color4",label="4c"}, +{x=9,y=6,class="checkbox",name="alpha",label="alpha"}, +{x=9,y=7,class="checkbox",name="alfa1",label="1a"}, +{x=9,y=8,class="checkbox",name="alfa2",label="2a"}, +{x=9,y=9,class="checkbox",name="alfa3",label="3a"}, +{x=9,y=10,class="checkbox",name="alfa4",label="4a"}, +{x=9,y=11,class="checkbox",name="align",label="a"}, +{x=9,y=12,class="checkbox",name="anna",label="an"}, +{x=9,y=13,class="checkbox",name="clip",label="(i)clip"}, + +{x=10,y=2,class="checkbox",name="fade",label="fad"}, +{x=10,y=3,class="checkbox",name="posi",label="pos"}, +{x=10,y=4,class="checkbox",name="move",label="move"}, +{x=10,y=5,class="checkbox",name="org",label="org"}, +{x=10,y=6,class="checkbox",name="frz",label="frz"}, +{x=10,y=7,class="checkbox",name="frx",label="frx"}, +{x=10,y=8,class="checkbox",name="fry",label="fry"}, +{x=10,y=9,class="checkbox",name="fax",label="fax"}, +{x=10,y=10,class="checkbox",name="fay",label="fay"}, +{x=10,y=11,width=2,class="checkbox",name="kara",label="k/kf/ko"}, +{x=10,y=12,class="checkbox",name="return",label="r"}, +{x=10,y=13,class="checkbox",name="trans",label="t"}, + +{x=11,y=12,height=2,class="checkbox",name="hidline",label="hide\ninline",hint='Hide ALL inline tags'}, } P,res=ADD(GUI, {"Run selected","Comments","Tags","Dial 5","Clean Tags","^ Kill Tags","Hide Tags","Cancer"},{ok='Run selected',cancel='Cancer'}) From 5632e1ddda0fdce68fe9be05d40bb0bed0541133 Mon Sep 17 00:00:00 2001 From: Ghegghe Date: Fri, 14 Jul 2023 00:34:16 +0200 Subject: [PATCH 12/15] fix: gui --- ua.ScriptCleanup.lua | 160 +++++++++++++++++++++---------------------- 1 file changed, 79 insertions(+), 81 deletions(-) diff --git a/ua.ScriptCleanup.lua b/ua.ScriptCleanup.lua index 6faee2b..41fba6d 100644 --- a/ua.ScriptCleanup.lua +++ b/ua.ScriptCleanup.lua @@ -735,90 +735,88 @@ GUI={ {x=0,y=12,width=3,class="checkbox",name="info",label="Print info"}, {x=0,y=13,width=3,class="checkbox",name="all",label="ALL OF THE ABOVE"}, -{x=4,y=0,class="label",label=" "}, - -{x=5,y=0,width=2,class="checkbox",name="allcol",label="Remove all colour tags"}, -{x=5,y=1,class="checkbox",name="allphas",label="Remove all alphas"}, -{x=6,y=1,class="checkbox",name="alpha14",label="Only 1a-4a"}, -{x=5,y=2,class="checkbox",name="allrot",label="Remove all rotations",hint="frx, fry, frz"}, -{x=6,y=2,class="checkbox",name="xyrot",label="Only x, y",hint="remove frx, fry"}, -{x=5,y=3,class="checkbox",name="allsize",label="Remove size/scaling",hint="fs, fscx, fscy"}, -{x=6,y=3,class="checkbox",name="scales",label="Only scaling",hint="remove fscx, fscy"}, -{x=5,y=4,class="checkbox",name="allshad",label="Remove all shadows",hint="shad, xshad, yshad"}, -{x=6,y=4,class="checkbox",name="xyshad",label="Only x, y",hint="remove xshad, yshad"}, -{x=5,y=5,class="checkbox",name="parent",label="Remove parentheses",hint="fad(e), (i)clip, pos, move, org\n(but not t)"}, -{x=6,y=5,class="checkbox",name="parent2",label="Except \\pos",hint="fad(e), (i)clip, move, org\n(but not t or pos)"}, -{x=5,y=6,width=2,class="checkbox",name="allpers",label="Remove all perspective",hint="frx, fry, frz, fax, fay, org"}, - -{x=5,y=7,width=2,class="label",label=" ~ Script Cleanup v5.0.0 ~"}, - -{x=5,y=8,width=2,class="checkbox",name="hspace",label="Remove hard spaces - \\h"}, -{x=5,y=9,class="checkbox",name="nobreak",label="Remove line breaks"}, -{x=6,y=9,class="checkbox",name="nobreak2",label="...no space",hint="Remove line breaks, leave no spaces"}, -{x=5,y=10,class="checkbox",name="nostyle",label="Delete unused styles"}, -{x=6,y=10,class="checkbox",name="nostyle2",label="Except Def.",hint="Delete unused styles except Default"}, -{x=5,y=11,class="checkbox",name="inline",label="Remove inline tags"}, -{x=6,y=11,class="checkbox",name="inline2",label="Except last",hint="Remove inline tags except the last one"}, -{x=5,y=12,width=2,class="checkbox",name="nocom",label="Remove comments from lines",hint="Removes {comments} (not tags)"}, -{x=5,y=13,width=2,class="checkbox",name="notag",label="Remove all {\\tags} from selected lines"}, - {x=0,y=15,width=3,class="label",label=" ~ Script Cleanup v"..script_version.." ~ "}, -{x=5,y=15,class="checkbox",label="ver. info"}, +{x=3,y=15,class="checkbox",label="ver. info"}, {x=0,y=16,width=3,class="checkbox",name="text",label="Remove text"}, {x=0,y=17,width=3,class="checkbox",name="removeTextlessLines",label="Remove textless lines",hint="Removes lines without text (tag doesn't count)"}, -{x=1,y=18,class="checkbox",name="textlessLinesKeepInlineComments",label="Keep inline comments",hint="Keeps lines with comments inside"}, -{x=1,y=19,class="checkbox",name="textlessLinesKeepCommentedLines",label="Keep commented lines",value=true,hint="Keeps commented lines"}, - -{x=7,y=0,height=20,class="label",label="|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|"}, - -{x=8,y=0,class="checkbox",name="skill",label="[start]",value=true}, -{x=9,y=0,class="checkbox",name="ikill",label="[inline]",value=true,hint="only kill, not hide"}, -{x=10,y=0,width=2,class="checkbox",name="inverse",label="[inverse/unhide]",hint="kill all except checked ones\n\n'Unhide' for 'Hide Tags'"}, -{x=10,y=1,width=2,class="checkbox",name="onlyt",label="[from \\t]",hint="remove only from transforms\n\n n/a for 'Hide Tags'"}, - -{x=8,y=1,class="checkbox",name="blur",label="blur"}, -{x=8,y=2,class="checkbox",name="border",label="bord",hint="includes xbord and ybord [not for Hide]"}, -{x=8,y=3,class="checkbox",name="shadow",label="shad",hint="includes xshad and yshad for Hide"}, -{x=8,y=4,class="checkbox",name="fsize",label="fs"}, -{x=8,y=5,class="checkbox",name="fspace",label="fsp"}, -{x=8,y=6,class="checkbox",name="scalex",label="fscx"}, -{x=8,y=7,class="checkbox",name="scaley",label="fscy"}, -{x=8,y=8,class="checkbox",name="fname",label="fn"}, -{x=8,y=9,class="checkbox",name="ital",label="i"}, -{x=8,y=10,class="checkbox",name="bold",label="b"}, -{x=8,y=11,class="checkbox",name="under",label="u"}, -{x=8,y=12,class="checkbox",name="stri",label="s"}, -{x=8,y=13,class="checkbox",name="wrap",label="q"}, -{x=8,y=14,class="checkbox",name="mask",label="p"}, - -{x=9,y=1,class="checkbox",name="bee",label="be"}, -{x=9,y=2,class="checkbox",name="color1",label="c, 1c"}, -{x=9,y=3,class="checkbox",name="color2",label="2c"}, -{x=9,y=4,class="checkbox",name="color3",label="3c"}, -{x=9,y=5,class="checkbox",name="color4",label="4c"}, -{x=9,y=6,class="checkbox",name="alpha",label="alpha"}, -{x=9,y=7,class="checkbox",name="alfa1",label="1a"}, -{x=9,y=8,class="checkbox",name="alfa2",label="2a"}, -{x=9,y=9,class="checkbox",name="alfa3",label="3a"}, -{x=9,y=10,class="checkbox",name="alfa4",label="4a"}, -{x=9,y=11,class="checkbox",name="align",label="a"}, -{x=9,y=12,class="checkbox",name="anna",label="an"}, -{x=9,y=13,class="checkbox",name="clip",label="(i)clip"}, - -{x=10,y=2,class="checkbox",name="fade",label="fad"}, -{x=10,y=3,class="checkbox",name="posi",label="pos"}, -{x=10,y=4,class="checkbox",name="move",label="move"}, -{x=10,y=5,class="checkbox",name="org",label="org"}, -{x=10,y=6,class="checkbox",name="frz",label="frz"}, -{x=10,y=7,class="checkbox",name="frx",label="frx"}, -{x=10,y=8,class="checkbox",name="fry",label="fry"}, -{x=10,y=9,class="checkbox",name="fax",label="fax"}, -{x=10,y=10,class="checkbox",name="fay",label="fay"}, -{x=10,y=11,width=2,class="checkbox",name="kara",label="k/kf/ko"}, -{x=10,y=12,class="checkbox",name="return",label="r"}, -{x=10,y=13,class="checkbox",name="trans",label="t"}, - -{x=11,y=12,height=2,class="checkbox",name="hidline",label="hide\ninline",hint='Hide ALL inline tags'}, +{x=1,y=18,width=2,class="checkbox",name="textlessLinesKeepInlineComments",label="Keep inline comments",hint="Keeps lines with comments inside"}, +{x=1,y=19,width=2,class="checkbox",name="textlessLinesKeepCommentedLines",label="Keep commented lines",value=true,hint="Keeps commented lines"}, + +{x=3,y=0,width=2,class="checkbox",name="allcol",label="Remove all colour tags"}, +{x=3,y=1,class="checkbox",name="allphas",label="Remove all alphas"}, +{x=4,y=1,class="checkbox",name="alpha14",label="Only 1a-4a"}, +{x=3,y=2,class="checkbox",name="allrot",label="Remove all rotations",hint="frx, fry, frz"}, +{x=4,y=2,class="checkbox",name="xyrot",label="Only x, y",hint="remove frx, fry"}, +{x=3,y=3,class="checkbox",name="allsize",label="Remove size/scaling",hint="fs, fscx, fscy"}, +{x=4,y=3,class="checkbox",name="scales",label="Only scaling",hint="remove fscx, fscy"}, +{x=3,y=4,class="checkbox",name="allshad",label="Remove all shadows",hint="shad, xshad, yshad"}, +{x=4,y=4,class="checkbox",name="xyshad",label="Only x, y",hint="remove xshad, yshad"}, +{x=3,y=5,class="checkbox",name="parent",label="Remove parentheses",hint="fad(e), (i)clip, pos, move, org\n(but not t)"}, +{x=4,y=5,class="checkbox",name="parent2",label="Except \\pos",hint="fad(e), (i)clip, move, org\n(but not t or pos)"}, +{x=3,y=6,width=2,class="checkbox",name="allpers",label="Remove all perspective",hint="frx, fry, frz, fax, fay, org"}, + +{x=3,y=7,width=2,class="label",label=" ~ Script Cleanup v5.0.0 ~"}, + +{x=3,y=8,width=2,class="checkbox",name="hspace",label="Remove hard spaces - \\h"}, +{x=3,y=9,class="checkbox",name="nobreak",label="Remove line breaks"}, +{x=4,y=9,class="checkbox",name="nobreak2",label="...no space",hint="Remove line breaks, leave no spaces"}, +{x=3,y=10,class="checkbox",name="nostyle",label="Delete unused styles"}, +{x=4,y=10,class="checkbox",name="nostyle2",label="Except Def.",hint="Delete unused styles except Default"}, +{x=3,y=11,class="checkbox",name="inline",label="Remove inline tags"}, +{x=4,y=11,class="checkbox",name="inline2",label="Except last",hint="Remove inline tags except the last one"}, +{x=3,y=12,width=2,class="checkbox",name="nocom",label="Remove comments from lines",hint="Removes {comments} (not tags)"}, +{x=3,y=13,width=2,class="checkbox",name="notag",label="Remove all {\\tags} from selected lines"}, + +{x=5,y=0,height=20,class="label",label="|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|\n|"}, + +{x=6,y=0,class="checkbox",name="skill",label="[start]",value=true}, +{x=7,y=0,class="checkbox",name="ikill",label="[inline]",value=true,hint="only kill, not hide"}, +{x=8,y=0,width=2,class="checkbox",name="inverse",label="[inverse/unhide]",hint="kill all except checked ones\n\n'Unhide' for 'Hide Tags'"}, +{x=8,y=1,width=2,class="checkbox",name="onlyt",label="[from \\t]",hint="remove only from transforms\n\n n/a for 'Hide Tags'"}, + +{x=6,y=1,class="checkbox",name="blur",label="blur"}, +{x=6,y=2,class="checkbox",name="border",label="bord",hint="includes xbord and ybord [not for Hide]"}, +{x=6,y=3,class="checkbox",name="shadow",label="shad",hint="includes xshad and yshad for Hide"}, +{x=6,y=4,class="checkbox",name="fsize",label="fs"}, +{x=6,y=5,class="checkbox",name="fspace",label="fsp"}, +{x=6,y=6,class="checkbox",name="scalex",label="fscx"}, +{x=6,y=7,class="checkbox",name="scaley",label="fscy"}, +{x=6,y=8,class="checkbox",name="fname",label="fn"}, +{x=6,y=9,class="checkbox",name="ital",label="i"}, +{x=6,y=10,class="checkbox",name="bold",label="b"}, +{x=6,y=11,class="checkbox",name="under",label="u"}, +{x=6,y=12,class="checkbox",name="stri",label="s"}, +{x=6,y=13,class="checkbox",name="wrap",label="q"}, +{x=6,y=14,class="checkbox",name="mask",label="p"}, + +{x=7,y=1,class="checkbox",name="bee",label="be"}, +{x=7,y=2,class="checkbox",name="color1",label="c, 1c"}, +{x=7,y=3,class="checkbox",name="color2",label="2c"}, +{x=7,y=4,class="checkbox",name="color3",label="3c"}, +{x=7,y=5,class="checkbox",name="color4",label="4c"}, +{x=7,y=6,class="checkbox",name="alpha",label="alpha"}, +{x=7,y=7,class="checkbox",name="alfa1",label="1a"}, +{x=7,y=8,class="checkbox",name="alfa2",label="2a"}, +{x=7,y=9,class="checkbox",name="alfa3",label="3a"}, +{x=7,y=10,class="checkbox",name="alfa4",label="4a"}, +{x=7,y=11,class="checkbox",name="align",label="a"}, +{x=7,y=12,class="checkbox",name="anna",label="an"}, +{x=7,y=13,class="checkbox",name="clip",label="(i)clip"}, + +{x=8,y=2,class="checkbox",name="fade",label="fad"}, +{x=8,y=3,class="checkbox",name="posi",label="pos"}, +{x=8,y=4,class="checkbox",name="move",label="move"}, +{x=8,y=5,class="checkbox",name="org",label="org"}, +{x=8,y=6,class="checkbox",name="frz",label="frz"}, +{x=8,y=7,class="checkbox",name="frx",label="frx"}, +{x=8,y=8,class="checkbox",name="fry",label="fry"}, +{x=8,y=9,class="checkbox",name="fax",label="fax"}, +{x=8,y=10,class="checkbox",name="fay",label="fay"}, +{x=8,y=11,width=2,class="checkbox",name="kara",label="k/kf/ko"}, +{x=8,y=12,class="checkbox",name="return",label="r"}, +{x=8,y=13,class="checkbox",name="trans",label="t"}, + +{x=9,y=12,height=2,class="checkbox",name="hidline",label="hide\ninline",hint='Hide ALL inline tags'}, } P,res=ADD(GUI, {"Run selected","Comments","Tags","Dial 5","Clean Tags","^ Kill Tags","Hide Tags","Cancer"},{ok='Run selected',cancel='Cancer'}) From a4c059788a324b1d7d32618b33e908d157a05559 Mon Sep 17 00:00:00 2001 From: Ghegghe Date: Mon, 17 Jul 2023 19:00:54 +0200 Subject: [PATCH 13/15] feat: add ver info --- ua.ScriptCleanup.lua | 66 ++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/ua.ScriptCleanup.lua b/ua.ScriptCleanup.lua index 41fba6d..0f67437 100644 --- a/ua.ScriptCleanup.lua +++ b/ua.ScriptCleanup.lua @@ -710,6 +710,33 @@ function removeTextlessLines(subs, sel, ignoreCommentedLines, keepInlineComments return newSel end +-- ver info +verInfo = "Script Cleanup v" .. script_version .. "\n" .. [[ + + What's new: + + New functions for clean your script: + - Remove text + Removes all the text from selected lines: + {tags(not removed)}text(removed){tags(not removed)} + + - Remove textless lines + Removes the lines without text from selection: + {tags} -- removed + {tags}text -- not removed + + Other options: + - Keep inline comments + {tags}{comments} + {comments} + lines like these wont be deleted + - Keep commented lines + Commented lines will be ignored + + Tag Manipulation: + Add "q" tag in tags list +]] + -- Ghegghe's end function cleanup(subs,sel,act) @@ -736,7 +763,7 @@ GUI={ {x=0,y=13,width=3,class="checkbox",name="all",label="ALL OF THE ABOVE"}, {x=0,y=15,width=3,class="label",label=" ~ Script Cleanup v"..script_version.." ~ "}, -{x=3,y=15,class="checkbox",label="ver. info"}, +{x=3,y=15,class="checkbox",name="info",label="ver. info"}, {x=0,y=16,width=3,class="checkbox",name="text",label="Remove text"}, {x=0,y=17,width=3,class="checkbox",name="removeTextlessLines",label="Remove textless lines",hint="Removes lines without text (tag doesn't count)"}, {x=1,y=18,width=2,class="checkbox",name="textlessLinesKeepInlineComments",label="Keep inline comments",hint="Keeps lines with comments inside"}, @@ -828,24 +855,29 @@ GUI={ if P=="Dial 5" then res.layers=true cleanlines(subs,sel) end if P=="Clean Tags" then res.cleantag=true cleanlines(subs,sel) end if P=="Run selected" then - C=0 for key,v in ipairs(GUI) do if v.x<=3 and res[v.name] then C=1 end end - if C==0 then t_error("Run Selected: Error - nothing selected",1) end - if res.all then - for key,v in ipairs(GUI) do if v.x>0 and v.name and v.y<15 then res[v.name]=false end end - cleanlines(subs,sel) - sel=noemptycom(subs,sel) - else cleanlines(subs,sel) - if res.nocomline and res.noempty then sel=noemptycom(subs,sel) + if res.info then + helpGUI=aegisub.dialog.display({{width=38,height=10,class="textbox",value=verInfo},{x=39,height=10,class="label",label="ScriptCleanup\nversion "..script_version}}, + {"Close"},{close='Close'}) else - if res.nocomline then sel=nocom_line(subs,sel) end - if res.noempty then sel=noempty(subs,sel) end - end - if res.removeTextlessLines then - sel = removeTextlessLines(subs, sel, res.textlessLinesKeepCommentedLines, res.textlessLinesKeepInlineComments) + C=0 for key,v in ipairs(GUI) do if v.x<=4 and res[v.name] then C=1 end end + if C==0 then t_error("Run Selected: Error - nothing selected",1) end + if res.all then + for key,v in ipairs(GUI) do if v.x>0 and v.name and v.y<15 then res[v.name]=false end end + cleanlines(subs,sel) + sel=noemptycom(subs,sel) + else cleanlines(subs,sel) + if res.nocomline and res.noempty then sel=noemptycom(subs,sel) + else + if res.nocomline then sel=nocom_line(subs,sel) end + if res.noempty then sel=noempty(subs,sel) end + end + if res.removeTextlessLines then + sel = removeTextlessLines(subs, sel, res.textlessLinesKeepCommentedLines, res.textlessLinesKeepInlineComments) + end + table.sort(sel) + if res.nostyle or res.nostyle2 then sel=nostyle(subs,sel) end + end end - table.sort(sel) - if res.nostyle or res.nostyle2 then sel=nostyle(subs,sel) end - end end if act>#subs then act=#subs end return sel,act From 41e997fd3d1e0daf7ca8744dea4186cf19786083 Mon Sep 17 00:00:00 2001 From: Ghegghe Date: Mon, 31 Jul 2023 01:55:23 +0200 Subject: [PATCH 14/15] feat: add function works on alphas --- ua.Recalculator.lua | 56 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/ua.Recalculator.lua b/ua.Recalculator.lua index f0b3e09..11390e6 100644 --- a/ua.Recalculator.lua +++ b/ua.Recalculator.lua @@ -202,7 +202,15 @@ function multiply(subs,sel) if res.clipx or res.clipy then clip=1 else clip=0 end for z,i in ipairs(sel) do progress("Processing line: "..z.."/"..#sel) - if res.byline then count=z*c linec=z altcount=z*alt else count=c linec=1 altcount=alt end + if res.byline then + count=z*c + linec=z + altcount=z*alt + else + count=c + linec=1 + altcount=alt + end if not res.alt then altcount=count alt=res.add end line=subs[i] text=line.text @@ -331,6 +339,31 @@ function multiply(subs,sel) return "\\t("..a..","..calc2(tonumber(b)).."," end) end if res.ly then line.layer=lmcalc(line.layer) end + if res.alpha then + text=text:gsub("\\alpha&H([%x]+)&", function(a) + return "\\alpha&H" .. hexAdd(a,res.add*linec) .. "&" + end) + end + if res["1a"] then + text=text:gsub("\\1a&H([%x]+)&", function(a) + return "\\1a&H" .. hexAdd(a,res.add*linec) .. "&" + end) + end + if res["2a"] then + text=text:gsub("\\2a&H([%x]+)&", function(a) + return "\\2a&H" .. hexAdd(a,res.add*linec) .. "&" + end) + end + if res["3a"] then + text=text:gsub("\\3a&H([%x]+)&", function(a) + return "\\3a&H" .. hexAdd(a,res.add*linec) .. "&" + end) + end + if res["4a"] then + text=text:gsub("\\4a&H([%x]+)&", function(a) + return "\\4a&H" .. hexAdd(a,res.add*linec) .. "&" + end) + end if res.ml then line.margin_l=lmcalc(line.margin_l) end if res.mr then line.margin_r=lmcalc(line.margin_r) end if res.mv then line.margin_t=lmcalc(line.margin_t) end @@ -347,6 +380,27 @@ function multiply(subs,sel) end end +function hexAdd(hexString, addValue) + if hexString == "FF" and addValue > 0 or + hexString == "00" and addValue < 0 then + return hexString + elseif #hexString < 3 then + local newValue = tonumber(hexString, 16) + addValue + if newValue < 0 then + newValue = 0 + elseif newValue > 255 then + newValue = 255 + end + newValue = string.format("%X", newValue) + if #newValue < 2 then + newValue = "0" .. newValue + end + return newValue + else + return nil + end +end + function lmcalc(num) if P=="Multiply" then num=round(num+num*count,0) end if P=="Add" then num=round(num+(res.add*linec),0)end From 0c3bbadcd7533d95a2da9540adc28bcea9649679 Mon Sep 17 00:00:00 2001 From: Ghegghe Date: Thu, 14 Sep 2023 18:47:00 +0200 Subject: [PATCH 15/15] feat: shift time by frame --- ua.Recalculator.lua | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/ua.Recalculator.lua b/ua.Recalculator.lua index 11390e6..76c56e3 100644 --- a/ua.Recalculator.lua +++ b/ua.Recalculator.lua @@ -92,9 +92,10 @@ STAG="^{>?\\[^}]-}" {x=6,y=3,class="checkbox",name="alpha",label="alpha"}, {x=7,y=3,class="checkbox",name="space",label="[ ]",value=true,hint="workaround for spaces with full-line GBC"}, - {x=0,y=10,width=3,class="checkbox",name="byline",label="multiply/add more with each line"}, + {x=0,y=10,width=2,class="checkbox",name="byline",label="multiply iteration"}, - {x=3,y=10,width=2,class="checkbox",name="regtag",label="regular tags",value=true}, + {x=2,y=10,class="checkbox",name="regtag",label="regular tags",value=true}, + {x=3,y=10,width=2,class="checkbox",name="shiftTimeByFrame",label="time by frame"}, {x=5,y=10,width=2,class="checkbox",name="tftag",label="tags in transforms",value=true}, {x=6,y=1,width=2,class="checkbox",name="rpt",label="repeat last"}, @@ -367,8 +368,21 @@ function multiply(subs,sel) if res.ml then line.margin_l=lmcalc(line.margin_l) end if res.mr then line.margin_r=lmcalc(line.margin_r) end if res.mv then line.margin_t=lmcalc(line.margin_t) end - if res.st then line.start_time=lmcalc(line.start_time) end - if res.et then line.end_time=lmcalc(line.end_time) end + if res.shiftTimeByFrame then + if res.st then + frame = aegisub.frame_from_ms(line.start_time) + frame = lmcalc(frame) + line.start_time = aegisub.ms_from_frame(frame) + end + if res.et then + frame = aegisub.frame_from_ms(line.end_time) + frame = lmcalc(frame) + line.end_time = aegisub.ms_from_frame(frame) + end + else + if res.st then line.start_time=lmcalc(line.start_time) end + if res.et then line.end_time=lmcalc(line.end_time) end + end if res.retxt then neg=1 text=retext(text) end if res.react then neg=1 line.actor=retext(line.actor) end