Complete cottage notebook with narration and discovery-only artwork

This commit is contained in:
Hadrian Burkhardt
2026-11-01 00:18:34 +01:00
parent 36fbbce6ef
commit 6bd14a9e20
90 changed files with 2394 additions and 221 deletions
+56 -30
View File
@@ -38,9 +38,31 @@ class CampaignLevel {
}
}
enum StoryPageType {
dedication,
entry,
puzzle,
memory,
note,
inspection,
closing,
}
class StoryPage {
const StoryPage(this.id, this.title, this.text);
const StoryPage(
this.id,
this.title,
this.text, {
this.type = StoryPageType.entry,
this.campaignIndex,
this.speaker = '',
this.illustrationAsset,
});
final String id, title, text;
final StoryPageType type;
final int? campaignIndex;
final String speaker;
final String? illustrationAsset;
}
class Book {
@@ -49,6 +71,9 @@ class Book {
final List<CampaignLevel> levels;
final List<StoryPage> pages;
final Map<String, dynamic> tracks;
int pageFor(int campaignIndex, StoryPageType type) => pages.indexWhere(
(p) => p.campaignIndex == campaignIndex && p.type == type,
);
static Future<Book> load() async {
final campaign = jsonDecode(
await rootBundle.loadString('assets/campaign.json'),
@@ -63,37 +88,38 @@ class Book {
),
)['tracks']
as Map<String, dynamic>;
const ids = [
'cottage.dedication',
'cottage.window',
'cottage.match.puzzle',
'cottage.match.memory',
'cottage.folded.note',
'cottage.lantern.sketch',
];
const titles = [
'For you, when you are ready',
'By the cottage window',
'A spark in the drawer',
'One small light',
'A note I nearly forgot',
'The handle, carefully mended',
];
final levels = (campaign['levels'] as List)
.map((e) => CampaignLevel(e))
.toList();
final notebook = jsonDecode(
await rootBundle.loadString('assets/notebook.json'),
) as Map<String, dynamic>;
return Book(
campaign['premise'],
(campaign['levels'] as List).map((e) => CampaignLevel(e)).toList(),
List.generate(
6,
(i) => StoryPage(
ids[i],
titles[i],
scripts
.where((s) => s['pageId'] == ids[i])
.map((s) => s['text'] as String)
.firstOrNull ??
'',
),
),
levels,
(notebook['pages'] as List).map((record) {
final index = record['campaignIndex'] as int?;
final text = switch (record['textSource']) {
'before' => levels[index!].before,
'after' => levels[index!].after,
'recording' =>
scripts
.where((s) => s['pageId'] == record['id'])
.map((s) => s['text'] as String)
.firstOrNull ??
'',
_ => record['text'] as String? ?? '',
};
return StoryPage(
record['id'],
record['title'],
text,
type: StoryPageType.values.byName(record['type']),
campaignIndex: index,
speaker: record['speaker'] as String? ?? '',
illustrationAsset: record['illustrationAsset'] as String?,
);
}).toList(),
tracks,
);
}
+34 -10
View File
@@ -25,6 +25,8 @@ class Game extends ChangeNotifier {
Difficulty get difficulty =>
Difficulty.fromStored(progress.text('difficulty', 'EASY'));
int storyIndex = 0, campaignIndex = 0, playingLevel = 1, selectedArea = 0;
int contentsChapter = 0;
StoryPage get storyPage => book.pages[storyIndex];
DateTime date = DateTime.now();
Puzzle? puzzle;
List<int> cells = [];
@@ -38,8 +40,10 @@ class Game extends ChangeNotifier {
int get recoveredCount =>
List.generate(12, (i) => recovered(i)).where((v) => v).length;
int get unlocked => progress.number('campaignUnlocked').clamp(0, 11);
int get accessible =>
math.max(unlocked, progress.number('story_access_level').clamp(0, 11));
int get accessible => math.max(
3,
math.max(unlocked, progress.number('story_access_level').clamp(0, 11)),
);
int get practiceLevel => progress.number('level_${difficulty.stored}', 1);
int get streak => visibleStreak(
progress.number('lastDaily', -99999),
@@ -54,10 +58,10 @@ class Game extends ChangeNotifier {
showStory(
book.pages
.indexWhere((p) => p.id == progress.text('notebook_last_page'))
.clamp(0, 5),
.clamp(0, book.pages.length - 1),
);
} else if (saved == 'contents') {
contents();
contents(progress.number('notebook_contents_chapter'));
} else if (saved == 'briefing') {
briefing(campaignIndex);
} else if (saved == 'reveal' &&
@@ -109,25 +113,37 @@ class Game extends ChangeNotifier {
void showStory(int i) {
_request++;
busy = false;
storyIndex = i.clamp(0, 5);
storyIndex = i.clamp(0, book.pages.length - 1);
mode = Mode.campaign;
campaignIndex = 0;
if (storyIndex == 2 && key != 'story_v1_0') {
_read(book.levels[0].puzzle(), 'story_v1_0');
campaignIndex = storyPage.campaignIndex ?? 0;
if (storyPage.type == StoryPageType.puzzle &&
key != 'story_v1_$campaignIndex') {
_read(book.levels[campaignIndex].puzzle(), 'story_v1_$campaignIndex');
}
unawaited(progress.set('notebook_last_page', book.pages[storyIndex].id));
unawaited(progress.set('viewed_${book.pages[storyIndex].id}', true));
_route(Screen.story);
}
void contents() {
void contents([int? chapter]) {
_request++;
busy = false;
contentsChapter = (chapter ?? campaignIndex ~/ 4).clamp(0, accessible ~/ 4);
unawaited(progress.set('notebook_contents_chapter', contentsChapter));
_route(Screen.contents);
}
void leaveCottage() {
unawaited(progress.set('story_access_level', math.max(accessible, 4)));
briefing(4);
}
void briefing(int i) {
campaignIndex = i.clamp(0, accessible);
if (campaignIndex < 4) {
showStory(book.pageFor(campaignIndex, StoryPageType.entry));
return;
}
mode = Mode.campaign;
_route(Screen.briefing);
}
@@ -138,6 +154,10 @@ class Game extends ChangeNotifier {
return;
}
campaignIndex = i;
if (i < 4) {
showStory(book.pageFor(i, StoryPageType.memory));
return;
}
mode = Mode.campaign;
_route(Screen.reveal);
}
@@ -187,6 +207,10 @@ class Game extends ChangeNotifier {
}
campaignIndex = i;
mode = Mode.campaign;
if (i < 4) {
showStory(book.pageFor(i, StoryPageType.puzzle));
return;
}
_read(book.levels[i].puzzle(), 'story_v1_$i');
_route(Screen.game);
}
@@ -287,7 +311,7 @@ class Game extends ChangeNotifier {
),
);
if (screen == Screen.story) {
showStory(3);
showStory(book.pageFor(campaignIndex, StoryPageType.memory));
} else {
reveal(campaignIndex);
}
+188 -103
View File
@@ -167,9 +167,14 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
}
Future<void> turn(int direction) async {
final next = (g.storyIndex + direction).clamp(0, 5);
if (direction > 0 && g.storyIndex == g.book.pages.length - 1) {
crossToHarbour();
return;
}
final next = (g.storyIndex + direction).clamp(0, g.book.pages.length - 1);
if (next == g.storyIndex) return;
if (g.storyIndex == 2 && direction > 0 && !g.won) {
final pageId = g.storyPage.id;
if (g.storyPage.type == StoryPageType.puzzle && direction > 0 && !g.won) {
unawaited(narrator.stop());
if (!await confirm(
'Leave a ribbon here?',
@@ -181,7 +186,11 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
}
await prefs.set('notebook_read_ahead', true);
}
g.showStory(next);
if (mounted && g.storyPage.id == pageId) g.showStory(next);
}
void crossToHarbour() {
g.leaveCottage();
}
Future<void> turnCampaign(int direction) async {
@@ -191,7 +200,11 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
if (direction > 0) {
g.startCampaign(index);
} else if (index > 0) {
g.reveal(index - 1, readAhead: true);
if (index == 4) {
g.showStory(g.book.pages.length - 1);
} else {
g.reveal(index - 1, readAhead: true);
}
} else {
g.contents();
}
@@ -435,8 +448,10 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
size: wide ? 19 : 21,
);
final next = InkButton(
g.storyIndex == 5 ? 'End of this trail' : 'Next leaf →',
g.storyIndex < 5 ? () => turn(1) : null,
g.storyIndex == g.book.pages.length - 1
? 'Across the tide →'
: 'Next leaf →',
() => turn(1),
size: wide ? 19 : 21,
);
if (wide) {
@@ -476,7 +491,11 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
]);
}
Widget reading(String text) => ListenableBuilder(
String get recordingId => g.screen == Screen.story
? g.storyPage.id
: 'campaign.${g.campaignIndex}.${g.screen == Screen.briefing ? 'before' : 'after'}';
Widget reading(String text, {double? size}) => ListenableBuilder(
listenable: narrator,
builder: (context, _) {
final passage = narrator.passage,
@@ -485,7 +504,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
padding: const EdgeInsets.symmetric(vertical: 8),
child: Text.rich(
TextSpan(
style: hand(g.storyIndex == 0 ? 22 : 21),
style: hand(size ?? (g.storyIndex == 0 ? 22 : 21)),
children: index < 0
? [TextSpan(text: text)]
: [
@@ -506,6 +525,13 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
Widget audio() => ListenableBuilder(
listenable: narrator,
builder: (context, _) => column([
writing(
g.book.tracks[recordingId]?['speaker'] == 'Narrator'
? 'Narrator · recorded story'
: 'Mara · diary reading',
size: 17,
color: muted,
),
Row(
children: [
Expanded(
@@ -515,7 +541,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
narrator.loading
? null
: () => narrator.toggle(
g.book.pages[g.storyIndex].id,
recordingId,
prefs.decimal('recording_speed'),
),
size: 21,
@@ -530,53 +556,42 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
writing(narrator.status, size: 17, color: muted),
]),
);
Widget illustration(
String asset,
String description, {
VoidCallback? onTap,
}) => Semantics(
image: true,
button: onTap != null,
label: description,
child: GestureDetector(
onTap: onTap,
child: Image.asset(
'assets/artwork/$asset',
height: 155,
fit: BoxFit.contain,
excludeFromSemantics: true,
),
),
);
Widget story() {
final p = g.book.pages[g.storyIndex];
final heading = <Widget>[
folio('MARA’S NOTEBOOK / ${g.storyIndex + 1} OF 6'),
folio('THE COTTAGE / ${g.storyIndex + 1} OF ${g.book.pages.length}'),
writing(p.title, size: 31),
];
final body = <Widget>[...heading];
Widget? wideBody;
switch (g.storyIndex) {
case 0:
switch (p.type) {
case StoryPageType.dedication:
body.addAll([
writing('A few things worth keeping', size: 20, color: muted),
divider(),
reading(p.text),
audio(),
]);
case 1:
case StoryPageType.entry:
body.addAll([
illustration(
'cottage-vignette-v1.png',
'Watercolour of Gran’s stone cottage, blue door and warm window.',
),
writing('A note beside the window · Mara', size: 17, color: muted),
if (p.illustrationAsset case final asset?)
Image.asset(
asset,
height: 155,
fit: BoxFit.contain,
semanticLabel: 'Watercolour of Gran’s stone cottage, blue door and warm window.',
),
writing(p.speaker, size: 17, color: muted),
reading(p.text),
audio(),
if (g.book.tracks.containsKey(p.id)) audio(),
if (p.campaignIndex != 0)
action('Turn to the pattern →', () => turn(1)),
]);
case 2:
case StoryPageType.puzzle:
final intro = writing(
'Restore a small light, or leave a bookmark and read on.',
g.campaignIndex < 2
? 'Restore a small light, or leave a bookmark and read on.'
: 'Compare the shared areas. Each cell counts in every area it belongs to.',
size: 21,
color: muted,
);
@@ -584,20 +599,27 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
wideBody = splitPuzzle(
side: [...heading, intro, areaPicker(), ...puzzleNotes()],
);
case 3:
case StoryPageType.memory:
body.addAll([
discoveryArt(g.book.levels.first, height: 155),
discoveryArt(g.book.levels[p.campaignIndex!], height: 155),
writing(
g.recovered(0)
g.recovered(p.campaignIndex!)
? 'A pattern restored · a memory kept'
: 'A memory to read · your puzzle can wait',
size: 17,
color: muted,
),
reading(p.text),
audio(),
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),
),
),
]);
case 4:
case StoryPageType.note:
if (!prefs.flag('notebook_note_open')) {
body.addAll([
writing('A folded scrap, tucked between the leaves.'),
@@ -628,31 +650,39 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
}),
]);
}
case 5:
case StoryPageType.inspection:
body.addAll([
illustration(
'lantern-vignette-v1.png',
'Watercolour of Mara’s blue storm lantern. Tap to examine the repaired handle.',
onTap: inspect,
),
writing(
prefs.flag('notebook_handle_seen')
? 'A repair made to keep small fingers safe.'
: 'Tap the lantern to look a little closer.',
: 'A repair note, tucked into the margin.',
size: 20,
color: muted,
),
reading(p.text),
audio(),
action('Follow the lantern into the next entry →', () {
unawaited(
prefs.set(
'story_access_level',
g.accessible < 1 ? 1 : g.accessible,
),
);
g.briefing(1);
}),
action('Read Gran’s margin note', inspect),
action('Follow the lantern into the next entry →', () => turn(1)),
]);
case StoryPageType.closing:
body.addAll([
reading(p.text),
if (g.book.tracks.containsKey(p.id)) audio(),
writing(
'Four memories in the cottage · ${List.generate(4, (i) => g.recovered(i)).where((v) => v).length} patterns restored',
size: 19,
color: muted,
),
action(
'Take the path to the harbour →',
crossToHarbour,
primary: true,
),
writing(
'Your unfinished patterns will wait here for you.',
size: 19,
color: muted,
),
]);
}
return Leaf(
@@ -704,42 +734,36 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
);
}
Widget contents() => Leaf(
key: const ValueKey('contents'),
body: column([
folio('THE NOTEBOOK BELONGS TO'),
writing('Mara Wren', size: 40),
writing('The Last Light', size: 33),
writing(
'For you, when you are ready.\nWith all my love, Gran.',
color: const Color(0xff70503b),
),
divider(),
folio('THE COTTAGE · OPENING LEAVES'),
for (var i = 0; i < 6; i++)
action('${i + 1} · ${g.book.pages[i].title}', () => g.showStory(i)),
action('Return to my ribbon bookmark', () {
final i = g.book.pages.indexWhere(
(p) => p.id == prefs.text('notebook_manual_bookmark'),
);
g.showStory(i < 0 ? 0 : i);
}),
divider(),
writing(g.book.premise),
writing(
'${g.recoveredCount} / 12 memories tucked between these pages',
size: 20,
color: muted,
),
for (var i = 0; i < 12; i++) ...[
if (i % 4 == 0) ...[
gap(24),
writing(g.book.levels[i].chapter, size: 28, color: blue),
Widget contents() {
final chapter = g.contentsChapter;
final first = chapter * 4;
final savedId = prefs.text('notebook_last_page');
final saved = g.book.pages.where((p) => p.id == savedId).firstOrNull;
final bookmarkId = prefs.text('notebook_manual_bookmark');
final ribbon = g.book.pages.where((p) => p.id == bookmarkId).firstOrNull;
return Leaf(
key: ValueKey('contents-$chapter'),
body: column([
folio('MARA’S NOTEBOOK · CONTENTS'),
writing(g.book.levels[first].chapter, size: 34),
if (chapter == 0) ...[
writing(
'For you, when you are ready. With all my love, Gran.',
color: const Color(0xff70503b),
),
action('Open the dedication', () => g.showStory(0)),
if (saved != null)
action('Continue reading · ${saved.title}', g.openNotebook),
if (ribbon != null)
action(
'Return to my ribbon bookmark',
() => g.showStory(g.book.pages.indexOf(ribbon)),
),
divider(),
],
Padding(
padding: const EdgeInsets.symmetric(vertical: 5),
child: InkButton(
'${(i + 1).toString().padLeft(2, '0')} · ${g.recovered(i) ? '${g.book.levels[i].object} ✓' : g.book.levels[i].title}${i > g.accessible ? ' · not yet' : ''}',
for (var i = first; i < first + 4; i++) ...[
InkButton(
'${i + 1} · ${g.book.levels[i].title}${g.recovered(i) ? ' ✓' : ''}${chapter == 0 && ribbon?.campaignIndex == i ? ' · ribbon' : ''}',
i <= g.accessible
? () {
if (g.recovered(i)) {
@@ -750,11 +774,48 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
}
: null,
),
],
if (chapter == 0) ...[
divider(),
action('The folded note', () => g.showStory(4)),
action('Gran’s repair note', () => g.showStory(5)),
action(
'Before you leave',
() => g.showStory(g.book.pages.length - 1),
),
],
writing(
'${g.recoveredCount} / 12 memories restored',
size: 20,
color: muted,
),
],
action('Close the notebook', g.home),
]),
);
]),
footer: column([
Row(
children: [
Expanded(
child: InkButton(
'← Previous chapter',
chapter > 0 ? () => g.contents(chapter - 1) : null,
size: 19,
),
),
Expanded(
child: InkButton(
'Next chapter →',
chapter < 2 && (chapter + 1) * 4 <= g.accessible
? () => g.contents(chapter + 1)
: null,
size: 19,
),
),
],
),
InkButton('Close the notebook', g.home, size: 19),
]),
);
}
Widget briefing() {
final l = g.book.levels[g.campaignIndex];
return Leaf(
@@ -765,7 +826,8 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
writing(l.chapter, size: 20, color: blue),
writing(l.title, size: 33),
gap(),
writing(l.before, size: 25),
reading(l.before, size: 25),
if (g.book.tracks.containsKey(recordingId)) audio(),
divider(),
writing(
g.campaignIndex < 2
@@ -987,7 +1049,8 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
g.key != requested ||
g.won ||
!(g.screen == Screen.game ||
g.screen == Screen.story && g.storyIndex == 2)) {
g.screen == Screen.story &&
g.storyPage.type == StoryPageType.puzzle)) {
return;
}
final h = g.applyHint();
@@ -996,7 +1059,13 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
'Row ${h.cell ~/ g.puzzle!.size + 1}, column ${h.cell % g.puzzle!.size + 1}',
'${h.explanation}\n\n${h.value == 1 ? 'This cell is lit.' : 'This cell stays dark.'}',
);
if (mounted && g.key == requested) g.check();
if (mounted &&
g.key == requested &&
(g.screen == Screen.game ||
g.screen == Screen.story &&
g.storyPage.type == StoryPageType.puzzle)) {
g.check();
}
}
if (!prefs.flag('hint_$requested')) {
@@ -1027,6 +1096,19 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
}
Widget discoveryArt(CampaignLevel level, {double height = 190}) {
// Discovery images belong only to the leaf after the puzzle, even when
// revisiting an earlier page with a completed save.
if (!(g.screen == Screen.reveal ||
g.screen == Screen.story && g.storyPage.type == StoryPageType.memory)) {
return const SizedBox.shrink();
}
if (!g.recovered(g.book.levels.indexOf(level))) {
return writing(
'The picture will appear once you restore the pattern.',
size: 19,
color: muted,
);
}
if (level.illustrationAsset case final asset?) {
return Image.asset(
asset,
@@ -1057,7 +1139,10 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
),
writing(l.object, size: 35),
discoveryArt(l),
writing(l.after, size: 25),
reading(l.after, size: 25),
if (g.book.tracks.containsKey(recordingId)) audio(),
if (!g.recovered(i))
action('Return to this pattern', () => g.startCampaign(i)),
gap(),
writing(
g.recovered(i)