Skip to content

Commit 8b73b6c

Browse files
authored
Add Undertale textdata reading
1 parent ea75621 commit 8b73b6c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

data.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import hashlib
22
import json
3+
import re
34
from dataclasses import dataclass
45
from pathlib import Path
56
from typing import Any, Dict, List, Optional
@@ -36,6 +37,20 @@ def load_json(self, filename: str) -> Any:
3637
with open(json_file, 'r') as file:
3738
return json.load(file)
3839

40+
def load_textdata(self, scriptname: str) -> Any:
41+
script_dir = get_script_path()
42+
lang_file = script_dir / 'out' / 'raw' / f'{scriptname}.gml'
43+
ret = {}
44+
textdata_regex = re.compile(r"ds_map_add\(global\.text_data_[a-z]+, \"([a-zA-Z0-9_]+)\", ([\"'])(.*)\2\)")
45+
with open(lang_file, 'r') as file:
46+
for line in file.readlines():
47+
if not line.startswith("ds_map_add"):
48+
continue
49+
line = line.replace("' + \"'\" + '", "'").replace('" + \'"\' + "', '"')
50+
matches = textdata_regex.match(line)
51+
ret[matches[1]] = matches[3]
52+
return ret
53+
3954
def load_enemies(self) -> List[str]:
4055
return self.load_json('enemies')
4156

@@ -51,6 +66,8 @@ def load_sums(self) -> Dict[str, str]:
5166
return self.load_json('sums')
5267

5368
def load_lang(self) -> Dict[str, str]:
69+
if self.game == 'undertale':
70+
return self.load_textdata('gml_Script_textdata_en')
5471
return self.load_json('lang_en')
5572

5673
def load_config(self) -> Config:

0 commit comments

Comments
 (0)