Skip to content
Snippets Groups Projects
Commit 4883d895 authored by lowercasedonkey's avatar lowercasedonkey
Browse files

SC to JS converter

parent 48575e53
No related branches found
No related tags found
No related merge requests found
# Script to convert SC passages to JS.
# lowercasedonkey, here. This script was written for the "PythonScript" plugin for notepad++. https://github.com/bruderstein/PythonScript. Not a python guy, but if works somewhere else, great!
# At the moment, you can't "rerun it" on JS. Only run the code on SC, not the output. It won't update the JS.
# Update slave references
editor.rereplace(r"\$activeSlave", r"slave")
editor.rereplace(r"\$slaves\[\$i\]", r"slave")
# Update all references
editor.rereplace(r"\$", r"V\.")
# Clean up print
editor.rereplace(r"<<print (.*)>>", r"${\1}")
editor.rereplace(r"<<= (.*?)>>", r"${\1}")
# Line breaks for embedded code, beautify later
editor.rereplace(r"([a-zA-Z@].*?)<<", r"$1\n<<")
editor.rereplace(r">>([a-zA-Z,\.@ ].*?)", r">>\n\t$1")
# Raw text
editor.rereplace(r" ([a-zA-Z@\.,; ].*)", r" r.push\(`\1 `\);")
# If / else
editor.rereplace(r"<<if (.*?)>>", r"if \1 {")
editor.rereplace(r"<<elseif (.*?)>>", r"} else if \(\1\) {")
editor.rereplace(r"<<else>>", r"} else {")
editor.rereplace(r"<</if>>", r"}")
#fix paren
editor.rereplace(r"([ \n])if ([^\(].*) {", r"\1 if \(\2\) {")
editor.rereplace(r"([ \n])else if ([^\(].*) {", r"\1 else if \(\2\) {")
# run can happen directly
editor.rereplace(r"<<run (.*?)>>", r"\1;")
# Set: If it uses "=" let's assume we should let and clean up later
editor.rereplace(r"<<set (.*? =.*?)>>", r"let $1;")
editor.rereplace(r"let (slave\.)", r"$1")
editor.rereplace(r"let (V\.)", r"$1")
# Set: otherwise we are likely modifying the value
editor.rereplace(r"<<set (.*?)>>", r"$1;")
#Switch
editor.rereplace(r"<<switch (.*?)>>", r"switch \(\1\) {")
editor.rereplace(r"<</switch>>", r"}")
editor.rereplace(r"<<case (.*?)>>", r"case \1:")
editor.rereplace(r"<<default>>", r"default:")
# SC markup
editor.rereplace(r"@@\.(.*?);(.*?)@@", r"<span class=\"\1\">\2</span>")
editor.rereplace(r"@@\.(.*?);", r"<span class=\"\1\">")
editor.rereplace(r"@@", r"</span>")
# JS
editor.rereplace(r" == ", r" === ")
editor.rereplace(r" != ", r" !== ")
#fix pronouns
editor.rereplace(r"V\.He", r"\${He}")
editor.rereplace(r"V\.he", r"\${he}")
editor.rereplace(r"V\.Him", r"\${Him}")
editor.rereplace(r"V\.him", r"\${him}")
editor.rereplace(r"V\.His", r"\${His}")
editor.rereplace(r"V\.his", r"\${his}")
editor.rereplace(r"V\.Hers", r"\${Hers}")
editor.rereplace(r"V\.hers", r"\${hers}")
editor.rereplace(r"V\.Himself", r"\${Himself}")
editor.rereplace(r"V\.himself", r"\${himself}")
editor.rereplace(r"V\.Girl", r"\${Girl}")
editor.rereplace(r"V\.girl", r"\${girl}")
editor.rereplace(r"V\.Loli", r"\${Loli}")
editor.rereplace(r"V\.loli", r"\${loli}")
editor.rereplace(r"V\.Woman", r"\${Woman}")
editor.rereplace(r"V\.woman", r"\${woman}")
editor.rereplace(r"V\.Hers", r"\${Hers}")
editor.rereplace(r"V\.hers", r"\${hers}")
#fix pronouns
editor.rereplace(r"_He2", r"\${_He2}")
editor.rereplace(r"_he2", r"\${_he2}")
editor.rereplace(r"_Him2", r"\${_Him2}")
editor.rereplace(r"_him2", r"\${_him2}")
editor.rereplace(r"_His2", r"\${_His2}")
editor.rereplace(r"_his2", r"\${_his2}")
editor.rereplace(r"_Hers2", r"\${_Hers2}")
editor.rereplace(r"_hers2", r"\${_hers2}")
editor.rereplace(r"_Himself2", r"\${_Himself2}")
editor.rereplace(r"_himself2", r"\${_himself2}")
editor.rereplace(r"_Girl2", r"\${_Girl2}")
editor.rereplace(r"_girl2", r"\${_girl2}")
editor.rereplace(r"_Loli2", r"\${_Loli2}")
editor.rereplace(r"_loli2", r"\${_loli2}")
editor.rereplace(r"_Woman2", r"\${_Woman2}")
editor.rereplace(r"_woman2", r"\${_woman2}")
editor.rereplace(r"_Hers2", r"\${_Hers2}")
editor.rereplace(r"_hers2", r"\${_hers2}")
#look for variables embedded in literals
editor.rereplace(r"( r.push.*?[^{])(V\.[^ ,']*)", r"\1${\2}")
editor.rereplace(r"( r.push.*?[^{])(slave\.[^ ,']*)", r"\1${\2}")
#remove incompatible comment style
editor.rereplace(r"/%", r"/*")
editor.rereplace(r"%/", r"*/")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment