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
+146 -23
View File
@@ -10,9 +10,11 @@ import 'domain/book.dart';
import 'domain/game.dart';
import 'domain/puzzle.dart';
import 'services/ads.dart';
import 'services/ambience.dart';
import 'services/narrator.dart';
import 'services/progress.dart';
import 'ui/board.dart';
import 'ui/discovery.dart';
import 'ui/paper.dart';
Future<void> main() async {
@@ -73,7 +75,9 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
Game get g => widget.game;
Progress get prefs => g.progress;
late final Narrator narrator;
late final Ambience ambience;
late final Ads ads;
bool _foreground = true;
String _route = '';
String get route =>
'${g.screen.name}:${g.screen == Screen.story ? g.storyIndex : g.campaignIndex}';
@@ -81,12 +85,15 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
void initState() {
super.initState();
narrator = Narrator(g.book.tracks);
ambience = Ambience();
narrator.addListener(_syncAtmosphere);
ads = Ads(enabled: widget.adsEnabled);
g.addListener(_changed);
_route = route;
WidgetsBinding.instance.addObserver(this);
WidgetsBinding.instance.addPostFrameCallback((_) {
unawaited(ads.start());
_syncAtmosphere();
});
}
@@ -95,11 +102,35 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
_route = route;
unawaited(narrator.stop());
}
_syncAtmosphere();
if (mounted) setState(() {});
}
bool get atmosphereEnabled =>
!prefs.contains('ambience_enabled') || prefs.flag('ambience_enabled');
void _syncAtmosphere() {
final inStory =
g.mode == Mode.campaign &&
[
Screen.story,
Screen.briefing,
Screen.game,
Screen.reveal,
].contains(g.screen);
ambience.update(
scene: inStory ? soundscapeFor(g.campaignIndex) : null,
enabled: atmosphereEnabled,
foreground: _foreground,
narrating: narrator.playing || narrator.loading,
volume: prefs.decimal('ambience_volume', .7),
);
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
_foreground = state == AppLifecycleState.resumed;
_syncAtmosphere();
if (state != AppLifecycleState.resumed) {
unawaited(narrator.stop());
unawaited(prefs.flushed);
@@ -110,6 +141,8 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
void dispose() {
WidgetsBinding.instance.removeObserver(this);
g.removeListener(_changed);
narrator.removeListener(_syncAtmosphere);
ambience.dispose();
narrator.dispose();
ads.dispose();
super.dispose();
@@ -225,7 +258,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
if (mounted) g.reveal(index, readAhead: true);
case Screen.reveal:
if (direction < 0) {
g.briefing(index);
g.startCampaign(index);
} else {
nextCampaign();
}
@@ -270,8 +303,9 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
} else {
g.home();
}
case Screen.briefing:
case Screen.reveal:
g.startCampaign(g.campaignIndex);
case Screen.briefing:
g.contents();
case Screen.game:
if (g.mode == Mode.campaign) {
@@ -415,6 +449,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
() => unawaited(g.startPractice()),
),
action('How to play', rules),
action('Sound & atmosphere', soundSettings),
action('Privacy & advertising', privacy),
action(
'Open-source licenses',
@@ -526,7 +561,10 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
listenable: narrator,
builder: (context, _) => column([
writing(
g.book.tracks[recordingId]?['speaker'] == 'Narrator'
(narrator.page == recordingId
? narrator.speaker
: g.book.tracks[recordingId]?['speaker']) ==
'Narrator'
? 'Narrator · recorded story'
: 'Mara · diary reading',
size: 17,
@@ -554,6 +592,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
],
),
writing(narrator.status, size: 17, color: muted),
InkButton('Sound & atmosphere', soundSettings, size: 18),
]),
);
Widget story() {
@@ -583,6 +622,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
),
writing(p.speaker, size: 17, color: muted),
reading(p.text),
if (p.continuation.isNotEmpty) reading(p.continuation),
if (g.book.tracks.containsKey(p.id)) audio(),
if (p.campaignIndex != 0)
action('Turn to the pattern →', () => turn(1)),
@@ -610,14 +650,16 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
color: muted,
),
reading(p.text),
if (p.continuation.isNotEmpty) reading(p.continuation),
if (g.book.tracks.containsKey(p.id)) audio(),
if (!g.recovered(p.campaignIndex!))
action(
'Return to this pattern',
() => g.showStory(
g.book.pageFor(p.campaignIndex!, StoryPageType.puzzle),
),
action(
g.recovered(p.campaignIndex!)
? 'View the solved pattern'
: 'Return to this pattern',
() => g.showStory(
g.book.pageFor(p.campaignIndex!, StoryPageType.puzzle),
),
),
]);
case StoryPageType.note:
if (!prefs.flag('notebook_note_open')) {
@@ -734,6 +776,65 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
);
}
Future<void> soundSettings() => showDialog<void>(
context: context,
builder: (dialogContext) => StatefulBuilder(
builder: (context, refresh) {
void save(String key, Object value) {
unawaited(prefs.set(key, value));
_syncAtmosphere();
if (mounted) setState(() {});
refresh(() {});
}
return AlertDialog(
title: Text('Sound & atmosphere', style: hand(29)),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SwitchListTile(
contentPadding: EdgeInsets.zero,
title: Text('Environmental sounds', style: hand(23)),
value: atmosphereEnabled,
onChanged: (value) => save('ambience_enabled', value),
),
writing(
'Water at the harbour and bridge, wind around the tower. The atmosphere grows quieter while the story is read.',
size: 20,
),
writing('Atmosphere volume', size: 20),
Slider(
label:
'${(prefs.decimal('ambience_volume', .7) * 100).round()}%',
value: prefs.decimal('ambience_volume', .7).clamp(0.0, 1.0),
divisions: 10,
onChanged: atmosphereEnabled
? (value) => save('ambience_volume', value)
: null,
),
writing(
'Readings play when you press Play. Your device volume controls the voice.',
size: 18,
color: muted,
),
if (ambience.error.isNotEmpty)
writing(ambience.error, size: 18),
],
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(dialogContext),
child: const Text('Keep going'),
),
],
);
},
),
);
Widget contents() {
final chapter = g.contentsChapter;
final first = chapter * 4;
@@ -827,6 +928,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
writing(l.title, size: 33),
gap(),
reading(l.before, size: 25),
if (l.beforeContinuation.isNotEmpty) reading(l.beforeContinuation),
if (g.book.tracks.containsKey(recordingId)) audio(),
divider(),
writing(
@@ -837,7 +939,9 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
color: muted,
),
action(
prefs.contains('grid_story_v1_${g.campaignIndex}')
g.recovered(g.campaignIndex)
? 'View the solved pattern →'
: prefs.contains('grid_story_v1_${g.campaignIndex}')
? 'Continue this pattern →'
: 'Restore the pattern →',
() => g.startCampaign(g.campaignIndex),
@@ -884,6 +988,8 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
}
List<Widget> puzzleNotes() => [
if (g.mode == Mode.campaign)
InkButton('Sound & atmosphere', soundSettings, size: 18),
writing(
g.won
? 'Already restored. Turn the leaf to revisit the memory.'
@@ -904,7 +1010,9 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
const SizedBox(width: 8),
Expanded(
child: InkButton(
prefs.flag('hint_${g.key}')
g.mode == Mode.campaign
? 'Hint · free'
: prefs.flag('hint_${g.key}')
? 'Hint · rewarded ad'
: 'Hint · free',
hint,
@@ -984,8 +1092,14 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
(
label: g.mode == Mode.daily
? 'Return to the notebook'
: g.mode == Mode.campaign
? 'Revisit the memory →'
: 'Next puzzle →',
run: g.mode == Mode.daily ? g.home : nextPractice,
run: g.mode == Mode.daily
? g.home
: g.mode == Mode.campaign
? () => g.reveal(g.campaignIndex)
: nextPractice,
primary: true,
),
(label: 'How to play', run: rules, primary: false),
@@ -1068,7 +1182,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
}
}
if (!prefs.flag('hint_$requested')) {
if (g.mode == Mode.campaign || !prefs.flag('hint_$requested')) {
await prefs.set('hint_$requested', true);
give();
return;
@@ -1110,14 +1224,20 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
);
}
if (level.illustrationAsset case final asset?) {
return Image.asset(
asset,
return Discovery(
key: ValueKey('discovery-${g.campaignIndex}'),
picture: level.picture,
label: level.object,
height: height,
width: double.infinity,
fit: BoxFit.contain,
semanticLabel: 'Watercolour illustration: ${level.object}',
errorBuilder: (_, _, _) =>
PixelPicture(level.picture, label: level.object, height: height),
artwork: Image.asset(
asset,
height: height,
width: double.infinity,
fit: BoxFit.contain,
semanticLabel: 'Watercolour illustration: ${level.object}',
errorBuilder: (_, _, _) =>
PixelPicture(level.picture, label: level.object, height: height),
),
);
}
return PixelPicture(level.picture, label: level.object, height: height);
@@ -1140,9 +1260,12 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
writing(l.object, size: 35),
discoveryArt(l),
reading(l.after, size: 25),
if (l.afterContinuation.isNotEmpty) reading(l.afterContinuation),
if (g.book.tracks.containsKey(recordingId)) audio(),
if (!g.recovered(i))
action('Return to this pattern', () => g.startCampaign(i)),
action(
g.recovered(i) ? 'View the solved pattern' : 'Return to this pattern',
() => g.startCampaign(i),
),
gap(),
writing(
g.recovered(i)
@@ -1193,7 +1316,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
void rules() => message(
'Find the light',
'Light exactly as many cells as the number beside each row and above each column.\n\nTap to cycle: empty → light → crossed out → empty. Mark every cell to finish. Small dots mark fixed clues.\n\nA, B and C are overlapping areas with their own totals. Shared cells count in both areas. Compare clues and subtract their shared parts to find new deductions.\n\nEvery story grid reveals an object. Later pages require area comparisons; all are solvable without guessing. Classic practice grades the length of simpler row and column chains.\n\nOne free explained hint per puzzle, then optional rewarded hints. Streaks count consecutive daily completions on this device.',
'Light exactly as many cells as the number beside each row and above each column.\n\nTap to cycle: empty → light → crossed out → empty. Mark every cell to finish. Small dots mark fixed clues.\n\nA, B and C are overlapping areas with their own totals. Shared cells count in both areas. Compare clues and subtract their shared parts to find new deductions.\n\nEvery story grid reveals an object. Later pages require area comparisons; all are solvable without guessing. Classic practice grades the length of simpler row and column chains.\n\nStory hints are always free and explained. Daily and classic puzzles offer one free hint, then optional rewarded hints. Streaks count consecutive daily completions on this device.',
close: 'Got it',
);
Future<void> privacy() async {