Expand narrated story, preserve solved patterns, and add ambience

Connect the island story with new character memories and narrative transitions.
Blend each solved symbol into its artwork and retain a replayable pattern stamp.
Allow completed grids to be inspected after navigation and app restarts.
Reduce campaign difficulty spikes and keep explained story hints free.

Append 24 narrated continuations while preserving original PCM takes. Add
four offline environmental loops with saved mute/volume controls, scene
fades, narration ducking and lifecycle handling.

Validation: 31 unit/widget tests, Flutter analysis, narration and soundscape
asset checks, tablet discovery layouts and extended-audio integration,
including simultaneous active voice and ambience mixer tracks.
This commit is contained in:
Hadrian Burkhardt
2026-11-02 05:04:57 +01:00
parent 6bd14a9e20
commit 68871ec573
102 changed files with 2322 additions and 520 deletions
+42 -15
View File
@@ -35,6 +35,7 @@ lib/
│ └── game.dart Game (ChangeNotifier), Screen/Mode, puzzle session, awards
├── services/
│ ├── progress.dart Progress — typed façade over SharedPreferencesAsync
│ ├── ambience.dart Ambience, Soundscape — location loops, fades and narration ducking
│ ├── narrator.dart Narrator — just_audio playback and passage cues
│ └── ads.dart Ads — UMP consent, rewarded hints, interstitials
└── ui/
@@ -52,8 +53,8 @@ assets/
├── artwork/*.png watercolours, vignettes and the notebook page
└── fonts/DancingScript.ttf bundled as family MaraHand; OFL.txt ships with licences
test/puzzle_test.dart 11 domain tests (Java parity, generation, solver, awards, restore)
test/widget_test.dart 9 widget tests (page gestures, scrolling, landscape layout)
test/puzzle_test.dart domain tests (Java parity, generation, solver, awards, restore)
test/widget_test.dart widget tests (page gestures, scrolling, landscape layout)
test/fixtures/java_boards.json 40 reference boards from the Java 1.7 version
integration_test/notebook_test.dart one on-device end-to-end test (QA flavour only)
scripts/ narration verification, install smoke check, narration rendering
@@ -65,7 +66,8 @@ scripts/ narration verification, install smoke check, narra
flowchart TD
subgraph UI["lib/ui — reusable page widgets"]
paper["paper.dart<br/>Paper · Leaf · Cover · Sketch<br/>InkButton · PageSwipeBlocker"]
board["board.dart<br/>Board · PencilMark · PixelPicture"]
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"]
game["domain/game.dart<br/>Game (ChangeNotifier)<br/>Screen/Mode · session · awards"]
@@ -73,12 +75,17 @@ flowchart TD
book["domain/book.dart<br/>Book · CampaignLevel · StoryPage"]
progress["services/progress.dart<br/>Progress — local key/value store"]
narrator["services/narrator.dart<br/>Narrator — just_audio"]
ambience["services/ambience.dart<br/>Ambience · Soundscape — just_audio"]
ads["services/ads.dart<br/>Ads — UMP consent + AdMob"]
main --> paper
main --> board
main --> discovery
discovery --> board
discovery --> paper
main --> game
main --> narrator
main --> ambience
main --> ads
board --> puzzle
board --> paper
@@ -91,6 +98,7 @@ flowchart TD
book --> scripts[("assets/narration/scripts.json")]
narrator --> manifest[("assets/audio/narration_manifest.json")]
narrator --> wav[("assets/audio/*.wav")]
ambience --> wav
```
Dependency rules:
@@ -146,7 +154,8 @@ stateDiagram-v2
game --> briefing: swipe back
game --> contents: Back to notebook
game --> home: daily or classic back
reveal --> briefing: next or previous leaf
reveal --> briefing: next leaf
reveal --> game: previous leaf / Android back / inspect solved pattern
reveal --> contents: last page or Back
reveal --> game: Today's puzzle
game --> game: daily or classic solve
@@ -159,7 +168,7 @@ stateDiagram-v2
| `contents` | `contents()` | `contents-<chapter>` | Four chapter entries, ribbon bookmark, reading resume and optional cottage scraps; chapter navigation | none |
| `briefing` | `briefing()` | `briefing-<i>` | Chapter, title, `before` passage, "Restore the pattern →" | `turnCampaign()` |
| `game` | `game()` | `game-<key>` | Puzzle heading, area totals, square board, hint/undo, actions | `turnCampaign()` in campaign mode only |
| `reveal` | `reveal()` | `reveal-<i>` | Object name, watercolour (or `PixelPicture` fallback), `after` passage, ending text on level 12 | `turnCampaign()` |
| `reveal` | `reveal()` | `reveal-<i>` | Object name, pattern-to-watercolour transition and permanent symbol (or `PixelPicture` fallback), `after` passage plus continuation, ending text on level 12 | `turnCampaign()` |
### Navigation methods (`Game`)
@@ -172,7 +181,7 @@ stateDiagram-v2
| `leaveCottage()` | Open Chapter II for reading without awarding unfinished cottage puzzles |
| `briefing(i)` | Clamp to `accessible`; cottage entry leaf or later `Screen.briefing` |
| `reveal(i, {readAhead})` | Redirect to `briefing(i)` unless recovered, or read-ahead is allowed for an accessible level; otherwise the cottage memory leaf or later `Screen.reveal` |
| `startCampaign(i)` | No-op if `i > accessible`; recovered levels go to `reveal`; else load `book.levels[i]` under `story_v1_<i>` and open the cottage puzzle leaf or later `Screen.game` |
| `startCampaign(i)` | No-op if `i > accessible`; including recovered levels, load `book.levels[i]` under `story_v1_<i>` and open the cottage puzzle leaf or later `Screen.game` |
| `startDaily(day)` | Load `Puzzle.seeded(epochDay(date) * 7919)` under `d<YYYY-MM-DD>`; `Screen.game` |
| `startPractice([level])` | Generate 5×5 board off the UI isolate with `compute(generatePractice)`; key `v2_<DIFFICULTY>_<level>`; `Screen.game` |
| `mark(i)` / `undo()` / `area(i)` | Cycle a cell 0→1→2→0, restore the previous snapshot, select an A/B/C area |
@@ -239,7 +248,8 @@ Content pipelines:
- `Board(puzzle, cells, onMark, selectedArea, won, maxWidth)` renders a square grid with row/column clues, fixed-clue dots, region highlight and per-cell `ValueKey('cell-<i>')`.
- `maxWidth` defaults to 350 (portrait). On wide leaves it is passed the available square; the clue unit is `u = boardWidth / (size + 1.3)` and clue text is clamped to 16–23 px.
- Each cell has a semantic label such as `Row 3, column 5, lit, fixed clue`; the whole board is wrapped in `PageSwipeBlocker`.
- `PixelPicture` shows the recovered 7×7 object after a campaign solve.
- `PixelPicture` shows the recovered 7×7 object when artwork is unavailable. `PatternStamp` draws the exact same 49 solution cells without a frame.
- `Discovery` (`ui/discovery.dart`) holds the solution briefly, then crossfades into the watercolour over 2.8 seconds. A small permanent stamp links the art to the solved symbol; an ink button replays the transition. Reduced-motion settings show the finished illustration and stamp immediately. Recovered grids are read-only and reconstructed from the solution if an old completed save lacks marks.
### Portrait versus landscape composition
@@ -286,12 +296,14 @@ All writes go through `Progress.set` (memory is updated synchronously, disk is w
| `grid_<key>` | digit string | `Game._save` | Marks per board (`0` empty, `1` lit, `2` crossed) |
| `done_<key>` | bool | `Game.check` | Exactly-once completion and win lock |
| `solved` | int | `Game.check` | Lifetime completions |
| `hint_<key>` | bool | `hint()` | First explained hint is free; later ones need a rewarded ad |
| `hint_<key>` | bool | `hint()` | Tracks hint use; daily/classic later hints need a rewarded ad, campaign hints stay free |
| `lastDaily` | int (epoch day) | daily completion | Streak bookkeeping |
| `streak` | int | daily completion | Consecutive daily completions |
| `campaignUnlocked` | int 0–11 | campaign completion | Furthest solved campaign level |
| `story_access_level` | int 0–11 | `nextCampaign`, `leaveCottage` | Furthest readable campaign level; effective access is at least 3 for cottage exploration, independent of awards |
| `storyAd_<index>` | bool | `nextCampaign` | At most one interstitial per fourth campaign step |
| `ambience_enabled` | bool (default true) | Sound & atmosphere | Independent environmental audio switch, applies only within story pages |
| `ambience_volume` | double 0–1 (default 0.7) | Sound & atmosphere | Saved environmental volume, independent of narration speed |
| `recording_speed` | double | speed dialog | `0.85`, `1.0` or `1.15` |
Board key formats (`<key>`):
@@ -302,14 +314,17 @@ Board key formats (`<key>`):
## Content and assets
- `assets/campaign.json`: `{ premise, levels: [{ chapter, title, object, before, after, picture, clues, areas, illustrationAsset? }] }`. `picture` is 49 characters of `0`/`1` (7×7, row-major). `clues` is a comma-separated list of forced-given indices. `areas` is `top,left,height,width` rectangles separated by `;` (labels A, B, C… in order).
- `assets/notebook.json`: sixteen ordered records with stable `id`, `type`, `title`, optional `campaignIndex`, `speaker`, `illustrationAsset` and `textSource` (`recording`, `before`, `after`) or inline `text`. `Book.pageFor()` finds a campaign entry/puzzle/memory. Preserve the first six IDs when extending the chapter.
- `assets/campaign.json`: `{ premise, levels: [{ chapter, title, object, before, after, picture, clues, areas, illustrationAsset?, beforeContinuation?, afterContinuation? }] }`. `picture` is 49 characters of `0`/`1` (7×7, row-major). `clues` is a comma-separated list of forced-given indices. `areas` is `top,left,height,width` rectangles separated by `;` (labels A, B, C… in order).
- `assets/notebook.json`: sixteen ordered records with stable `id`, `type`, `title`, optional `campaignIndex`, `speaker`, `illustrationAsset` and `textSource` (`recording`, `before`, `after`) or inline `text`, plus optional `continuation`. `Book.pageFor()` finds a campaign entry/puzzle/memory. Preserve the first six IDs when extending the chapter.
- Campaign `beforeContinuation`/`afterContinuation` add narrative after the original passage, with one audio control after the full text. Cottage entries/memories inherit these by text source; custom recording leaves can supply their own `continuation`. Recorded scripts include both parts. Recording-source leaves read `baseText` for the original displayed passage. Every new continuation has narrator cues; the original take remains byte-identical as PCM and has its own prefix checksum in the manifest.
- Campaign balance: all area puzzles have at least seven initial single-clue deductions; solver comparison counts are capped at 3 for the key, 5 for the crossing chapter and 6 for the final chapter. These are regression bounds, not a substitute for player feedback. Every area puzzle still needs comparison and has a unique, no-guess solution.
- Cottage `briefing`, `startCampaign` and `reveal` route to the entry, puzzle or memory leaf for levels 0–3. This migrates older saved routes while retaining marks, hint keys and completion awards. Chapters II/III use the existing screens.
- `assets/narration/scripts.json`: canonical diary text, one record per recorded page (`pageId`, `text`). `Book.load()` resolves `recording` text by stable page ID; a missing script yields empty text.
- `assets/narration/scripts.json`: canonical complete diary text, one record per recorded page (`pageId`, `text`, optional `baseText`, `continuation`, `continuationSpeaker`). `Book.load()` resolves `recording` base text by stable page ID; a missing script yields empty text.
- `assets/narration/manifest.json`: source masters, text hashes, WAV/FLAC hashes and cues — the provenance record.
- `assets/audio/narration_manifest.json`: runtime `{ tracks: { pageId: { file, durationMs, cues: [{ startMs, endMs, text }] } } }`. `Narrator` plays `assets/audio/<file>`.
- Five Mara recordings exist: `cottage.dedication`, `cottage.window`, `cottage.match.memory`, `cottage.folded.note`, `cottage.lantern.sketch`. The match-puzzle leaf has no recording.
- Twenty-three narrator tracks use `bm_george`: seven cottage prose leaves and `campaign.<4..11>.before/after`. `scripts.json` records speaker/voice/speed; the renderer accepts `--speaker Narrator` to preserve Mara’s original takes. The asset checker validates narrator scripts against notebook/campaign text.
- Twenty-three narrator tracks use `bm_george`: seven cottage prose leaves and `campaign.<4..11>.before/after`. `scripts.json` records speaker/voice/speed; the renderer accepts `--speaker Narrator` to preserve Mara’s original takes. `--append-continuations` appends only the narrator additions to existing PCM masters and records the original PCM frame count and checksum; use it when adding to existing recordings. The asset checker validates narrator scripts against notebook/campaign text.
- `audio()` follows the current cue speaker, including the switch from Mara to the narrator on the window/match memory pages. Both original and continuation paragraphs use cue highlighting.
- `audio()` uses the story ID or `campaign.<index>.before/after`, with a visible speaker label. Never show a recording control for an ID without a bundled track.
- `discoveryArt()` returns only a text placeholder until `Game.recovered(index)` is true. This gates both watercolours and pixel fallbacks; entry, inspection and closing leaves never call it, regardless of completed progress. The helper also rejects calls outside a memory/reveal screen. The repair note uses a text action rather than a picture hotspot; completed saves must not re-enable artwork on earlier leaves. Contextual cottage/background art is separate from the discovery images.
- The `check` Android flavor (`com.lumen.daily.check`) isolates device automation from the user’s installed QA app and progress.
@@ -327,11 +342,19 @@ Board key formats (`<key>`):
- Narration stops on route change and when the app backgrounds; the player is disposed with `Notebook`.
- Playback failures surface as reader-friendly text and never block reading.
### Environmental audio
- `Ambience` owns a separate looping player. `soundscapeFor(index)` maps cottage/home to cottage air, boat/anchor/bell to harbour water, bridge to flowing water and tower discoveries to wind. Home, contents, daily and practice screens are silent.
- `_syncAtmosphere()` follows navigation, narration and app lifecycle. Story ambience defaults on and resumes on foregrounding; narration stays opt-in. Muting/backgrounding stops it; scene transitions and volume changes fade over 240 ms.
- Environmental gain is `0.4 × saved volume`, reduced to one quarter while narration plays or loads. Both players share the speech audio session; the environmental player disables automatic session activation to avoid competing with narration. Audio interruptions/headphone removal use just_audio interruption handling.
- A serial queue and revision guard discard stale requests while loading/fading. Missing soundscapes never block narration or puzzles. `AmbienceOutput` allows race, fade, failure and lifecycle tests without a device backend.
- `scripts/render_ambience.py` deterministically renders four original 24-second PCM16/24 kHz loops offline. `assets/audio/ambience_manifest.json` records seeds/checksums. `scripts/check_soundscape_assets.py` checks bundling, PCM format, levels and loop boundaries.
### Ads and consent flow
- `Ads.supported` is false on the web, when `enabled`/`adsEnabled` is false (both test suites pass `adsEnabled: false`) and on platforms other than Android/iOS.
- `start()` requests UMP consent, shows the form if required, then initialises the SDK and preloads one rewarded and one interstitial ad.
- Hint flow: the first hint per board is free (`hint_<key>`), later hints require confirmation and `ads.hint(give)`. If no ad is available the user sees "No ad available. Please try again later." and no hint is consumed.
- Hint flow: campaign hints are always free and explained. Daily/classic boards keep the first-free policy (`hint_<key>`); later hints require confirmation and `ads.hint(give)`. If no ad is available the user sees "No ad available. Please try again later." and no hint is consumed.
- Interstitials: `nextPractice()` after every fourth classic completion; `nextCampaign()` at most once per fourth campaign step (`storyAd_<index>`). `between(next)` always calls `next()` if ads are unavailable, stale (≥58 min) or unconsented.
- `privacy()` opens the privacy options form only when UMP requires it; otherwise `main.dart` shows the local privacy explanation.
- Ad unit IDs default to Google test IDs; production overrides come from `ADMOB_APP_ID` (Gradle), `ADMOB_REWARDED_ID` and `ADMOB_INTERSTITIAL_ID` (Dart defines).
@@ -340,8 +363,10 @@ Board key formats (`<key>`):
| File | Covers |
| --- | --- |
| `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/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` | 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 |
| `test/widget_test.dart` | Pattern-to-art timing/replay, back-to-solved-grid navigation, repeated free story hints, 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/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 |
@@ -356,6 +381,7 @@ flutter pub get
flutter analyze
flutter test
python3 scripts/check_narration_assets.py
python3 scripts/check_soundscape_assets.py
# QA APK for isolated on-device checks (package com.lumen.daily.qa)
flutter build apk --debug --flavor qa
@@ -455,7 +481,8 @@ grep -rn "ValueKey('cell-\|leaf-scroll\|leaf-side-scroll" lib test
- Keep it in step with the root `README.md` (user-facing overview) and `ROADMAP.md` (product direction). This file is the only architecture/dependency map.
- Update the Mermaid graph when imports between layers change, when a screen is added, or when persistence keys or invariants change.
- Re-run `flutter analyze`, `flutter test` and `python3 scripts/check_narration_assets.py` after structural edits.
- Re-run `flutter analyze`, `flutter test` and `python3 scripts/check_narration_assets.py
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._