Open Lumen on a responsive bookshelf and land pending story work

- 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.
This commit is contained in:
Hadrian Burkhardt
2026-11-05 14:29:50 +01:00
parent d45cd0698a
commit 0718e3f252
149 changed files with 16875 additions and 393 deletions
+31 -12
View File
@@ -8,10 +8,10 @@
- **What it is:** an offline illustrated logic-puzzle notebook ("Lumen", version 2.0.2+11).
- **Stack:** Flutter 3.47.5 / Dart 3.13.4, Material widgets, no backend and no account.
- **Entry point:** `main()` in `lib/main.dart` → `StoryLibrary.load()` + `Progress.load()` → open selected story/language → `Game(...)` → `await game.restore()` → `runApp(LumenApp(game: game))`. `Book.load()` remains an English Mara compatibility loader for existing tests/tools.
- **Entry point:** `main()` in `lib/main.dart` → `StoryLibrary.load()` + `Progress.load()` → open selected story/language → `Game(...)` → `await game.restore()` → `game.showLibrary()` → `runApp(LumenApp(game: game))`. The shelf is the first window; `restore()` has already positioned each book's saved leaf so choosing a book resumes it. `Book.load()` remains an English Mara compatibility loader for existing tests/tools.
- **State:** one `Game extends ChangeNotifier` (`lib/domain/game.dart`) owns the current screen, puzzle session, marks, undo history and progress. `_NotebookState` listens to it and rebuilds the active screen.
- **Screens:** `Screen { home, story, contents, briefing, game, reveal }`, rendered by six builder methods in `_NotebookState`.
- **Story content:** an offline catalogue in `assets/library.json`; Mara has twelve authored 7×7 pictures, and the short Paper Boat example demonstrates English/German story packages. Daily and classic boards are generated 5×5 puzzles.
- **Screens:** `Screen { library, home, story, contents, briefing, game, reveal }`, rendered by seven builder methods in `_NotebookState`.
- **Story content:** an offline catalogue in `assets/library.json`; Mara has twelve authored 7×7 pictures; Paper Boat demonstrates English/German packages; The Midnight Invitation is a complete English Halloween special (38 leaves, twelve puzzles, thirteen illustrations, 26 recorded passages). Daily and classic boards are generated 5×5 puzzles.
- **Persistence:** local `SharedPreferencesAsync` behind `lib/services/progress.dart`; legacy Java saves are never imported.
- **Platform:** Android is the tested target; iOS scaffolding exists but is unvalidated. `legacy/` is archived Java 1.7 and is excluded from builds and analysis.
@@ -78,7 +78,7 @@ flowchart TD
board["board.dart<br/>Board · PencilMark · PixelPicture · PatternStamp"]
discovery["discovery.dart<br/>Discovery · transition · replay"]
end
main["main.dart<br/>LumenApp · Notebook<br/>six screen builders · dialogs"]
main["main.dart<br/>LumenApp · Notebook<br/>seven screen builders · dialogs"]
game["domain/game.dart<br/>Game (ChangeNotifier)<br/>Screen/Mode · session · awards"]
puzzle["domain/puzzle.dart<br/>Puzzle · LogicSolver · JavaRandom · Difficulty"]
thinking["domain/thinking.dart<br/>ThinkingAnalyzer · ThinkingReport"]
@@ -138,7 +138,7 @@ Dependency rules:
## Runtime wiring
- `main()` sets the system overlay style, registers the Dancing Script OFL licence, initializes date symbols, loads the catalogue and progress, resolves the saved story and requested language, constructs `Game`, awaits `game.restore()`, then runs `LumenApp`.
- `main()` sets the system overlay style, registers the Dancing Script OFL licence, initializes date symbols, loads the catalogue and progress, resolves the saved story and requested language, constructs `Game`, awaits `game.restore()`, opens the shelf with `game.showLibrary()`, then runs `LumenApp`.
- `LumenApp` is a `MaterialApp` with seed colour `blue` (`#274956`), cream surface (`#f3e7cc`), `fontFamily: 'MaraHand'` and `Notebook` as `home`.
- `_NotebookState` creates exactly one `Narrator(g.book.tracks)` and one `Ads(enabled: widget.adsEnabled)`, subscribes to `Game` with `_changed`, and starts ads after the first frame.
- `_changed()` replaces narration tracks when the active book/language changes, stops narration when the route string (`storyId:language:screen:storyIndex|campaignIndex`) changes, then rebuilds.
@@ -177,6 +177,7 @@ stateDiagram-v2
| Screen | Builder in `_NotebookState` | Leaf key | Content | `onTurn` |
| --- | --- | --- | --- | --- |
| `library` | `libraryScreen()` | `library` | Bookshelf: every catalogue entry as a card with cover, languages, restored patterns and settings | none (cards call `selectStory`) |
| `home` | `home()` | none (own `Scaffold` body) | Harbour art, notebook cover, daily ritual, difficulty, rules, privacy, licences | none |
| `story` | `story()` | `story-<index>` | Sixteen cottage leaves: dedication, four entry/puzzle/memory beats, note, inspection, closing | `turn()` |
| `contents` | `contents()` | `contents-<chapter>` | Four chapter entries, ribbon bookmark, reading resume and optional cottage scraps; chapter navigation | none |
@@ -188,6 +189,7 @@ stateDiagram-v2
| Method | Effect |
| --- | --- |
| `showLibrary()` | `Screen.library`; cancels pending board generation. Never written to `flutter_screen`, so each book's saved route survives and the app opens on the shelf |
| `home()` | `Screen.home`; cancels pending board generation |
| `openNotebook()` | `showStory(index of notebook_last_page, else 0)` |
| `showStory(i)` | Clamp `i` to available pages; set campaign mode and the record’s campaign index; on a puzzle leaf load its `story_v1_<index>` unless already loaded; persist last page and `viewed_<pageId>`; `Screen.story` |
@@ -207,7 +209,7 @@ stateDiagram-v2
- **Boot/app:** `main`, `LumenApp`, `Notebook`, `_NotebookState`.
- **Lifecycle/router:** `initState`, `_changed`, `didChangeAppLifecycleState`, `dispose`, `build`, `back`.
- **Screens:** `home`, `story`, `contents`, `briefing`, `game`, `reveal`.
- **Screens:** `libraryScreen`, `home`, `story`, `contents`, `briefing`, `game`, `reveal`.
- **Puzzle UI:** `puzzleBody`, `areaPicker`, `board`, `puzzleNotes`, `splitPuzzle`, `hint`, `nextPractice`.
- **Story extras:** `reading` (narrator cue highlight), `audio` (play/pause, stop, speed), `illustration`, `navigation`, `bookmark`, `openLetter`, `inspect`, `speed`.
- **Leaf turning:** `turn`, `turnCampaign`, `nextCampaign`.
@@ -255,7 +257,7 @@ Content pipelines:
- All visible handwriting uses `hand(size)` (`MaraHand` → Dancing Script). Colours live in `lib/ui/paper.dart`: `ink` `#36413c`, `blue` `#274956`, `muted` `#796b55`, `cream` `#f3e7cc`, `amber` `#e0b568`.
- `writing()` adds paper spacing; `folio()` is the small blue label above a leaf's content.
- The home folio stays above the scroll viewport so its lettering remains fully visible during scrolling; the title, illustrations and actions scroll below it.
- The home folio stays above the scroll viewport so its lettering remains fully visible during scrolling; the title, illustrations and actions scroll below it. Home is keyed by story ID, so selecting a different story opens at its cover instead of retaining the preceding book’s home scroll offset.
- `InkButton` is the only button style: transparent, underlined ink text, minimum 48 px touch target, optional `primary` emphasis, wrapped in `PageSwipeBlocker`.
### Paper and leaves
@@ -287,11 +289,11 @@ Content pipelines:
See [Story packages and translations](STORY_PACKAGES.md) for the authoring schema and a complete recipe.
- `StoryLibrary` reads `assets/library.json` and caches books by stable story ID and resolved language. `Book.loadDefinition()` merges only display fields from locale overlays, validates IDs/references/grid shapes, and derives chapters from stable `chapterId` values.
- `Game.selectStory()` cancels old puzzle work and restores that story's route/marks; `selectLanguage()` replaces localized content without replacing the live grid or undo stack. The library dialog and language picker are reachable from home; language is also available while reading.
- `Game.selectStory()` cancels old puzzle work and restores that story's route/marks; `selectLanguage()` replaces localized content without replacing the live grid or undo stack. `Game.showLibrary()` opens the bookshelf, which is the app's first window; `bookCard`/`shelfBooks` load every book once per requested language, and a broken package is skipped so the rest of the shelf stays usable. The shelf is responsive: dense single-column cards below 480 logical pixels, a two-column grid from 720 px, and a centred column capped at 860 px; Settings scrolls with the books. The language picker is reachable from the shelf's Settings and from a book's home; language is also available while reading.
- `LumenApp` rebuilds its locale/theme and `CopyScope` from `Game`. Flutter localization delegates handle standard controls and RTL direction. `CopyText` translates UI messages separately from authored passages, which `reading()` displays directly. The board explicitly remains LTR so its spatial solution does not change with language.
- Mara's special note/inspection pages live in `lib/ui/mara_story.dart`; `standardStory()` supports new packages without Mara-specific assumptions. Existing ambience scenes apply only to Mara.
- Languages resolve exact tag → base language → original story language; individual missing fields also use original text. Translated books only use explicitly supplied locale narration manifests, so English recordings do not automatically play over translated text.
- The shipped Paper Boat package demonstrates English/German content; Mara's story text is still English. Both English and German app UI catalogues are bundled.
- The shipped Paper Boat package demonstrates English/German content; Mara's story text is still English. `assets/stories/midnight-invitation/` adds the complete Halloween story with its own narrated English content and original generated artwork. Both English and German app UI catalogues are bundled.
## Persistence key map
@@ -406,14 +408,19 @@ Board key formats (`<key>`):
| `integration_test/autoplay_test.dart` | Real-device delayed playback of bundled WAVs, cancellation when entering a puzzle and Stop preventing restart |
| `test/ambience_test.dart` | Scene mapping, voice ducking, mute/background stop, stale loading requests, backend failure/recovery and disposal |
| `integration_test/soundscape_test.dart` | Real-device decoding of all 24 new continuations, bridge/narration mixing, saved mute and automatic Mara-to-narrator handoff |
| `test/halloween_test.dart` | Complete Halloween structure, twelve unique/no-assumption puzzles, all prose/audio/image assets, read-ahead, independent saves and exactly-once completion |
| `test/halloween_widget_test.dart` | All 38 Halloween leaves at 1.5× text in both orientations, gated discovery artwork and bookmarks from later chapters |
| `integration_test/halloween_test.dart` | Complete on-device Halloween flow, all 26 native WAV decodes, play/pause/resume, twelve discoveries, read-ahead, bookmarks and ending |
| `test/library_test.dart` | All registered packages/locales, unique puzzles, identity-safe overlays, fallback/audio, independent story saves, live language switching, variable chapters, UI placeholders and invalid content |
| `test/library_widget_test.dart` | Actual library/language controls, translated metadata, German at larger text in both orientations, Arabic RTL/font behavior |
| `test/library_widget_test.dart` | Bookshelf as the app's first window (all books listed and one opened), actual library/language controls, translated metadata, German at larger text in both orientations, Arabic RTL/font behavior |
| `test/puzzle_test.dart` | 40 Java reference boards (signed 64-bit seeds), 300 graded boards, solver counts vs. exhaustive search, campaign uniqueness/no-guess, streaks, fresh progress, read-ahead, daily awards and practice levels |
| `test/widget_test.dart` | Pattern-to-art timing/replay, back-to-solved-grid navigation, rewarded hints in all modes, declined/unavailable ads and duplicate/stale callbacks, page swipes vs. grid drags, swipes over text/blank paper, vertical scrolling and cancelled drags, small/landscape/1.5× text, landscape two-column puzzle leaf, illustrated campaign reveals and pixel fallback at 1.5× text |
| `integration_test/library_test.dart` | Isolated on-device library selection, English/German switching, shared marks/bookmark/undo, story isolation, read-ahead and exactly-once completion; four screenshots |
| `integration_test/library_test.dart` | Isolated on-device bookshelf start, English/German switching, shared marks/bookmark/undo, story isolation, read-ahead and exactly-once completion; five screenshots |
| `integration_test/notebook_test.dart` | On-device QA flow: six leaves, real WAV playback and pause/resume, bookmarks/discoveries, match and lantern solves, exactly-once awards, QA disk round-trip, screenshots |
| `integration_test/cottage_test.dart` | All sixteen leaves, larger-text portrait/landscape, bookmarks, legacy-key marks, all four awards, all 23 narrator tracks and isolated test persistence; eight screenshots |
| `integration_test/discovery_art_test.dart` | QA tablet screenshots of all twelve discoveries and the opening match memory, portrait/landscape at 1.5× text; checks reachable controls and unchanged awards |
| `tool/shelf_screenshots_test.dart` | Renders the bookshelf at phone (360×640, 390×844, 1.5× text) and tablet (800×1280, 1280×800) metrics, asserts every card and Settings stay reachable without overflow, and writes `artifacts/library/shelf-*.png` |
| `scripts/check_story_package.py` | Independent story script/cue/audio/master/archive and illustration validation |
| `scripts/check_narration_assets.py` | Script text ↔ manifest ↔ WAV masters checksums |
| `scripts/check_flutter_install.py` | Read-only installed-app smoke check and screenshots |
| `scripts/render_narration.py` | Renders the fixed WAV masters and FLAC archives; the app never synthesises speech |
@@ -484,7 +491,7 @@ Each run checks four discoveries in both orientations at 1.5× text, including n
- **Widget tests use a test font.** Glyphs render as squares, so text wraps far more than Dancing Script. Use geometry assertions and, for visual work, load the real font with `FontLoader('MaraHand')` or check on the device before trusting a layout.
- **`pumpAndSettle` can struggle with the full app.** Prefer a bounded `pump()` loop when mounting `LumenApp`; the audio streams keep notifying and may prevent settling.
- **`Game.restore()` must be awaited before `runApp`.** Otherwise the app opens on `home` and ignores the saved screen.
- **`Game.restore()` must be awaited before `runApp`.** The shelf is shown first, but selecting a book calls `restore()`; without that route data the book opens on `home` and ignores its saved screen.
- **Story page 3 is index 2.** Solving the opening match puzzle awards the first campaign entry (`story_v1_0`) and jumps to story page 4 (`showStory(3)`), skipping the campaign reveal.
- **`showStory()` sets campaign mode and the page record’s campaign index (0 if absent).** Daily and classic starts set their own mode afterwards; keep that order.
- **`startPractice` discards stale results** with `_request`. Do not remove that guard when refactoring.
@@ -531,3 +538,15 @@ python3 scripts/check_soundscape_assets.py` after structural edits.
- The map is hand-maintained; no generator or CI check keeps it current, so treat drift as a bug.
_Last reviewed against version 2.0.2+11._
The cast diary audio system adds `lib/domain/soundscape.dart` (package-defined loops),
`narration/cast.json` and segmented scripts in the Halloween package, plus
`scripts/audio_drama.py` for offline cast validation/Foley. `Book.atmosphere`
binds stable page IDs to nonverbal loops independently of language. Native
cast/mixing coverage is in `integration_test/drama_test.dart`.
Halloween now uses `Book.paperAsset` through `PaperSkin` on all notebook pages.
`tool/compile_midnight_diary.py` compiles the first-person `STORY.md` manuscript
into stable content and cast scripts. `RegionButton` provides a filled selected
state; `Board` overlays a pointer-transparent frame around the selected region.
`test/region_selection_test.dart` verifies frame geometry, marking and book skins.
+1
View File
@@ -3,6 +3,7 @@
| Document | Purpose |
| --- | --- |
| [Code map](CODE_MAP.md) | Agent-oriented architecture, dependency graph, screen state machine, puzzle pipeline, UI/layout rules, persistence keys, asset and service flows, test map, invariants, change recipes and gotchas |
| [Halloween special](../assets/stories/midnight-invitation/README.md) | The Midnight Invitation: manuscript, artwork prompts, narration provenance and puzzle proofs |
| [Story packages and translations](STORY_PACKAGES.md) | Add stories to the library, author puzzles/pages, translate content and UI, and preserve saves across languages |
| [Thinking-depth tool](THINKING_DEPTH.md) | CLI usage, reasoning model, depth limits, reports and human-difficulty interpretation |
| [Project README](../README.md) | Features, artwork, narration, build and verification commands, publishing notes |
+82 -3
View File
@@ -186,10 +186,89 @@ 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
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. `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`:
```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.