Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion index.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,26 @@ def process_scripts(data: Data, decompiled_dir: Path) -> ScriptIndex:
return index


def annotate_line(line: str, data: Data) -> str:
def quote(string: str) -> str:
if data.game == 'undertale':
# Undertale's decompiled GML doesn't use backslash escapes.
# But for nested quotes this is easier/more readable.
return '"' + string.replace('"', '\\"') + '"'
return json.dumps(string, ensure_ascii=False)

keys: list[str] = re.findall(
r'scr_(?:84_get_lang_string(?:_ch1)?|gettext)\("([a-zA-Z0-9_-]+)"\)',
line,
flags=re.IGNORECASE,
)
if keys:
line += ' // ' + ', '.join(
quote(data.get_localized_string_ch1(key)) for key in keys
)
return line


def write_index(index: ScriptIndex, data: Data, output_dir: Path) -> None:
with open(output_dir / 'index.html', 'w', encoding='utf-8') as f:
env = Environment(loader=FileSystemLoader('templates'))
Expand All @@ -116,7 +136,14 @@ def write_index(index: ScriptIndex, data: Data, output_dir: Path) -> None:
)
)
with open(output_dir / 'index.json', 'w', encoding='utf-8') as f:
json.dump(index.text, f, separators=(',', ':'))
json.dump(
{
filename: [annotate_line(line, data) for line in lines]
for filename, lines in index.text.items()
},
f,
separators=(',', ':'),
)


if __name__ == '__main__':
Expand Down
Loading