mirror of
https://github.com/Dasemu/vnpipe.git
synced 2026-11-26 15:26:27 +00:00
feat: extract vnpipe pipeline from faust-vn
Generic "classic novels to visual novels" pipeline extracted from faust-vn (source commit 6486ab1). The work-specific data (Faust text, annotations, assets, generated project) stays in faust-vn. Changes versus the source: --work defaults to the current directory, the renpy command writes to <work root>/vn, the Ren'Py SDK is located through RENPY_SDK, and tests only use fixtures. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
ff78dc5b14
68 files changed
+7727
No files matched your search
@@ -0,0 +1,67 @@
|
||||
# Adaptation rules
|
||||
|
||||
How a play becomes a visual novel. The text is never rewritten, abridged or reordered:
|
||||
every verse line of the scoped text is shown, in order. What changes is *how* it is
|
||||
shown. Generic rules are implemented in `src/vnpipe/renpy_gen.py`; work-specific choices
|
||||
live in the work's `work.toml` (`[staging.*]`, `[[cues]]`, `[cast.*]`; see [work-config.md](work-config.md)).
|
||||
|
||||
## Principle: show less, suggest more
|
||||
|
||||
A VN tempts you to draw everything. Romantic verse drama works better when the image
|
||||
sets the mood and the words carry the scene. So:
|
||||
|
||||
1. **Draw people only when they converse.** Sprites appear in dialogue scenes.
|
||||
2. **Never draw the ineffable.** Divine or supernatural presences are a lighting change,
|
||||
a flash or a shake on the background, never a sprite. Their lines still carry a name
|
||||
and colour.
|
||||
3. **Lyric passages are full-screen text (NVL).** Poems and hymns are read over a
|
||||
background, without a dialogue box or sprites.
|
||||
4. **Choral or crowd presences belong to the background**, not drawn as several sprites.
|
||||
5. **Stage directions are narration**, shown in italics by the narrator. Directions that
|
||||
change the scene also trigger a cue (background, tint, transition). Cast lists under
|
||||
a scene heading are not shown; they only inform who is on stage.
|
||||
6. **One background per location**, plus variants only where the text itself changes
|
||||
the light (a vision, an apparition, a change of mood).
|
||||
|
||||
## Text rhythm
|
||||
|
||||
- Each scene opens with a title card (scene heading, centred, over black).
|
||||
- Verse is grouped into text boxes of at most **4 lines**, never crossing a stanza or a
|
||||
speaker change. In NVL, a whole stanza (max 8 lines) is shown before the page clears.
|
||||
- Split verse lines (a line shared between two speakers, printed deeply indented) are
|
||||
shown as their own box so the exchange keeps its speed.
|
||||
|
||||
## Sprites and expressions
|
||||
|
||||
- The annotation gives each line one emotion from a fixed vocabulary: `neutral`,
|
||||
`joyful`, `melancholic`, `solemn`, `ironic`, `angry`, `fearful`, `ecstatic`.
|
||||
- `work.toml` maps that vocabulary to the 3–4 expressions each character actually has
|
||||
(`[cast.<id>].expressions`). A text box uses the emotion of its first line.
|
||||
- Positions (`left`, `center`, `right`) come from the annotation, but the first
|
||||
position a character gets in a scene is kept for the whole scene, so nobody jumps
|
||||
around between boxes.
|
||||
- Characters with `sprite = false` are never drawn, even if annotated as on stage.
|
||||
|
||||
## Human judgment layer
|
||||
|
||||
The annotation is an LLM's first guess; `work.toml` can override it, generically:
|
||||
|
||||
- `[staging.<scene>].cast = { <char> = "<pos>" }` pins characters (sprite = true) on stage
|
||||
at fixed positions for the whole scene, overriding the annotation's `on_stage`.
|
||||
- A cue's `move = { <char> = "<pos>" }` slides a visible sprite to another position.
|
||||
- `[[overrides]] { from, to, emotion }` forces the emotion of an inclusive line range
|
||||
(same scene) before expression mapping.
|
||||
|
||||
Stage-direction lines never change who is on stage (they keep the previous box's
|
||||
`on_stage`). Unknown line ids, characters, positions or emotions are errors at generation.
|
||||
|
||||
## Transitions
|
||||
|
||||
- `dissolve` between expressions and on sprite entry/exit, `fade` between scenes,
|
||||
`slow` (2 s dissolve) for light changes, `flash` for supernatural apparitions.
|
||||
|
||||
## Music
|
||||
|
||||
Every line carries an optional music mood (`contemplative`, `comic`, `sacred`,
|
||||
`ominous`, `mystical`, `none`). The prototype ships without audio; the generator emits
|
||||
`play music` only when `game/audio/<mood>.ogg` exists, so adding files is enough.
|
||||
@@ -0,0 +1,70 @@
|
||||
# Annotation stage
|
||||
|
||||
Turns `data/parsed.json` into `data/annotated.json`: every parsed line gets an `ann` block
|
||||
(emotion, who is on stage and where, music). Judgement calls are made by LLM sub-agents;
|
||||
`vnpipe annotate` only prepares their input, checks their output and merges it.
|
||||
|
||||
```
|
||||
parsed.json ──chunk──▶ annotations/chunks/<chunk_id>.json (annotator input)
|
||||
sub-agent ──────────▶ annotations/cache/<chunk_id>.json (annotator output)
|
||||
──merge──▶ data/annotated.json
|
||||
```
|
||||
|
||||
## Chunks
|
||||
|
||||
- Id `<scene_id>_cNN`. A chunk never crosses a scene and holds at most 60 lines. Splits
|
||||
prefer speech boundaries, then stanza boundaries, and only then cut mid-stanza.
|
||||
- `input_sha256` is the SHA-256 of the canonical JSON of the chunk without that field. It
|
||||
includes `prompt_version` (SHA-256 of `src/vnpipe/prompts/annotate.md`), so editing the
|
||||
prompt, the text, `work.toml` scenes/cast or the schema enums invalidates the cache.
|
||||
- Contents: `scene`, `allowed` (speakers, characters, locations, emotions, positions,
|
||||
music), `context_before` (up to 6 preceding lines, read-only) and `lines`, each with a
|
||||
`defaults` block that is deterministic and must be copied verbatim:
|
||||
- verse with a speaker: `dialogue` / that speaker;
|
||||
- verse without speaker: `narration` / `[work].lyric_voice` from `work.toml`;
|
||||
- direction and cast list: `stage_direction` / `narrator`;
|
||||
- `location` and `time_of_day` from the scene config.
|
||||
- `allowed.characters` are the cast ids except `narrator` and the lyric voice. Cast members
|
||||
with `sprite = false` are valid on stage; the Ren'Py generator filters them.
|
||||
|
||||
## Cache
|
||||
|
||||
One file per chunk, `annotation.schema.json`: `chunk_id`, `input_sha256` (copied from the
|
||||
chunk) and `annotations` (one per line, in order). Cache files are never deleted by the
|
||||
tool; a cache whose hash no longer matches is simply `stale` and gets redone.
|
||||
|
||||
## Commands
|
||||
|
||||
| Command | Effect |
|
||||
|---|---|
|
||||
| `vnpipe annotate chunk` | Write chunk files, remove chunk files that no longer exist. |
|
||||
| `vnpipe annotate status [id ...]` | Per chunk `ok`, `missing`, `stale` or `invalid` (with reason) plus a summary. Always exits 0. |
|
||||
| `vnpipe annotate prompt <id>` | Print the full annotator instructions for a chunk (absolute paths filled in). |
|
||||
| `vnpipe annotate merge [--fallback]` | Validate every cache and write `data/annotated.json`. |
|
||||
|
||||
A cache is `ok` when it validates against the schema, carries the chunk's hash, covers exactly
|
||||
the chunk's line ids in order, keeps `speaker`/`kind`/`location`/`time_of_day` equal to the
|
||||
defaults, and uses only allowed characters (each at most once per line). `stale` means the
|
||||
hash differs; everything else wrong is `invalid`.
|
||||
|
||||
`merge` without `--fallback` prints every problem and exits 1 without writing anything. With
|
||||
`--fallback`, each non-ok chunk gets deterministic annotations (defaults, emotion `neutral`,
|
||||
music `null`, on stage: the speakers seen so far in the scene who have sprites, placed
|
||||
left/right/center in order of appearance), a warning is printed, and the chunk ids are listed
|
||||
in `fallback_chunks`. Output is byte-identical across runs.
|
||||
|
||||
## Running the annotators
|
||||
|
||||
1. `vnpipe annotate chunk`
|
||||
2. For each chunk that is not `ok` in `vnpipe annotate status`, start one cheap-model
|
||||
sub-agent whose whole instruction is the output of `vnpipe annotate prompt <chunk_id>`.
|
||||
Chunks are independent, so run them in parallel.
|
||||
3. `vnpipe annotate status` until everything is `ok`; relaunch only the failing chunks.
|
||||
4. `vnpipe annotate merge`.
|
||||
|
||||
## Resumability
|
||||
|
||||
Re-running is safe: only `missing`, `stale` and `invalid` chunks need work. After changing the
|
||||
prompt every chunk becomes stale; after changing the text only the affected chunks do. Always
|
||||
run `vnpipe annotate chunk` after changing `parsed.json`, `work.toml` or the prompt, before
|
||||
starting annotators (`status` warns when chunk files are out of date).
|
||||
@@ -0,0 +1,49 @@
|
||||
# Pipeline overview
|
||||
|
||||
`vnpipe` turns a public-domain text from Project Gutenberg into a Ren'Py visual novel.
|
||||
A *work* (one text) is a directory with a `work.toml` (see [work-config.md](work-config.md));
|
||||
all paths below are relative to the work root. Adding a work needs a new `work.toml` plus art,
|
||||
no code changes.
|
||||
|
||||
```
|
||||
Gutenberg .txt ──fetch──▶ data/raw/ (cached, gitignored)
|
||||
──parse──▶ data/play.txt (header/footer stripped, scope cut)
|
||||
data/parsed.json (scenes, speakers, verse lines, directions)
|
||||
──chunk──▶ annotations/chunks/*.json (LLM work units)
|
||||
LLM sub-agents ─────▶ annotations/cache/*.json (one file per chunk, keyed by hash)
|
||||
──merge──▶ data/annotated.json (schema-validated, complete)
|
||||
art (any generator) ──▶ assets/assets.json + images (manifest, sha256, status)
|
||||
──renpy──▶ vn/ (generated Ren'Py project)
|
||||
```
|
||||
|
||||
Every stage is a `vnpipe` subcommand, deterministic given its inputs, and idempotent
|
||||
(re-running produces byte-identical output). The only non-deterministic steps, LLM annotation
|
||||
and image generation, write to caches keyed by content hash, so they are resumable and never
|
||||
redone unless their input changes.
|
||||
|
||||
## Stages
|
||||
|
||||
| Stage | Commands | Module |
|
||||
|---|---|---|
|
||||
| Text | `fetch`, `parse` | `text.py` |
|
||||
| Annotation | `annotate chunk/status/prompt/merge` ([details](annotation.md)) | `annotate.py` |
|
||||
| Assets | `assets prompt/import/process/status/placeholders/sheet` | `assets.py` |
|
||||
| Ren'Py | `renpy [--from-parsed] [--with-test] [--out DIR]` | `renpy_gen.py` |
|
||||
|
||||
`--work DIR` (before the subcommand) selects the work root; default is the current directory.
|
||||
|
||||
## Source layout
|
||||
|
||||
| Path | Purpose |
|
||||
|---|---|
|
||||
| `src/vnpipe/` | Work-agnostic pipeline code |
|
||||
| `src/vnpipe/schemas/` | JSON Schemas: parsed text, annotation, annotated text, asset manifest |
|
||||
| `src/vnpipe/prompts/annotate.md` | Annotator instructions (its hash versions the cache) |
|
||||
| `src/vnpipe/renpy_templates/` | Default Ren'Py GUI, screens and fonts |
|
||||
| `tests/` | Unit tests on `tests/fixtures/` (a mini work); the Ren'Py SDK tests need `RENPY_SDK` |
|
||||
|
||||
## Asset manifest
|
||||
|
||||
`assets/assets.json` lists backgrounds and sprites with a status (`processed`, `approved`,
|
||||
`placeholder`, ...). Anything missing or unusable is replaced by a generated placeholder, so
|
||||
the game always runs.
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
# Running, linting and building the game
|
||||
|
||||
The Ren'Py project in `<work>/vn/` is generated; never edit it by hand. Commands below run
|
||||
from the work root (the directory with `work.toml`); `RENPY_SDK` is the SDK directory
|
||||
(e.g. `export RENPY_SDK=/path/to/renpy-sdk`).
|
||||
|
||||
## 1. Ren'Py SDK
|
||||
|
||||
The SDK is not committed. Install **Ren'Py 8.5.3** (SDK
|
||||
archive from <https://www.renpy.org/latest.html>, `renpy-8.5.3-sdk.tar.bz2`) so that
|
||||
`$RENPY_SDK/renpy.sh` exists:
|
||||
|
||||
```sh
|
||||
tar -xjf renpy-8.5.3-sdk.tar.bz2 && mv renpy-8.5.3-sdk "$RENPY_SDK"
|
||||
```
|
||||
|
||||
The SDK already contains the web runtime (`$RENPY_SDK/web`) and the Linux, Windows
|
||||
and macOS distribution templates. Inside the sandbox set `HOME=$TMPDIR/renpy-home` for
|
||||
SDK commands, since Ren'Py writes to `~/.renpy`.
|
||||
|
||||
## 2. Regenerate the project
|
||||
|
||||
```sh
|
||||
uv run vnpipe renpy # from data/annotated.json
|
||||
uv run vnpipe renpy --from-parsed # trivial annotations built from parsed.json
|
||||
uv run vnpipe renpy --out some/dir # default output: <work>/vn
|
||||
```
|
||||
|
||||
Generation is deterministic: running it twice gives identical files (no timestamps).
|
||||
It rewrites `game/{options,gui,screens,support,characters,images,script}.rpy`,
|
||||
`game/gui/`, `game/fonts/` and `game/images/`; anything else (for example `game/audio/`)
|
||||
is left alone. Music only appears in the script for moods that have a matching
|
||||
`game/audio/<mood>.ogg`, so drop files there and regenerate.
|
||||
|
||||
Images come from `assets/assets.json` (statuses `processed`, `approved`,
|
||||
`placeholder`); anything missing or unusable is replaced by a generated placeholder so
|
||||
the game always runs.
|
||||
|
||||
### GUI template and licences
|
||||
|
||||
`src/vnpipe/renpy_templates/` (in this repo) holds the default Ren'Py GUI (`gui.rpy`, `screens.rpy`,
|
||||
`options.rpy` and `gui/*.png`). It was generated once with the SDK's own command and then
|
||||
edited minimally (dark palette, ivory text, accent `#c9a25b`, Roboto Slab font, NVL
|
||||
tweaks, `@@TOKEN@@` placeholders for title/build name/about text/menu background):
|
||||
|
||||
```sh
|
||||
"$RENPY_SDK"/renpy.sh $RENPY_SDK/launcher generate_gui OUT --width 1920 --height 1080 \
|
||||
--accent '#c9a25b' --boring '#14110e' --template "$RENPY_SDK/gui" --start
|
||||
```
|
||||
|
||||
These files are part of Ren'Py (MIT licence, Tom Rothamel and contributors). The font
|
||||
`game/fonts/RobotoSlab-*.ttf` is Roboto Slab (Apache 2.0), taken from the SDK
|
||||
documentation assets.
|
||||
|
||||
## 3. Lint
|
||||
|
||||
```sh
|
||||
HOME=$TMPDIR/renpy-home "$RENPY_SDK"/renpy.sh vn lint
|
||||
```
|
||||
|
||||
The expected result is a statistics block with no warnings above it.
|
||||
|
||||
## 3b. End-to-end playthrough test
|
||||
|
||||
Lint does not catch runtime errors (missing GUI images, display bugs). `--with-test` also
|
||||
writes `game/e2e_test.rpy`, a Ren'Py `testcase` that clicks "Start", advances through the
|
||||
whole game up to the final card (`label the_end`) and back to the main menu, failing on any
|
||||
exception (`traceback.txt`). Use a throw-away output directory so the test file never ends
|
||||
up in `vn/` or in a build:
|
||||
|
||||
```sh
|
||||
uv run vnpipe renpy --with-test --out build/e2e
|
||||
HOME=$TMPDIR/renpy-home SDL_VIDEODRIVER=dummy SDL_AUDIODRIVER=dummy RENPY_RENDERER=sw \
|
||||
"$RENPY_SDK"/renpy.sh build/e2e test
|
||||
```
|
||||
|
||||
The headless run needs the software renderer (`RENPY_RENDERER=sw`, no GL under the dummy
|
||||
video driver); matrix tints are therefore not rendered but all game logic is exercised.
|
||||
`tests/test_renpy_gen.py` runs this for the fixture work when the SDK exists (set
|
||||
`RENPY_SDK`; slow: about a minute). On a desktop with a display, drop the three variables.
|
||||
|
||||
## 4. Play
|
||||
|
||||
```sh
|
||||
"$RENPY_SDK"/renpy.sh vn
|
||||
```
|
||||
|
||||
## 5. Builds (output under `build/`, gitignored)
|
||||
|
||||
```sh
|
||||
# Web (HTML5)
|
||||
"$RENPY_SDK"/renpy.sh $RENPY_SDK/launcher web_build vn --destination build/web
|
||||
python3 -m http.server -d build/web 8000 # then open http://localhost:8000
|
||||
|
||||
# Linux desktop
|
||||
"$RENPY_SDK"/renpy.sh $RENPY_SDK/launcher distribute vn --package linux --destination build/dist
|
||||
```
|
||||
|
||||
`--package` also accepts `win` and `mac`; omit it to build every package. The web build
|
||||
also leaves a `build/web.zip` next to the folder. A web build writes
|
||||
`vn/progressive_download.txt`; delete it (it is not part of the generated project).
|
||||
@@ -0,0 +1,24 @@
|
||||
# Work configuration (`work.toml`)
|
||||
|
||||
A work is a directory containing `work.toml`, plus the folders the pipeline fills:
|
||||
`data/`, `annotations/`, `assets/` and the generated `vn/`. A complete example is the
|
||||
`faust-vn` repo. Keys:
|
||||
|
||||
| Table | Keys |
|
||||
|---|---|
|
||||
| `[work]` | `id`, `title`, `subtitle`, `author`, `translator`, `language` (`es`/`en`, used for the About text), `lyric_voice` (cast id for verse nobody speaks; default `poet_voice`), `end_text`, `menu_bg` (background asset id for the main menu; default: first staged `bg`). |
|
||||
| `[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) → cast id. An unknown speaker is a parse error. |
|
||||
| `[[scenes]]` | `heading` (as printed), `id`, `location`, `time_of_day`. |
|
||||
| `[cast.<id>]` | `name` (shown in the dialogue box), `color`, `sprite` (default `true`; `false` = never drawn), `expressions` (annotation emotion → sprite expression; needs `neutral`). |
|
||||
| `[staging.<scene id>]` | `bg` (background shown after the title card), `mode` (`adv` or `nvl`), `cast = { <char> = "left\|center\|right" }` pins sprite characters for the whole scene. |
|
||||
| `[[cues]]` | `at` (line id; fires right before it) plus any of `bg`, `transition` (`dissolve`, `fade`, `flash`, `slow`), `tint` (`none`, `dark`, `red`), `mode`, `hide_all`, `shake`, `move = { <char> = "<pos>" }`. |
|
||||
| `[[overrides]]` | `from`, `to` (inclusive line ids in one scene), `emotion`: forces the emotion before expression mapping. |
|
||||
|
||||
Emotions: `neutral`, `joyful`, `melancholic`, `solemn`, `ironic`, `angry`, `fearful`, `ecstatic`.
|
||||
Unknown line ids, characters, positions or emotions are errors at generation. See
|
||||
[adaptation-rules.md](adaptation-rules.md) for how these choices are meant to be used.
|
||||
|
||||
Asset ids (`bg_*`, sprite names) are defined in the work's `assets/assets.json`; a missing
|
||||
image is replaced by a placeholder.
|
||||
Reference in new issue
Block a user