Skip to content

Commit

Permalink
[Honorary] Create script to rightfully remove honoraries (#51)
Browse files Browse the repository at this point in the history
* [Honorary] New script (0.1.0)

* [Honorary] Add to depctrl
  • Loading branch information
petzku authored Aug 26, 2024
1 parent 3da14d3 commit 1e4fec6
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
24 changes: 24 additions & 0 deletions DependencyControl.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,30 @@
]
}
},
"petzku.Honorary": {
"fileBaseUrl": "@{fileBaseUrl}/@{channel}/macros/@{namespace}",
"url": "@{baseUrl}#@{namespace}",
"author": "petzku",
"name": "Honorary",
"description": "Rightfully restore (or remove) honoraries easily by inserting autoswapper bits",
"channels": {
"stable": {
"version": "0.1.0",
"released": "2024-08-26",
"default": true,
"files": [
{
"name": ".moon",
"url": "@{fileBaseUrl}@{fileName}",
"sha1": "373625e67f8d0d87ff606856afb5fa1ce646dd3b"
}
]
}
},
"changelog": {
"0.1.0": ["Add DependencyControl"]
}
},
"petzku.JumpToNextPlus": {
"fileBaseUrl": "@{fileBaseUrl}/@{channel}/macros/@{namespace}",
"url": "@{baseUrl}#@{namespace}",
Expand Down
55 changes: 55 additions & 0 deletions macros/petzku.Honorary.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
-- Copyright (c) 2024 petzku <[email protected]>

export script_name = "Honorary"
export script_description = "Rightfully restore (or remove) honoraries easily by inserting autoswapper bits"
export script_author = "petzku"
export script_namespace = "petzku.Honorary"
export script_version = "0.1.0"


_add_swap = (line, idx) ->
beg, den = line.text\sub(1, idx-1), line.text\sub(idx)
line.text = beg .. "{**}" .. den
-- cursor at end of this: {**_}
aegisub.gui.set_cursor idx + 3
line

_enable = (line) ->
ss, se = aegisub.gui.get_selection!
beg = line.text\sub 1, ss-1
sel = line.text\sub ss, se-1
den = line.text\sub se
line.text = "#{beg}{*}#{sel}{*}#{den}"
-- at second {*_}
aegisub.gui.set_cursor #beg + #sel + 5
line

_disable = (line) ->
ss, se = aegisub.gui.get_selection!
beg = line.text\sub 1, ss-1
sel = line.text\sub ss, se-1
den = line.text\sub se
line.text = "#{beg}{**#{sel}}#{den}"
-- before swap: beg_{**sel}
aegisub.gui.set_cursor #beg
line


main = (line, fun) ->
-- if zero-length selection, just add the swap thing
ss, se = aegisub.gui.get_selection!
if ss == se
_add_swap line, ss
else
fun line


main_en = (sub, _, act) ->
sub[act] = main sub[act], _enable

main_dis = (sub, _, act) ->
sub[act] = main sub[act], _disable


aegisub.register_macro "#{script_name}/Enable", "Rightfully restore the honorary", main_en
aegisub.register_macro "#{script_name}/Disable", "Rightfully remove the honorary", main_dis

0 comments on commit 1e4fec6

Please sign in to comment.