Add modular story library and shared-progress translations

This commit is contained in:
Hadrian Burkhardt
2026-11-03 17:15:15 +01:00
parent 5b9a76fb53
commit d45cd0698a
30 changed files with 2694 additions and 495 deletions
+366 -237
View File
@@ -2,9 +2,17 @@ import 'dart:async';
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'ui/translation.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/services.dart';
import 'package:intl/intl.dart';
import 'package:intl/date_symbol_data_local.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'domain/library.dart';
import 'services/translation.dart';
import 'domain/book.dart';
import 'domain/game.dart';
@@ -17,6 +25,8 @@ import 'ui/board.dart';
import 'ui/discovery.dart';
import 'ui/paper.dart';
part 'ui/mara_story.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
LicenseRegistry.addLicense(() async* {
@@ -31,8 +41,17 @@ Future<void> main() async {
systemNavigationBarColor: Color(0xff314345),
),
);
final book = await Book.load(), progress = await Progress.load();
final game = Game(book, progress);
await initializeDateFormatting();
final library = await StoryLibrary.load(), progress = await Progress.load();
final deviceLanguage = WidgetsBinding.instance.platformDispatcher.locale
.toLanguageTag();
final preference = progress.text('language', 'system');
final book = await library.open(
progress.text('selected_story', 'mara-island'),
language: preference == 'system' ? deviceLanguage : preference,
);
final game = Game(book, progress, library: library)
..deviceLanguage = deviceLanguage;
await game.restore();
runApp(LumenApp(game: game));
}
@@ -42,24 +61,62 @@ class LumenApp extends StatelessWidget {
final Game game;
final bool adsEnabled;
@override
Widget build(BuildContext context) => MaterialApp(
title: 'Lumen',
debugShowCheckedModeBanner: false,
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: blue, surface: cream),
scaffoldBackgroundColor: cream,
fontFamily: 'MaraHand',
textTheme: ThemeData.light().textTheme.apply(
fontFamily: 'MaraHand',
bodyColor: ink,
displayColor: ink,
),
dialogTheme: const DialogThemeData(backgroundColor: cream),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(textStyle: hand(22), foregroundColor: blue),
),
),
home: Notebook(game: game, adsEnabled: adsEnabled),
Widget build(BuildContext context) => ListenableBuilder(
listenable: game,
builder: (context, _) {
final catalog = game.library?.copy ?? TranslationCatalog.english;
final language = game.requestedLanguage.replaceAll('_', '-');
final locale = localeFromTag(language);
final parts = language.split('-');
final languages = <String>{
...catalog.languages.keys,
...?game.library?.stories.expand((s) => s.languages.keys),
};
final latin = const [
'en',
'de',
'fr',
'es',
'it',
'pt',
'nl',
'da',
'sv',
'no',
'fi',
].contains(parts.first);
return MaterialApp(
title: 'Lumen',
debugShowCheckedModeBanner: false,
locale: locale,
supportedLocales: languages.map(localeFromTag).toList(),
localizationsDelegates: GlobalMaterialLocalizations.delegates,
builder: (context, child) => CopyScope(
catalog: catalog,
language: language,
overrides: game.book.copy,
child: child!,
),
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: blue, surface: cream),
scaffoldBackgroundColor: cream,
fontFamily: latin ? 'MaraHand' : null,
textTheme: ThemeData.light().textTheme.apply(
fontFamily: latin ? 'MaraHand' : null,
bodyColor: ink,
displayColor: ink,
),
dialogTheme: const DialogThemeData(backgroundColor: cream),
textButtonTheme: TextButtonThemeData(
style: TextButton.styleFrom(
textStyle: hand(22),
foregroundColor: blue,
),
),
),
home: Notebook(game: game, adsEnabled: adsEnabled),
);
},
);
}
@@ -88,10 +145,11 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
bool _foreground = true;
String _route = '';
String get route =>
'${g.screen.name}:${g.screen == Screen.story ? g.storyIndex : g.campaignIndex}';
'${g.book.id}:${g.book.language}:${g.screen.name}:${g.screen == Screen.story ? g.storyIndex : g.campaignIndex}';
@override
void initState() {
super.initState();
unawaited(initializeDateFormatting());
narrator = widget.narrator ?? Narrator(g.book.tracks);
ambience = Ambience();
narrator.addListener(_syncAtmosphere);
@@ -107,6 +165,9 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
}
void _changed() {
if (!identical(narrator.tracks, g.book.tracks)) {
narrator.replaceTracks(g.book.tracks);
}
if (_route != route) {
_route = route;
unawaited(narrator.stop());
@@ -124,6 +185,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
_foreground &&
[Screen.story, Screen.briefing, Screen.reveal].contains(g.screen) &&
!(g.screen == Screen.story &&
g.book.isMara &&
g.storyPage.type == StoryPageType.note &&
!prefs.flag('notebook_note_open'));
narrator.scheduleAutoplay(
@@ -142,7 +204,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
Screen.reveal,
].contains(g.screen);
ambience.update(
scene: inStory ? soundscapeFor(g.campaignIndex) : null,
scene: inStory && g.book.isMara ? soundscapeFor(g.campaignIndex) : null,
enabled: atmosphereEnabled,
foreground: _foreground,
narrating: narrator.playing || narrator.loading,
@@ -150,6 +212,20 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
);
}
@override
void didChangeLocales(List<Locale>? locales) {
g.deviceLanguage = locales?.firstOrNull?.toLanguageTag() ?? 'en';
if (g.languagePreference == 'system') {
unawaited(
g.selectLanguage('system').catchError((Object _) {
if (mounted) {
toast('This language could not be opened. Please try again.');
}
}),
);
}
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
_foreground = state == AppLifecycleState.resumed;
@@ -175,7 +251,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(text, style: hand(20, color: cream)),
content: CopyText(text, style: hand(20, color: cream)),
),
);
}
@@ -190,16 +266,16 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
await showDialog<bool>(
context: context,
builder: (c) => AlertDialog(
title: Text(title, style: hand(29)),
content: Text(text, style: hand(23)),
title: CopyText(title, style: hand(29)),
content: CopyText(text, style: hand(23)),
actions: [
TextButton(
onPressed: () => Navigator.pop(c, false),
child: Text(no),
child: CopyText(no),
),
TextButton(
onPressed: () => Navigator.pop(c, true),
child: Text(yes),
child: CopyText(yes),
),
],
),
@@ -213,10 +289,10 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
await showDialog<void>(
context: context,
builder: (c) => AlertDialog(
title: Text(title, style: hand(29)),
content: SingleChildScrollView(child: Text(text, style: hand(23))),
title: CopyText(title, style: hand(29)),
content: SingleChildScrollView(child: CopyText(text, style: hand(23))),
actions: [
TextButton(onPressed: () => Navigator.pop(c), child: Text(close)),
TextButton(onPressed: () => Navigator.pop(c), child: CopyText(close)),
],
),
);
@@ -256,7 +332,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
if (direction > 0) {
g.startCampaign(index);
} else if (index > 0) {
if (index == 4) {
if (index == g.book.continueAt) {
g.showStory(g.book.pages.length - 1);
} else {
g.reveal(index - 1, readAhead: true);
@@ -292,7 +368,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
void nextCampaign() {
final index = g.campaignIndex;
if (index == 11) {
if (index == g.book.levels.length - 1) {
g.contents();
return;
}
@@ -305,7 +381,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
}
if (g.recovered(index) &&
(index + 1) % 4 == 0 &&
g.book.chapterLevels(g.book.chapterFor(index)).last == index &&
!prefs.flag('storyAd_$index')) {
unawaited(prefs.set('storyAd_$index', true));
ads.between(next);
@@ -397,7 +473,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
Expanded(child: Divider(color: muted.withValues(alpha: .3))),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Text('❦', style: hand(27, color: muted)),
child: CopyText('❦', style: hand(27, color: muted)),
),
Expanded(child: Divider(color: muted.withValues(alpha: .3))),
],
@@ -416,7 +492,11 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
constraints: const BoxConstraints(maxWidth: 650),
child: SizedBox(
width: double.infinity,
child: folio('L U M E N / AN ISLAND STORY'),
child: folio(
g.book.isMara
? 'L U M E N / AN ISLAND STORY'
: 'L U M E N / STORY LIBRARY',
),
),
),
),
@@ -429,44 +509,81 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 650),
child: column([
writing('A light to come\nhome to.', size: 40),
Image.asset(
'assets/artwork/home-harbour-v2.png',
height: 220,
fit: BoxFit.contain,
semanticLabel: 'Watercolour of the island at dusk, with the lighthouse and Gran’s cottage.',
),
writing(
'Some things are worth keeping. — Gran',
g.book.isMara
? 'A light to come\nhome to.'
: g.book.title,
size: 40,
),
if (g.book.isMara)
Image.asset(
'assets/artwork/home-harbour-v2.png',
height: 220,
fit: BoxFit.contain,
semanticLabel: 'Watercolour of the island at dusk, with the lighthouse and Gran’s cottage.',
),
writing(
g.book.isMara
? 'Some things are worth keeping. — Gran'
: g.book.description,
size: 25,
color: const Color(0xff70503b),
),
Cover(onTap: g.openNotebook),
if (g.book.isMara)
Cover(onTap: g.openNotebook)
else if (g.book.coverAsset case final asset?)
InkWell(
onTap: g.openNotebook,
child: Image.asset(
asset,
height: 220,
semanticLabel: g.book.title,
),
),
action(
'Open Mara’s notebook · ${g.recoveredCount} / 12',
'Open ${g.book.title} · ${g.recoveredCount} / ${g.book.levels.length}',
g.openNotebook,
primary: true,
),
action('Story library', storyLibrary),
action('Language', chooseLanguage),
if (g.requestedLanguage
.replaceAll('_', '-')
.split('-')
.first !=
g.book.language.split('-').first)
writing(
'This story is shown in its original language.',
size: 18,
color: muted,
),
gap(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Text(
'${g.streak}\nDAY STREAK',
textAlign: TextAlign.center,
style: hand(18, color: blue),
Expanded(
child: CopyText(
'${g.streak}\nDAY STREAK',
textAlign: TextAlign.center,
style: hand(18, color: blue),
),
),
Text(
'${g.solved}\nPATTERNS FOUND',
textAlign: TextAlign.center,
style: hand(18, color: blue),
Expanded(
child: CopyText(
'${g.solved}\nPATTERNS FOUND',
textAlign: TextAlign.center,
style: hand(18, color: blue),
),
),
],
),
divider(),
folio('A SMALL DAILY RITUAL'),
writing(
DateFormat('EEEE, d MMMM').format(DateTime.now()),
DateFormat(
'EEEE, d MMMM',
Localizations.localeOf(context).languageCode,
).format(DateTime.now()),
size: 27,
),
action(
@@ -513,6 +630,153 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
),
),
);
Future<void> storyLibrary() async {
narrator.cancelAutoplay();
final catalogue = g.library;
if (catalogue == null) return;
List<Book> books;
try {
books = await Future.wait(
catalogue.stories.map(
(story) => catalogue.open(story.id, language: g.requestedLanguage),
),
);
} catch (_) {
if (mounted) toast('This story could not be opened. Please try again.');
return;
}
if (!mounted) return;
final selected = await showDialog<String>(
context: context,
builder: (c) => AlertDialog(
title: const CopyText('Story library'),
content: SizedBox(
width: 520,
child: ListView(
shrinkWrap: true,
children: [
for (final story in books)
ListTile(
leading: story.coverAsset == null
? null
: Image.asset(story.coverAsset!, width: 56),
title: Text(story.title),
subtitle: Text(
'${story.description}\n${catalogue.definition(story.id).languages.values.map((v) => v['label']).join(' · ')}',
),
isThreeLine: true,
selected: story.id == g.book.id,
onTap: () => Navigator.pop(c, story.id),
),
],
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(c),
child: const CopyText('Close'),
),
],
),
);
if (selected == null || !mounted) return;
try {
await g.selectStory(selected);
} catch (_) {
if (mounted) toast('This story could not be opened. Please try again.');
}
}
Future<void> chooseLanguage() async {
narrator.cancelAutoplay();
final catalogue = g.library;
if (catalogue == null) return;
final languages = <String, String>{...catalogue.copy.languages};
for (final story in catalogue.stories) {
for (final entry in story.languages.entries) {
languages[entry.key] = entry.value['label'];
}
}
final selected = await showDialog<String>(
context: context,
builder: (c) => SimpleDialog(
title: const CopyText('Language'),
children: [
SimpleDialogOption(
onPressed: () => Navigator.pop(c, 'system'),
child: CopyText(
'${g.languagePreference == 'system' ? '✓ ' : ''}Follow device language',
),
),
for (final entry in languages.entries)
SimpleDialogOption(
onPressed: () => Navigator.pop(c, entry.key),
child: Text(
'${g.languagePreference == entry.key ? '✓ ' : ''}${entry.value}',
),
),
Padding(
padding: const EdgeInsets.all(20),
child: CopyText(
'Missing translations use the story’s original language. Your reading position and puzzle marks are shared across languages.',
style: hand(18),
),
),
],
),
);
if (selected == null || !mounted) return;
try {
await g.selectLanguage(selected);
} catch (_) {
if (mounted) {
toast('This language could not be opened. Please try again.');
}
}
}
Widget standardStory() {
final p = g.storyPage;
final heading = <Widget>[
folio('${g.book.title} / ${g.storyIndex + 1} OF ${g.book.pages.length}'),
writing(p.title, size: 31),
];
final body = <Widget>[
...heading,
if (p.speaker.isNotEmpty) writing(p.speaker, size: 17, color: muted),
if (p.illustrationAsset case final asset?)
Image.asset(
asset,
height: 155,
fit: BoxFit.contain,
semanticLabel: p.caption.isEmpty ? p.title : p.caption,
),
if (p.caption.isNotEmpty) reading(p.caption, size: 18),
if (p.type == StoryPageType.memory)
discoveryArt(g.book.levels[p.campaignIndex!], height: 155),
if (p.text.isNotEmpty) reading(p.text),
if (p.continuation.isNotEmpty) reading(p.continuation),
if (g.book.tracks.containsKey(p.id)) audio(),
if (p.type == StoryPageType.puzzle) puzzleBody(),
if (p.type == StoryPageType.memory)
action(
g.recovered(p.campaignIndex!)
? 'View the solved pattern'
: 'Return to this pattern',
() => g.startCampaign(p.campaignIndex!),
),
];
return Leaf(
key: ValueKey('${g.book.id}-story-${p.id}'),
onTurn: (d) => turn(d),
body: column(body),
wideBody: p.type == StoryPageType.puzzle
? splitPuzzle(side: [...heading, areaPicker(), ...puzzleNotes()])
: null,
footer: navigation(),
);
}
void bookmark() {
unawaited(
prefs.set('notebook_manual_bookmark', g.book.pages[g.storyIndex].id),
@@ -529,7 +793,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
);
final next = InkButton(
g.storyIndex == g.book.pages.length - 1
? 'Across the tide →'
? (g.book.isMara ? 'Across the tide →' : 'Back to contents')
: 'Next leaf →',
() => turn(1),
size: wide ? 19 : 21,
@@ -542,6 +806,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
Expanded(child: InkButton('Contents', g.contents, size: 19)),
const SizedBox(width: 6),
Expanded(child: InkButton('Bookmark', bookmark, size: 19)),
Expanded(child: InkButton('Language', chooseLanguage, size: 19)),
const SizedBox(width: 6),
Expanded(child: InkButton('Close book', g.home, size: 19)),
const SizedBox(width: 6),
@@ -557,6 +822,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
Expanded(child: InkButton('Contents', g.contents, size: 20)),
const SizedBox(width: 6),
Expanded(child: InkButton('Bookmark', bookmark, size: 20)),
Expanded(child: InkButton('Language', chooseLanguage, size: 20)),
const SizedBox(width: 6),
Expanded(child: InkButton('Close book', g.home, size: 20)),
],
@@ -584,7 +850,8 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
padding: const EdgeInsets.symmetric(vertical: 8),
child: Text.rich(
TextSpan(
style: hand(size ?? (g.storyIndex == 0 ? 22 : 21)),
style: hand(size ?? (g.storyIndex == 0 ? 22 : 21))
.copyWith(fontFamily: g.book.fontFamily ?? 'sans-serif'),
children: index < 0
? [TextSpan(text: text)]
: [
@@ -611,7 +878,9 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
: g.book.tracks[recordingId]?['speaker']) ==
'Narrator'
? 'Narrator · recorded story'
: 'Mara · diary reading',
: g.book.isMara
? 'Mara · diary reading'
: '${g.book.tracks[recordingId]?['speaker'] ?? g.storyPage.speaker} · recorded story',
size: 17,
color: muted,
),
@@ -640,162 +909,8 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
InkButton('Sound & atmosphere', soundSettings, size: 18),
]),
);
Widget story() {
final p = g.book.pages[g.storyIndex];
final heading = <Widget>[
folio('THE COTTAGE / ${g.storyIndex + 1} OF ${g.book.pages.length}'),
writing(p.title, size: 31),
];
final body = <Widget>[...heading];
Widget? wideBody;
switch (p.type) {
case StoryPageType.dedication:
body.addAll([
writing('A few things worth keeping', size: 20, color: muted),
divider(),
reading(p.text),
audio(),
]);
case StoryPageType.entry:
body.addAll([
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),
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)),
]);
case StoryPageType.puzzle:
final intro = writing(
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,
);
body.addAll([intro, puzzleBody()]);
wideBody = splitPuzzle(
side: [...heading, intro, areaPicker(), ...puzzleNotes()],
);
case StoryPageType.memory:
body.addAll([
discoveryArt(g.book.levels[p.campaignIndex!], height: 155),
writing(
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),
if (p.continuation.isNotEmpty) reading(p.continuation),
if (g.book.tracks.containsKey(p.id)) audio(),
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')) {
body.addAll([
writing('A folded scrap, tucked between the leaves.'),
GestureDetector(
onTap: openLetter,
child: const Sketch('envelope', height: 190),
),
action('Unfold Gran’s note', openLetter),
writing(
'You don’t have to solve anything to discover this.',
size: 20,
color: muted,
),
]);
} else {
body.addAll([
writing(
'For the crossing',
size: 28,
color: const Color(0xff70503b),
),
reading(p.text),
audio(),
action('Fold the note again', () {
unawaited(narrator.stop());
unawaited(prefs.set('notebook_note_open', false));
setState(() {});
}),
]);
}
case StoryPageType.inspection:
body.addAll([
writing(
prefs.flag('notebook_handle_seen')
? 'A repair made to keep small fingers safe.'
: 'A repair note, tucked into the margin.',
size: 20,
color: muted,
),
reading(p.text),
audio(),
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(
key: ValueKey('story-${g.storyIndex}'),
onTurn: (d) => turn(d),
body: column(body),
wideBody: wideBody,
footer: navigation(),
);
}
void openLetter() {
unawaited(prefs.set('notebook_note_open', true));
_scheduleAutoplay();
setState(() {});
}
Future<void> inspect() async {
await prefs.set('notebook_handle_seen', true);
await message(
'A careful repair',
'The wire is hidden under a strip of cloth. In the margin, Gran has written: “The light matters. So do the hands carrying it.”',
close: 'Keep that thought',
);
if (mounted) setState(() {});
}
void refreshNotebook() => setState(() {});
Widget story() => g.book.isMara ? maraStory() : standardStory();
Future<void> speed() async {
await narrator.pause();
@@ -803,7 +918,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
await showDialog<void>(
context: context,
builder: (c) => SimpleDialog(
title: Text('Recording speed', style: hand(29)),
title: CopyText('Recording speed', style: hand(29)),
children: [
for (final entry in [
(0.85, 'Unhurried · 0.85×'),
@@ -815,7 +930,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
unawaited(prefs.set('recording_speed', entry.$1));
Navigator.pop(c);
},
child: Text(entry.$2, style: hand(23)),
child: CopyText(entry.$2, style: hand(23)),
),
],
),
@@ -836,7 +951,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
}
return AlertDialog(
title: Text('Sound & atmosphere', style: hand(29)),
title: CopyText('Sound & atmosphere', style: hand(29)),
content: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
@@ -844,7 +959,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
children: [
SwitchListTile(
contentPadding: EdgeInsets.zero,
title: Text('Environmental sounds', style: hand(23)),
title: CopyText('Environmental sounds', style: hand(23)),
value: atmosphereEnabled,
onChanged: (value) => save('ambience_enabled', value),
),
@@ -875,7 +990,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
actions: [
TextButton(
onPressed: () => Navigator.pop(dialogContext),
child: const Text('Keep going'),
child: const CopyText('Keep going'),
),
],
);
@@ -886,7 +1001,8 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
Widget contents() {
final chapter = g.contentsChapter;
final first = chapter * 4;
final indices = g.book.chapterLevels(chapter);
final first = indices.first;
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');
@@ -894,9 +1010,18 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
return Leaf(
key: ValueKey('contents-$chapter'),
body: column([
folio('MARA’S NOTEBOOK · CONTENTS'),
folio('${g.book.title.toUpperCase()} · CONTENTS'),
writing(g.book.levels[first].chapter, size: 34),
if (chapter == 0) ...[
if (chapter == 0 && !g.book.isMara) ...[
reading(g.book.premise),
action('Continue reading', g.openNotebook),
if (ribbon != null)
action(
'Return to my ribbon bookmark',
() => g.showStory(g.book.pages.indexOf(ribbon)),
),
],
if (chapter == 0 && g.book.isMara) ...[
writing(
'For you, when you are ready. With all my love, Gran.',
color: const Color(0xff70503b),
@@ -911,7 +1036,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
),
divider(),
],
for (var i = first; i < first + 4; i++) ...[
for (final i in indices) ...[
InkButton(
'${i + 1} · ${g.book.levels[i].title}${g.recovered(i) ? ' ✓' : ''}${chapter == 0 && ribbon?.campaignIndex == i ? ' · ribbon' : ''}',
i <= g.accessible
@@ -925,7 +1050,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
: null,
),
],
if (chapter == 0) ...[
if (chapter == 0 && g.book.isMara) ...[
divider(),
action('The folded note', () => g.showStory(4)),
action('Gran’s repair note', () => g.showStory(5)),
@@ -935,7 +1060,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
),
],
writing(
'${g.recoveredCount} / 12 memories restored',
'${g.recoveredCount} / ${g.book.levels.length} memories restored',
size: 20,
color: muted,
),
@@ -953,7 +1078,8 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
Expanded(
child: InkButton(
'Next chapter →',
chapter < 2 && (chapter + 1) * 4 <= g.accessible
chapter + 1 < g.book.chapters.length &&
g.book.chapterLevels(chapter + 1).first <= g.accessible
? () => g.contents(chapter + 1)
: null,
size: 19,
@@ -972,7 +1098,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
key: ValueKey('briefing-${g.campaignIndex}'),
onTurn: (d) => turnCampaign(d),
body: column([
folio('MARA’S NOTEBOOK / LEAF ${g.campaignIndex + 1}'),
folio('${g.book.title.toUpperCase()} / LEAF ${g.campaignIndex + 1}'),
writing(l.chapter, size: 20, color: blue),
writing(l.title, size: 33),
gap(),
@@ -990,7 +1116,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
action(
g.recovered(g.campaignIndex)
? 'View the solved pattern →'
: prefs.contains('grid_story_v1_${g.campaignIndex}')
: prefs.contains('grid_${g.book.puzzleKey(g.campaignIndex)}')
? 'Continue this pattern →'
: 'Restore the pattern →',
() => g.startCampaign(g.campaignIndex),
@@ -1107,9 +1233,9 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
List<Widget> heading({bool compact = false}) => [
folio(
g.mode == Mode.daily
? 'DAILY / ${DateFormat('d MMMM').format(g.date)}'
? 'DAILY / ${DateFormat('d MMMM', Localizations.localeOf(context).languageCode).format(g.date)}'
: g.mode == Mode.campaign
? 'THE LAST LIGHT / ${g.campaignIndex + 1} OF 12'
? '${g.book.title.toUpperCase()} / ${g.campaignIndex + 1} OF ${g.book.levels.length}'
: 'CLASSIC / ${g.difficulty.label} / LEVEL ${g.playingLevel}',
),
writing(
@@ -1213,7 +1339,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
if (h == null) return;
await message(
'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.'}',
'${CopyScope.text(context, h.explanation)}\n\n${CopyScope.text(context, h.value == 1 ? 'This cell is lit.' : 'This cell stays dark.')}',
);
if (mounted &&
g.key == requested &&
@@ -1286,7 +1412,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
key: ValueKey('reveal-$i'),
onTurn: (d) => turnCampaign(d),
body: column([
folio('MARA’S NOTEBOOK / LEAF ${i + 1}'),
folio('${g.book.title.toUpperCase()} / LEAF ${i + 1}'),
writing(
g.recovered(i)
? 'Something found. Something remembered.'
@@ -1312,15 +1438,15 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
color: const Color(0xff70503b),
),
divider(),
if (i == 11) ...[
if (i == g.book.levels.length - 1) ...[
folio(
g.recoveredCount == 12
g.recoveredCount == g.book.levels.length
? 'THE END · YOUR WATCH HAS BEGUN'
: 'THE LAST PAGE · COME BACK WHENEVER YOU LIKE',
),
writing(
g.recoveredCount == 12
? 'Twelve patterns. One light brought home. The daily puzzle will be here whenever you return.'
g.recoveredCount == g.book.levels.length
? 'Every pattern restored. The daily puzzle will be here whenever you return.'
: 'A light kept in these pages. Your unfinished patterns will be here whenever you return.',
),
action('Return to the notebook', g.contents, primary: true),
@@ -1336,7 +1462,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
await showDialog<void>(
context: context,
builder: (c) => SimpleDialog(
title: Text('Classic practice pace', style: hand(29)),
title: CopyText('Classic practice pace', style: hand(29)),
children: [
for (final d in Difficulty.values)
SimpleDialogOption(
@@ -1344,7 +1470,10 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
g.selectDifficulty(d);
Navigator.pop(c);
},
child: Text('${d.label} — ${d.description}', style: hand(23)),
child: CopyText(
'${CopyScope.text(context, d.label)} — ${CopyScope.text(context, d.description)}',
style: hand(23),
),
),
],
),