- Start the app on a shelf of every installed book instead of the last book's home. Cards show the cover, translated metadata, available languages, restored patterns and either "Continue reading" or a way in. - Keep each book's saved route: the shelf is never written to flutter_screen, so choosing a book resumes its own leaf. - Lay the shelf out responsively: dense single-column cards on phones, a two-column grid from 720 logical pixels, a centred 860 px column on tablets and a chevron that exists in the bundled handwriting font. - Keep Settings reachable from the shelf and let the home page's story library button open the shelf instead of a dialog. - Add tool/shelf_screenshots_test.dart, which renders the shelf at phone and tablet metrics, checks that every card and Settings stay reachable without overflow, and writes artifacts/library/shelf-*.png. - Commit the pending Midnight Invitation package (campaign, notebook, narration and artwork), cast drama and ambience tooling, region selection, phone/tablet integration coverage and related docs. flutter analyze is clean and all 74 widget/domain tests pass.
13 KiB
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
- Copy the
paper-boatfolder toassets/stories/<story-id>/. - Give the story a unique, permanent lowercase ID (letters, digits and hyphens).
- Edit its campaign, notebook and translation files. Keep page and puzzle IDs stable once the story has shipped.
- Add an entry to
assets/library.jsonand list every new asset directory inpubspec.yaml. Flutter directory declarations are not recursive; include translation, artwork and audio subdirectories explicitly. - Run
flutter analyzeandflutter test. The library tests load every registered story in every declared language and check that each puzzle has one solution.
Example catalogue entry:
{
"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:
{
"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:
{
"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. direction is a production note for a human
or a future expressive speech engine; Kokoro does not interpret emotion prompts.
The current renderer supports 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.
Render selected pages with repeatable --page <stable-page-id> arguments to
scripts/render_narration.py --story-root <package> .... Other tracks are
preserved. 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:
{
"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.