diff options
| author | coco875 <59367621+coco875@users.noreply.github.com> | 2024-01-21 05:22:35 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-20 21:22:35 -0700 |
| commit | 639fec14583decbebba6bc069157884bda17f054 (patch) | |
| tree | b23be0b57cd6813d857cd132bfcacf18480a3b35 /python_convert.py | |
| parent | 1b9a6f4e24d52cc7a8d51181af8f02db8d28589a (diff) | |
place surface type const and unassemble flag in vtx and document effects (#553)
* place surface type const and unassemble flag in vtx
Diffstat (limited to 'python_convert.py')
| -rw-r--r-- | python_convert.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/python_convert.py b/python_convert.py new file mode 100644 index 000000000..eca14bf12 --- /dev/null +++ b/python_convert.py @@ -0,0 +1,35 @@ +import re +import argparse + +def convert(file): + open_file = open(file, 'r') + lines = open_file.readlines() + lines_out = [] + for line in lines: + if re.match(r" *\{\{ *-*\d+, *-*\d+, *-*\d+\}, *\{ *-*\d+, *-*\d+\}, *\{.*, *.*, *.*, *.*\}\},\n", line): + get_number:str = re.findall(r"\{\{ *-*\d+, *-*\d+, *-*\d+\}, *\{ *-*\d+, *-*\d+}, *\{(.*, *.*, *.*), *.*\}\},", line) + if get_number[0].startswith("MACRO_COLOR_FLAG"): + lines_out.append(line) + continue + r, g, b = get_number[0].split(',') + r = int(r.strip(), 16) + g = int(g.strip(), 16) + b = int(b.strip(), 16) + flag = r & 0b11 | (g<<2) & 0b1100 + r = r & ~0b11 + g = g & ~0b11 + out = f"MACRO_COLOR_FLAG({r:#04x}, {g:#04x}, {b:#04x}, {flag})" + lines_out.append(re.sub(r"( *\{\{ *-*\d+, *-*\d+, *-*\d+\}, *\{ *-*\d+, *-*\d+\}, *\{).*, *.*, *.*(, *.*\}\},\n)", fr"\1{out}\2", line)) + else: + lines_out.append(line) + + return lines_out + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='Convert colors') + parser.add_argument('file', metavar='file', type=str, help='input file', nargs='+') + args = parser.parse_args() + for file in args.file: + lines = convert(file) + open_file = open(file, 'w') + open_file.writelines(lines)
\ No newline at end of file |
