diff options
author | Astatin <[email protected]> | 2024-10-31 16:12:46 +0900 |
---|---|---|
committer | Astatin <[email protected]> | 2024-10-31 16:12:46 +0900 |
commit | 0a203e404468bb0822657d309ca8168bae2fd24b (patch) | |
tree | 64fb814c8992d9f9b329d7215fa868bcb868e7bf /scripts | |
parent | a69ff95615b9ef4ed1ef2e0dbe42bf64b36e25b0 (diff) |
Add script to generate dialogue data from text
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/generate_from_gbtxt.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/scripts/generate_from_gbtxt.py b/scripts/generate_from_gbtxt.py new file mode 100644 index 0000000..f31ed04 --- /dev/null +++ b/scripts/generate_from_gbtxt.py @@ -0,0 +1,54 @@ +import sys + +if len(sys.argv) < 2: + raise ValueError("Must have gbtxt file in first argument") + +gbtxt_filename = sys.argv[1] + +gbtxt_file = open(gbtxt_filename, 'r') + + +def ascii_to_gbtext_format(c): + c = c.upper() + match c: + case c if c <= '9' and c >= '0': + return ord(c) - ord('0') + 0x80 + case c if c <= 'Z' and c >= 'A': + return ord(c) - ord('A') + 0x80 + 10 + case ':': + return 0xaa + case '"': + return 0xa9 + case "'": + return 0xa8 + case ',': + return 0xa7 + case '?': + return 0xa6 + case '!': + return 0xa5 + case '.': + return 0xa4 + case ' ': + return 0x00 + case _: + raise ValueError("Char \"" + c + "\" is not in the allowed charset") + +for line in gbtxt_file: + line = line.strip() + + if len(line) == 0: + continue + + if line[0] == '#': + continue + + if not ':' in line: + raise ValueError("Text without label is not allowed") + + label = line[:line.index(':') + 1] + text = line[line.index(':') + 1:].strip() + + print(label) + + print(".DB", ", ".join([hex(ascii_to_gbtext_format(c)) for c in text]) + ", 0xff") |