Merge branch 'feat/tl' into development

This commit is contained in:
dasemu committed 2026-10-19 05:15:18 +02:00
commit 58b4fcba46
3 files changed
+44 -4

No files matched your search

+1 -1
View File
@@ -7,7 +7,7 @@ A work is a directory containing `work.toml`, plus the folders the pipeline fill
| Table | Keys |
|---|---|
| `[work]` | `id`, `title`, `subtitle`, `author`, `translator`, `language` (`es`/`en`: About, menu and credits texts), `lyric_voice` (cast id for verse nobody speaks; default `poet_voice`), `end_text`, `menu_bg` (legacy alias of `[ui].main_menu_bg`). |
| `[ui]` | `main_menu_bg` (background asset id of the main menu and, darker, the game menu; default: `[work].menu_bg`, else the first staged `bg`). |
| `[ui]` | `main_menu_bg` (background asset id of the main menu and, darker, the game menu; default: `[work].menu_bg`, else the first staged `bg`); `language` (Ren'Py language name set as `config.default_language`, e.g. `spanish`; its strings come from `<work>/tl/<language>/*.rpy`, copied into `game/tl/`). |
| `[source]` | `gutenberg_id`, `url`, `raw_file` (cache path, relative to the work root, gitignored). |
| `[scope]` | `start_marker`, `end_marker` (whole stripped lines), `end_occurrence` (1-based, searched after the start; the end marker itself is excluded). |
| `[speakers]` | Speaker heading as printed (upper case, without its italic note) → cast id. Several headings may share one id (anonymous crowd speakers). A key with punctuation or markup (`"CORO, TUTTI"`) is matched against the whole printed line first. An unknown speaker is a parse error. |
+27 -3
View File
@@ -157,6 +157,28 @@ def scan_audio(out: Path) -> Audio:
return Audio(moods, frozenset(paths))
def copy_translations(work: Work, out: Path) -> list[Path]:
"""Copy ``<work>/tl/**/*.rpy`` into ``game/tl/`` and set ``[ui].language`` as default."""
src_root = work.path("tl")
dest_root = out / "game" / "tl"
lang_file = out / "game" / "language.rpy"
written = []
if src_root.is_dir():
shutil.rmtree(dest_root, ignore_errors=True)
for src in sorted(src_root.rglob("*.rpy")):
dest = dest_root / src.relative_to(src_root)
dest.parent.mkdir(parents=True, exist_ok=True)
shutil.copyfile(src, dest)
written.append(dest)
language = work.data.get("ui", {}).get("language")
if language:
write_text(lang_file, f"define config.default_language = {quote(language)}\n")
written.append(lang_file)
else:
lang_file.unlink(missing_ok=True)
return written
def copy_audio(work: Work, out: Path) -> list[Path]:
"""Copy ``<work>/audio/**/*.ogg`` into ``game/audio/`` keeping subdirectories."""
src_root = work.path("audio")
@@ -712,7 +734,8 @@ testcase default:
$ _test.timeout = 30.0
$ preferences.text_cps = 0
pause 1.0
click "Start"
# Actions, not label text: stock menu labels may be translated.
run Start()
@@PICK@@ advance until eval (e2e_state["end"]) timeout 900
advance until screen "main_menu" timeout 60
@@MENUS@@ assert eval (e2e_state["end"])
@@ -734,11 +757,11 @@ def render_e2e(styles: dict[str, Any], ui: dict[str, str]) -> str:
menus = (
f" click {_plain_quote(ui['credits'])}\n"
' assert screen "vn_credits"\n'
' click "Return"\n'
" run Return()\n"
' assert screen "main_menu"\n'
f" click {_plain_quote(ui['scenes'])}\n"
' assert screen "vn_scene_select"\n'
' click "Return"\n'
" run Return()\n"
' assert screen "main_menu"\n'
)
return E2E_TESTCASE.replace("@@PICK@@", pick).replace("@@MENUS@@", menus)
@@ -993,6 +1016,7 @@ def generate(
img.save(dest, "PNG")
written.append(dest)
written.extend(copy_audio(work, out))
written.extend(copy_translations(work, out))
test_file = game / E2E_FILE
test_file.unlink(missing_ok=True)
if with_test:
+16
View File
@@ -427,6 +427,22 @@ def test_scan_and_copy_audio(work, tmp_path):
assert "audio/scenes/x.ogg" in audio.files
def test_copy_translations_and_default_language(work, tmp_path):
root = tmp_path / "w"
(root / "tl/spanish").mkdir(parents=True)
(root / "tl/spanish/common.rpy").write_text("translate spanish strings:\n", encoding="utf-8")
data = {**work.data, "ui": {**work.data.get("ui", {}), "language": "spanish"}}
out = tmp_path / "out"
copied = renpy_gen.copy_translations(type(work)(root=root, data=data), out)
assert (out / "game/tl/spanish/common.rpy").is_file()
lang = out / "game/language.rpy"
assert lang in copied
assert lang.read_text(encoding="utf-8") == 'define config.default_language = "spanish"\n'
# Without [ui].language the stale file is removed.
renpy_gen.copy_translations(type(work)(root=tmp_path / "none", data=work.data), out)
assert not lang.exists()
def test_mood_directory_is_a_playlist(work, annotated):
block = scene_block(renpy_gen.render_script(work, annotated, _audio()), "lyric")
assert _music_lines(block) == [