Files
logic-puzzle/docs/STORY_PACKAGES.md
T
2026-11-13 10:18:42 +01:00

283 lines
14 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Story packages and translations
The library is an offline catalogue in `assets/library.json`. Adding a standard
story means adding JSON and assets, registering one catalogue entry, and rebuilding
the app. It does not require a new screen or changes to the puzzle engine.
`assets/stories/paper-boat/` is a complete, small example in English and German.
The original Mara story remains available with its existing saves and narration.
## Add a story
1. Copy the `paper-boat` folder to `assets/stories/<story-id>/`.
2. Give the story a unique, permanent lowercase ID (letters, digits and hyphens).
3. Edit its campaign, notebook and translation files. Keep page and puzzle IDs
stable once the story has shipped.
4. Add an entry to `assets/library.json` and list every new asset directory in
`pubspec.yaml`. Flutter directory declarations are not recursive; include
translation, artwork and audio subdirectories explicitly.
5. Run `flutter analyze` and `flutter test`. The library tests load every registered
story in every declared language and check that each puzzle has one solution.
Example catalogue entry:
```json
{
"id": "paper-boat",
"title": "The paper boat",
"description": "A short story about a small journey.",
"coverAsset": "assets/artwork/little-boat-vignette-v1.png",
"defaultLanguage": "en",
"campaignAsset": "assets/stories/paper-boat/campaign.json",
"notebookAsset": "assets/stories/paper-boat/notebook.json",
"initiallyAccessible": 0,
"languages": {
"en": {"label": "English", "fontFamily": "MaraHand"},
"de": {
"label": "Deutsch",
"fontFamily": "MaraHand",
"asset": "assets/stories/paper-boat/locales/de.json"
}
}
}
```
`presentation` defaults to `standard`. The optional `mara` presentation preserves
the original folded-note and repair interactions in `lib/ui/mara_story.dart`;
new stories normally use the standard renderer. New *kinds* of interactive pages
still need renderer code; ordinary text, pictures, puzzles and memories do not.
`continueAt` is an optional campaign index for a book whose initial notebook pages
lead into further briefing/puzzle/memory screens. Without it, the final notebook
page returns to that story's contents.
## Campaign and chapters
`campaign.json` contains `premise` and a `levels` list. Each level supplies:
| Field | Meaning |
| --- | --- |
| `id` | Permanent puzzle ID, unique within this story; letters, digits, `.`, `_`, `-` |
| `chapterId` | Permanent chapter ID; levels belonging to a chapter must be contiguous |
| `chapter` | Display name of that chapter |
| `title`, `object` | Puzzle title and name of the discovered object |
| `before`, `after` | Passages before and after the puzzle |
| `beforeContinuation`, `afterContinuation` | Optional additional passages |
| `size` | Square grid size, default 7; supported range 2–10 |
| `picture` | Exactly `size × size` digits, each `0` or `1`, in row order |
| `clues` | Comma-separated zero-based cell indices for fixed clues; `""` for none |
| `areas` | Semicolon-separated `top,left,height,width` rectangles; `""` for none |
| `illustrationAsset` | Optional discovery image |
Chapter counts and lengths are derived from `chapterId`; neither twelve puzzles
nor four puzzles per chapter are required. Solve access advances through levels;
reading ahead saves unfinished marks and does not award puzzle completion.
## Notebook pages
`notebook.json` contains a `pages` list in reading order. Every page has a stable
`id`, a `title`, and a `type`: `dedication`, `entry`, `puzzle`, `memory`, `note`,
`inspection`, or `closing`.
A puzzle or memory page must include its zero-based `campaignIndex`. Entry pages
can link to a campaign level as well. Text can be supplied directly in `text`, or
selected with `textSource: "before"` or `"after"`. Optional fields are `speaker`,
`continuation`, `illustrationAsset` and `caption`. In a standard package, notes
and inspections display their authored text and image; they do not inherit
Mara-specific actions.
Prefer an entry, puzzle and memory page for every level, as in the example.
If a campaign level has no matching notebook page, its generic briefing, game
or reveal screen is used instead. Notebook pages are a sequential reading order;
translations cannot reorder pages or change their puzzle associations.
## Translate a story
Add a language entry and a JSON overlay. For example:
```json
{
"title": "Das Papierboot",
"description": "Eine kurze Geschichte über eine kleine Reise.",
"premise": "Eine gefaltete Seite trägt ein Versprechen über den Dorfteich.",
"levels": {
"boat": {
"chapter": "Eine kleine Überfahrt",
"title": "Ein Boot aus Papier",
"object": "Das Papierboot",
"before": "…",
"after": "…"
}
},
"pages": {
"boat.entry": {"title": "Ein Boot aus Papier"},
"boat.memory": {"title": "Etwas kommt nach Hause"}
}
}
```
Level overlays are keyed by puzzle ID, and page overlays by page ID. Only display
fields are applied: text, titles, speakers, captions and illustration paths.
Translations cannot replace IDs, chapter IDs, grid solutions, clues, page order,
or campaign associations. An optional top-level `coverAsset` can replace artwork
with embedded text; `copy` can override individual UI messages for that story.
An exact language tag is preferred, then its base language, then the story's
original language. Missing fields fall back individually to original text; an
explicit empty string can clear an optional passage. Library cards and story
headings use the translated metadata. A notice on the home screen identifies
when a story falls back to its original language.
The language control offers device language or a manual choice. Marks, current
page, bookmarks, achievements and the live undo stack survive a language change.
Nothing is copied into a separate translated-story save.
## App interface translations
App controls live separately in `assets/locales/en.json` and `de.json`, registered
by `assets/locales/catalog.json`. The English source is the catalogue key. To add
an interface language, register its label and asset path and translate a copy of
the English file. Missing messages fall back to English.
Preserve numbered placeholders such as `{0}` and `{1}`; their order may change.
For example, `"Open {0} · {1} / {2}"` translates the control while retaining the
story title and progress values. Placeholder sets are checked at load time.
Longer, more specific templates take precedence over shorter templates.
Flutter's localized controls, dates and text direction follow the selected
language. The handwriting font is used for supported Latin-script interface
languages; other scripts use system fallback fonts. A story language can declare
its own bundled `fontFamily` (register it under `flutter.fonts`); without one,
reading passages use the system font. The puzzle grid keeps its spatial layout
in right-to-left languages so switching language does not mirror the solution.
## Narration
Audio is optional. A catalogue entry can provide `tracksAsset` for its original
language and `scriptsAsset` for existing `textSource: "recording"` pages. Each
translated language supplies its own `tracksAsset` if recordings are available.
A translated story without its own manifest remains readable and does **not**
automatically play the original-language audio.
A manifest contains a `tracks` map keyed by page ID. A track can use an explicit
bundled `asset` path, or the legacy `file` name under `assets/audio/`. Include
`speaker`, `durationMs`, and optional timed `cues` (`startMs`, `endMs`, `text`,
`speaker`) for passage highlighting. Generic campaign fallback screens use
`campaign.<index>.before` and `campaign.<index>.after` track IDs. Keep those level
orders stable if using these fallback IDs.
## Saves and compatibility
Each additional story uses a `story/<story-id>/` preference namespace for reading
position, bookmarks, unlocks, page flags, puzzle marks and achievements. New puzzle
save keys include the story ID and permanent puzzle ID. Language is deliberately
absent from these keys. Device settings, total solved count and daily/practice
progress are shared across the app.
Mara's reserved `mara-island` story retains its original preference keys and
`story_v1_<index>` puzzle keys, so existing installations keep their progress.
Do not reuse that ID for another story or reorder Mara's existing campaign levels.
Adding packaged stories still requires a rebuilt app; downloading user-created
packages and an in-app story editor are not part of this implementation.
## Verification in this repository
`test/library_test.dart` covers all bundled stories/locales, unique puzzles,
original-language and per-field fallback, immutable puzzle identity under
translations, independent story saves, live undo after translation, chapter
progression, stale async language loads, and invalid content.
`test/library_widget_test.dart` exercises the actual selectors, German at 1.5×
text in both orientations, and Arabic direction/font behavior with a fixed
puzzle layout. `integration_test/library_test.dart` starts on the bookshelf and then runs the
library flow on the tablet with an in-memory game and ads disabled (`QA_TEST=true`,
preferably the isolated `check` flavor). Screenshots are written under
`artifacts/flutter-check/library-*.png` by the existing integration driver.
`flutter test tool/shelf_screenshots_test.dart` renders the shelf at phone and
tablet metrics into `artifacts/library/shelf-*.png` without a device.
For every device installation, follow the root `AGENTS.md`: build and verify the
intended APK first, then fresh-install its package with no restored app data.
## Cast readings and scene atmosphere
A page can remain one transport-controlled WAV while containing several voices.
The Midnight Invitation diary uses `narration/cast.json` for stable role-to-voice
assignments and optional `segments` in `narration/scripts.json`:
```json
{
"speaker": "Iris",
"text": "“I always do.”\n\n",
"pauseMs": 900,
"direction": "Understated, almost to herself."
}
```
Concatenating segment text **without a separator** must reproduce the page text
exactly, including whitespace and punctuation. Each segment names a cast member;
optional `speed`, `sentencePause`, `pauseMs`, `perspective` and `afterEffect`
control the offline performance. Midnight now uses Qwen3-TTS 1.7B VoiceDesign,
the selected engine for expressive story narration. Its renderer sends
`direction`, the scene's performance notes and the cast's voice description to
`generate_voice_design(..., instruct=...)`, separately from the exact spoken
text. `narration/performance.json` pins the model revision and scene directions.
Mara’s lighthouse story now uses the same directed Qwen workflow; its compiler
is `tool/compile_mara_story.py` and its assets remain under `assets/narration`
and `assets/audio`. For historical Kokoro packages, directions are editorial only. The renderers support `near` / `behind-door` perspective and three soft
procedural effects (`door-knock`, `chair-shift`, `paper`) placed in the pauses.
These effects are part of the reading, so pause/replay/speed changes keep them in
sync. The atmosphere switch controls the separate background layer.
For Midnight, use `scripts/render_qwen_narration.py`; see its package README for
the pinned runtime, staging, batched rendering, transcription review and
`--publish` workflow. Repeatable `--page <stable-page-id>` arguments select
readings; a first Qwen publication must replace the entire story. The older
`scripts/render_narration.py --story-root <package> ...` handles Kokoro packages.
Per-segment cue speakers drive highlighting and the live speaker label;
the role remains displayed through its pause. Generated drama tracks use
`cueJoin: ""`; legacy paragraph tracks retain their double-newline convention.
Master WAV, runtime WAV and FLAC archive checks remain mandatory.
For a translation, keep role/page IDs stable and author new text segments, voices
and timings for that language. Use a speech engine with suitable target-language
voices and publish the resulting manifest through that locale's `tracksAsset`.
English cue offsets or spoken tracks must not be reused over translated text.
A catalogue entry may also specify an independent `atmosphereAsset`:
```json
{
"scenes": {
"kitchen": {"asset": "assets/stories/example/audio/kitchen.wav"}
},
"pages": {
"example.candle.entry": "kitchen",
"example.candle.puzzle": "kitchen"
}
}
```
Use actual page IDs and bundled WAV paths. This manifest is shared across locales
and must contain nonverbal sound only. Unmapped pages are quiet. Adjacent pages
using the same asset retain the loop; another scene fades between loops. Leaving
the story, muting, or backgrounding stops it. Background volume lowers under the
reading; existing Sound & atmosphere controls apply to every story. The original
Mara chapter mapping remains supported.
`test/drama_test.dart` covers language isolation, invalid bindings, live cast
labels, ducking, loop continuity and leaving the book. The dedicated device test
is `integration_test/drama_test.dart`. Pilot review mixes can be exported with
`python3 scripts/render_drama_previews.py`; they are local artifacts, not bundled
in the app.
## Story-specific notebook paper
Set optional `paperAsset` on a catalogue entry to a bundled page-background image.
It applies to reading, contents and puzzle pages through `PaperSkin`; absent
values preserve the original notebook. A locale overlay may override `paperAsset`.
Keep the reading rectangle clear (approximately x=8–91%, y=12–91% of a portrait
1024×1536 page), and keep any decorations in the margins. Verify portrait,
landscape, larger text and a switch back to another book.
The selected puzzle region uses both a filled/checkmarked button and a continuous
outline. Keep its overlay transparent and pointer-transparent: an opaque shadow
or fill above the grid can conceal marks even when hit testing still works.