Created
September 14, 2021 00:51
-
-
Save mwpenny/7b104d682bbb618a0532d1258964796b to your computer and use it in GitHub Desktop.
Script to extract hard-coded VVVVVV scripts into separate .vsc files
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
#!/usr/bin/python3 | |
import os | |
import re | |
import sys | |
SCRIPT_REGEX = re.compile('if \(.+?"(.+?)".+?\).+?lines\[\] = {\n(.+?)}', re.MULTILINE | re.DOTALL) | |
LINE_CONTENT_REGEX = re.compile('^\s{8}(\S)', re.MULTILINE) | |
if len(sys.argv) < 3: | |
print(f'Usage: {sys.argv[0]} <input c++ file> <output directory>') | |
script_cpp_file, out_dir = sys.argv[1:3] | |
matches = [] | |
with open(script_cpp_file, 'r') as in_file: | |
contents = in_file.read() | |
matches = SCRIPT_REGEX.findall(contents) | |
for match in matches: | |
script_name, script_body = match | |
# Hack to skip false positive match | |
if script_name == 'custom_': | |
continue | |
# Fix formatting and strip C++ characters | |
script_body = script_body.replace('\t', '') | |
script_body = LINE_CONTENT_REGEX.sub('\\1', script_body) | |
script_body = script_body.replace('",', '') | |
script_body = script_body.replace('" ,', '') | |
script_body = script_body.replace('"', '') | |
script_body = script_body.replace('// ', '# ') | |
script_body = script_body.replace('//', '# ') | |
script_body = script_body.strip() | |
with open(os.path.join(out_dir, f'{script_name}.vsc'), 'w') as out_file: | |
print(f'Writing {out_file.name}') | |
out_file.write(script_body) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment