Edit subtitles and menu text

This commit is contained in:
2026-10-09 22:36:46 +02:00
parent 5d6c2447f7
commit ef68edbe45
40 changed files with 105877 additions and 1291 deletions

View File

@@ -7,6 +7,8 @@ Outputs
data/catalog/<ARCHIVE>.csv every sound of one archive (schema: data/catalog/README.md)
data/catalog/BANK.csv in-memory sounds (soundbanks in SFX/*.bnk and the .upk packages)
data/catalog/BANK_locations.csv.gz every stored copy of them + the prefetch heads of speech lines
data/catalog/SUB_<LANG>.csv subtitles of the speech lines (one file per language)
data/catalog/SUB_locations.csv.gz every stored copy of each subtitle string
data/catalog/index.json fingerprints the CSVs were built from + counts
Run it only on clean game files (`ackit status` must say nothing is modified).
"""
@@ -20,8 +22,8 @@ import sys
import time
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from ackit import banks, settings # noqa: E402
from ackit.catalog import scan_archive, scan_banks, write_csv, hash_names # noqa: E402
from ackit import banks, settings, subtitles # noqa: E402
from ackit.catalog import scan_archive, scan_text, write_csv, hash_names # noqa: E402
from ackit.classify import USER_LABELS # noqa: E402
from ackit.game import Game, default_game_dir, wad_fingerprint # noqa: E402
from ackit.inject import read_target # noqa: E402
@@ -113,8 +115,9 @@ def main():
# in-memory sounds: loose SFX\*.bnk + banks inside the .upk packages (a few minutes)
t0 = time.time()
sounds, locs, sc = scan_banks(game, progress=lambda k, n: print(" banks: %d/%d files" % (k, n), flush=True)
if k % 500 == 0 else None, characters=charmap)
sounds, locs, sc, texts, sublocs, sub_issues = scan_text(
game, progress=lambda k, n: print(" banks + subtitles: %d/%d files" % (k, n), flush=True)
if k % 500 == 0 else None, characters=charmap)
write_csv(os.path.join(out_dir, "%s.csv" % banks.ARCHIVE), sounds)
banks.write_locations(os.path.join(out_dir, banks.LOCATIONS), locs)
g = collections.Counter(s.group for s in sounds)
@@ -128,6 +131,23 @@ def main():
"issues": ["%s: %s" % i for i in sc.issues]}
print("%s.csv: %d sounds %s, %d copies in %d files, %d prefetch heads (%.0fs)"
% (banks.ARCHIVE, len(sounds), dict(g), len(locs) - len(heads), len(sc.files), len(heads), time.time() - t0))
# subtitles (dialogue objects in the packages), one CSV per language + every stored copy
for f in os.listdir(out_dir):
if f.startswith("SUB_") and f.endswith(".csv"):
os.remove(os.path.join(out_dir, f))
for lang, rows in texts.items():
subtitles.write_texts(os.path.join(out_dir, "SUB_%s.csv" % lang), rows)
subtitles.write_locations(os.path.join(out_dir, subtitles.LOCATIONS), sublocs)
any_lang = next(iter(texts.values()), [])
index["archives"]["SUB"] = {
"fingerprint": banks.game_fingerprint(game.cooked),
"lines": {lang: len(rows) for lang, rows in sorted(texts.items())},
"speech_lines": len({s.speech for s in any_lang}),
"linked": {lang: sum(1 for s in rows if s.sound) for lang, rows in sorted(texts.items())},
"copies": len(sublocs), "issues": ["%s: %s" % i for i in sub_issues]}
print("SUB_*.csv: %d languages, %d subtitle strings, %d copies"
% (len(texts), sum(len(r) for r in texts.values()), len(sublocs)))
# flatten for catalog.load_archive
flat = {a: v for a, v in index["archives"].items()}
json.dump(dict(flat, _info=index["built_from"]), open(os.path.join(out_dir, "index.json"), "w", newline="\n"), indent=1)