9.3 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 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.
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.