Add modular story library and shared-progress translations
This commit is contained in:
+37
-12
@@ -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` → `Book.load()` + `Progress.load()` → `Game(...)` → `await game.restore()` → `runApp(LumenApp(game: game))`.
|
||||
- **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.
|
||||
- **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`.
|
||||
- **Puzzle content:** twelve authored 7×7 pictures in `assets/campaign.json`; daily and classic boards are generated 5×5 puzzles.
|
||||
- **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.
|
||||
- **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.
|
||||
|
||||
@@ -32,9 +32,11 @@ lib/
|
||||
├── domain/
|
||||
│ ├── puzzle.dart Puzzle, JavaRandom, LogicSolver, Difficulty, Region, Hint
|
||||
│ ├── thinking.dart ThinkingAnalyzer, ThinkingReport — snapshot deduction waves and bounded hypothetical proofs
|
||||
│ ├── book.dart Book, CampaignLevel, StoryPage/StoryPageType — loads authored content
|
||||
│ ├── book.dart Book, CampaignLevel, StoryPage/StoryPageType — validated content and locale overlays
|
||||
│ ├── library.dart StoryDefinition, StoryLibrary — catalogue, locale resolution and cached books
|
||||
│ └── game.dart Game (ChangeNotifier), Screen/Mode, puzzle session, awards
|
||||
├── services/
|
||||
│ ├── translation.dart TranslationCatalog, MessageTranslator — separate UI catalogues and placeholders
|
||||
│ ├── 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
|
||||
@@ -42,9 +44,14 @@ lib/
|
||||
└── ui/
|
||||
├── paper.dart Paper, Leaf, Cover, Sketch, InkButton, PageSwipeBlocker
|
||||
├── board.dart Board, PencilMark painter, PixelPicture, PatternStamp
|
||||
└── discovery.dart Discovery — pattern-to-art transition and replay
|
||||
├── discovery.dart Discovery — pattern-to-art transition and replay
|
||||
├── translation.dart CopyScope, CopyText — translated controls, locale parsing and font fallback
|
||||
└── mara_story.dart Original-story presenter (part of main.dart); standard packages use standardStory
|
||||
|
||||
assets/
|
||||
├── library.json Story catalogue, IDs, asset paths and language metadata
|
||||
├── locales/ App UI catalogue index and English/German messages
|
||||
├── stories/paper-boat/ Small standard story with a German overlay
|
||||
├── campaign.json premise + 12 authored levels (chapter/title/object/before/after/picture/clues/areas; optional illustrationAsset)
|
||||
├── notebook.json sixteen stable cottage leaf records (type, speaker, campaignIndex, text source)
|
||||
├── narration/scripts.json canonical diary text, one record per recorded page
|
||||
@@ -131,10 +138,10 @@ Dependency rules:
|
||||
|
||||
## Runtime wiring
|
||||
|
||||
- `main()` sets the system overlay style, registers the Dancing Script OFL licence, loads `Book` and `Progress`, 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()`, 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()` stops narration when the route string (`screen:storyIndex|campaignIndex`) changes, then rebuilds.
|
||||
- `_changed()` replaces narration tracks when the active book/language changes, stops narration when the route string (`storyId:language:screen:storyIndex|campaignIndex`) changes, then rebuilds.
|
||||
- Lifecycle: backgrounding stops narration and awaits `prefs.flushed`; `dispose` stops/disposes the narrator, disposes ads and removes listeners.
|
||||
- `PopScope` intercepts Android back: it pops only on `home` with no `busy` work; otherwise it calls `back()`.
|
||||
- `build()` switches on `g.screen`; a full-screen overlay with `CircularProgressIndicator` covers the app while `g.busy` (classic board generation).
|
||||
@@ -184,7 +191,7 @@ stateDiagram-v2
|
||||
| `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` |
|
||||
| `contents([chapter])` | One chapter’s four entries; persist `notebook_contents_chapter`; default to current campaign chapter |
|
||||
| `contents([chapter])` | One chapter’s entries (derived from stable `chapterId`); persist `notebook_contents_chapter`; default to current campaign chapter |
|
||||
| `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` |
|
||||
@@ -232,7 +239,7 @@ Cell encoding across the app:
|
||||
|
||||
Content pipelines:
|
||||
|
||||
- **Campaign:** `Book.load()` parses `assets/campaign.json` → `CampaignLevel.puzzle()` builds `Puzzle(7, picture)` and applies `clues` (forced-given indices) and `areas` (`top,left,height,width` rectangles labelled A, B, C…).
|
||||
- **Campaign:** `Book.load()` parses `assets/campaign.json` → `CampaignLevel.puzzle()` builds `Puzzle(size, picture)` (default size 7) and applies `clues` (forced-given indices) and `areas` (`top,left,height,width` rectangles labelled A, B, C…).
|
||||
- **Daily:** fixed board per local calendar day (`Puzzle.seeded(epochDay * 7919)`), progress keyed by date.
|
||||
- **Classic:** deterministic practice board per difficulty and level (`1000000 + level` seed), generated on an isolate.
|
||||
|
||||
@@ -275,8 +282,22 @@ Content pipelines:
|
||||
- `splitPuzzle` sizing (content width `w`, height `h`): usable width `min(w, 980)`, side panel `min(min(280, max(200, 0.40·usable)), 0.55·usable)`, board `min(min(h, usable − panel − 18), 520)`. The board is always square and is centred; the side column scrolls when text is large.
|
||||
- `navigation()` uses one row of five buttons in landscape and two rows in portrait.
|
||||
|
||||
## Story library and localization
|
||||
|
||||
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.
|
||||
- `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.
|
||||
|
||||
## Persistence key map
|
||||
|
||||
`selected_story` and `language` (`system` or a locale tag) are global device preferences. New story-local keys below are stored under `story/<story-id>/`; Mara retains the original unprefixed keys for compatibility. Puzzle identity uses `Book.puzzleKey()` (legacy `story_v1_<index>` for Mara; `story_<story-id>_<puzzle-id>` for other stories). Language is never part of a save key. Daily/practice records, device settings and the total solved counter remain global.
|
||||
|
||||
|
||||
All writes go through `Progress.set` (memory is updated synchronously, disk is written in order; `flushed` awaits the queue). There is no migration from the legacy Java `lumen.xml`.
|
||||
|
||||
### Routing and session restore
|
||||
@@ -295,7 +316,7 @@ All writes go through `Progress.set` (memory is updated synchronously, disk is w
|
||||
| Key | Type | Written by | Purpose |
|
||||
| --- | --- | --- | --- |
|
||||
| `notebook_last_page` | page id | `Game.showStory` | Resume the last cottage leaf |
|
||||
| `notebook_contents_chapter` | int 0–2 | `Game.contents` | Restored chapter contents leaf |
|
||||
| `notebook_contents_chapter` | chapter index | `Game.contents` | Restored chapter contents leaf |
|
||||
| `notebook_manual_bookmark` | page id | `bookmark()` | "Return to my ribbon bookmark" in Contents |
|
||||
| `notebook_note_open` | bool | folded-note leaf | Note unfolded/folded state |
|
||||
| `notebook_handle_seen` | bool | `inspect()` | Repair margin note read; never reveals pre-puzzle artwork |
|
||||
@@ -317,7 +338,7 @@ All writes go through `Progress.set` (memory is updated synchronously, disk is w
|
||||
| `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 |
|
||||
| `storyAd_<index>` | bool | `nextCampaign` | At most one interstitial at each completed chapter boundary |
|
||||
| `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` |
|
||||
@@ -349,7 +370,7 @@ Board key formats (`<key>`):
|
||||
- Campaign reveals use optional `CampaignLevel.illustrationAsset` paths from campaign JSON. All twelve discoveries have watercolours; absent or unloadable image assets fall back to `PixelPicture`. The opening match memory shares the first campaign illustration through `discoveryArt()`. No puzzle identity or progress keys change.
|
||||
- Font: `assets/fonts/DancingScript.ttf` registered as `MaraHand`; `assets/fonts/OFL.txt` is registered with `LicenseRegistry` in `main()`.
|
||||
- `android/app/src/qa/AndroidManifest.xml` opts the isolated QA package into external installation (`preferExternal`); the production manifest keeps its existing installation policy. Android/OEM support still determines whether an SD-card install is accepted. The review Huawei reports `sm has-adoptable=false` and rejects new ASEC installs; use a compact release build installed internally there.
|
||||
- `pubspec.yaml` lists every bundled asset explicitly (no directory globs), so new assets must be added there.
|
||||
- `pubspec.yaml` registers individual legacy assets and story/UI directories. Directory declarations are not recursive: add each new subdirectory explicitly.
|
||||
|
||||
### Audio flow
|
||||
|
||||
@@ -372,7 +393,7 @@ Board key formats (`<key>`):
|
||||
- `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: every hint in campaign, daily and classic requires explicit confirmation and `ads.hint(give)`, including the first hint. The grid changes only in the reward callback; a local guard permits at most one hint per rewarded ad. Late callbacks check the active puzzle key and route. `Notebook.ads` permits deterministic reward/cancel/no-fill tests without bypassing the production gate. 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.
|
||||
- Interstitials: `nextPractice()` after every fourth classic completion; `nextCampaign()` at most once at a completed chapter boundary (`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).
|
||||
|
||||
@@ -385,8 +406,11 @@ 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/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/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/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 |
|
||||
@@ -443,6 +467,7 @@ Each run checks four discoveries in both orientations at 1.5× text, including n
|
||||
|
||||
| Goal | Touch | Also |
|
||||
| --- | --- | --- |
|
||||
| Add a story or translation | `assets/library.json`, new package/locale files, `pubspec.yaml` | Follow `docs/STORY_PACKAGES.md`; run library/domain/widget tests |
|
||||
| Edit campaign content or pictures | `assets/campaign.json` | Re-run `flutter test` (uniqueness/no-guess campaign tests) and `scripts/check_narration_assets.py` only if text changes |
|
||||
| Add or reorder cottage leaves | `assets/notebook.json`, `StoryPageType` builders, `Book.pageFor()`, narration scripts if recorded | Add a WAV + manifests + `pubspec.yaml` if narrated; update integration test |
|
||||
| Add a screen | `Screen` enum, `Game._route`/navigation method, `_NotebookState.build` switch, new builder | Back-button behaviour in `back()` and `PopScope` |
|
||||
|
||||
Reference in New Issue
Block a user