-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Honorary] Create script to rightfully remove honoraries (#51)
* [Honorary] New script (0.1.0) * [Honorary] Add to depctrl
- Loading branch information
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |