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

@@ -171,37 +171,82 @@ def cmd_revert(a):
ws = _workspace(a)
if a.all:
done = ws.revert_all(progress=print)
else:
done = ws.revert([ws.sound(n) for n in a.names], progress=print)
texts = ws.texts.revert_all(progress=print)
print("reverted %d sound(s) and %d text(s)" % (len(done), len(texts)))
return
done = ws.revert([ws.sound(n) for n in a.names], progress=print)
print("reverted %d sound(s)" % len(done))
def cmd_status(a):
ws = _workspace(a)
keys = ws.modified_keys()
if not keys:
print("no sounds modified; game audio is original")
texts = ws.texts.modified()
if not keys and not texts:
print("no sounds or texts modified; game files are original")
return
for k in keys:
s = ws.catalog.by_key.get(k)
st = ws.state(s) if s else "(other language)"
print("%-50s %s" % (s.name if s else k, st))
for k in texts:
print("%-50s %s" % (k, ws.texts.state(k)))
def cmd_export_mod(a):
from .modpack import export_mod
ws = _workspace(a)
keys = [ws.sound(n).key for n in a.names] if a.names else ws.modified_keys()
texts = [] if a.names else ws.texts.modified()
n = export_mod(ws, a.out, keys, a.title or os.path.splitext(os.path.basename(a.out))[0], a.author or "",
a.description or "")
print("wrote %s (%d sounds)" % (a.out, n))
a.description or "", texts=texts)
print("wrote %s (%d sounds, %d texts)" % (a.out, len(keys), n - len(keys)))
def cmd_import_mod(a):
from .modpack import import_mod
ws = _workspace(a)
for im in import_mod(ws, a.file, force=a.force, progress=print):
items, texts = import_mod(ws, a.file, force=a.force, progress=print)
for im in items:
print("%-8s %-46s %s" % (im.how, im.item.get("name"), im.note))
for k, _, problem in texts:
print("%-8s %-46s %s" % ("text", k, problem or "applied"))
def cmd_text(a):
"""Subtitles and menu text: find, show, set, revert."""
ws = _workspace(a)
tx = ws.texts
lang = (a.lang or ws.game.language()).upper()
if a.action == "find":
words = [w.lower() for w in a.args]
rows = []
if a.kind in ("all", "subs"):
rows += [(subtitles_key(s), s.text) for s in tx.subtitles(lang)]
if a.kind in ("all", "menu"):
rows += [("MENU:" + e.key, e.value) for e in tx.menu(lang)]
hits = [(k, v) for k, v in rows if all(w in (k + " " + v).lower() for w in words)]
for k, v in hits[:a.limit]:
print("%s\n %s" % (k, v))
print("%d match(es)%s" % (len(hits), "" if len(hits) <= a.limit else " (first %d shown)" % a.limit))
elif a.action == "show":
for k in a.args:
print("%s\n now: %s\n original: %s\n state: %s%s" % (
k, tx.current(k), tx.original(k), tx.state(k),
"" if tx.limit(k) is None else "\n room: %d characters" % tx.limit(k)))
elif a.action == "set":
if len(a.args) != 2:
raise GameError("usage: ackit text set KEY \"new text\"")
tx.apply({a.args[0]: a.args[1]}, force=a.force, progress=print)
print("set %s" % a.args[0])
elif a.action == "revert":
done = tx.revert_all(progress=print) if a.all else tx.revert(a.args, progress=print)
print("reverted %d text(s)" % len(done))
def subtitles_key(s):
from .subtitles import key
return key(s.lang, s.speech, s.line)
# --- advanced ---------------------------------------------------------------------------------
@@ -321,6 +366,12 @@ def build_parser():
s = add("revert", cmd_revert, "put original sounds back", aliases=["restore"])
s.add_argument("names", nargs="*"); s.add_argument("--all", action="store_true")
add("status", cmd_status, "list the sounds you modified")
s = add("text", cmd_text, "subtitles and menu text: find WORDS | show KEY | set KEY TEXT | revert KEY/--all")
s.add_argument("action", choices=["find", "show", "set", "revert"])
s.add_argument("args", nargs="*")
s.add_argument("--kind", choices=["all", "subs", "menu"], default="all", help="with find: what to search")
s.add_argument("--limit", type=int, default=40); s.add_argument("--all", action="store_true")
s.add_argument("--force", action="store_true", help="overwrite texts changed outside this tool")
s = add("export-mod", cmd_export_mod, "save your changes as a shareable .acmod package")
s.add_argument("out"); s.add_argument("names", nargs="*", help="default: everything you modified")
s.add_argument("--title"); s.add_argument("--author"); s.add_argument("--description")