926 lines
28 KiB
Dart
926 lines
28 KiB
Dart
import 'dart:async';
|
||
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter/foundation.dart';
|
||
import 'package:flutter/services.dart';
|
||
import 'package:intl/intl.dart';
|
||
|
||
import 'domain/book.dart';
|
||
import 'domain/game.dart';
|
||
import 'domain/puzzle.dart';
|
||
import 'services/ads.dart';
|
||
import 'services/narrator.dart';
|
||
import 'services/progress.dart';
|
||
import 'ui/board.dart';
|
||
import 'ui/paper.dart';
|
||
|
||
Future<void> main() async {
|
||
WidgetsFlutterBinding.ensureInitialized();
|
||
LicenseRegistry.addLicense(() async* {
|
||
yield LicenseEntryWithLineBreaks([
|
||
'Dancing Script',
|
||
], await rootBundle.loadString('assets/fonts/OFL.txt'));
|
||
});
|
||
SystemChrome.setSystemUIOverlayStyle(
|
||
const SystemUiOverlayStyle(
|
||
statusBarColor: cream,
|
||
statusBarIconBrightness: Brightness.dark,
|
||
systemNavigationBarColor: Color(0xff314345),
|
||
),
|
||
);
|
||
final book = await Book.load(), progress = await Progress.load();
|
||
final game = Game(book, progress);
|
||
await game.restore();
|
||
runApp(LumenApp(game: game));
|
||
}
|
||
|
||
class LumenApp extends StatelessWidget {
|
||
const LumenApp({super.key, required this.game, this.adsEnabled = true});
|
||
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),
|
||
);
|
||
}
|
||
|
||
class Notebook extends StatefulWidget {
|
||
const Notebook({super.key, required this.game, required this.adsEnabled});
|
||
final Game game;
|
||
final bool adsEnabled;
|
||
@override
|
||
State<Notebook> createState() => _NotebookState();
|
||
}
|
||
|
||
class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||
Game get g => widget.game;
|
||
Progress get prefs => g.progress;
|
||
late final Narrator narrator;
|
||
late final Ads ads;
|
||
String _route = '';
|
||
String get route =>
|
||
'${g.screen.name}:${g.screen == Screen.story ? g.storyIndex : g.campaignIndex}';
|
||
@override
|
||
void initState() {
|
||
super.initState();
|
||
narrator = Narrator(g.book.tracks);
|
||
ads = Ads(enabled: widget.adsEnabled);
|
||
g.addListener(_changed);
|
||
_route = route;
|
||
WidgetsBinding.instance.addObserver(this);
|
||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||
unawaited(ads.start());
|
||
});
|
||
}
|
||
|
||
void _changed() {
|
||
if (_route != route) {
|
||
_route = route;
|
||
unawaited(narrator.stop());
|
||
}
|
||
if (mounted) setState(() {});
|
||
}
|
||
|
||
@override
|
||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||
if (state != AppLifecycleState.resumed) {
|
||
unawaited(narrator.stop());
|
||
unawaited(prefs.flushed);
|
||
}
|
||
}
|
||
|
||
@override
|
||
void dispose() {
|
||
WidgetsBinding.instance.removeObserver(this);
|
||
g.removeListener(_changed);
|
||
narrator.dispose();
|
||
ads.dispose();
|
||
super.dispose();
|
||
}
|
||
|
||
void toast(String text) {
|
||
if (mounted) {
|
||
ScaffoldMessenger.of(context).showSnackBar(
|
||
SnackBar(
|
||
content: Text(text, style: hand(20, color: cream)),
|
||
),
|
||
);
|
||
}
|
||
}
|
||
|
||
Future<bool> confirm(
|
||
String title,
|
||
String text,
|
||
String yes, {
|
||
String no = 'Keep reading',
|
||
}) async =>
|
||
await showDialog<bool>(
|
||
context: context,
|
||
builder: (c) => AlertDialog(
|
||
title: Text(title, style: hand(29)),
|
||
content: Text(text, style: hand(23)),
|
||
actions: [
|
||
TextButton(
|
||
onPressed: () => Navigator.pop(c, false),
|
||
child: Text(no),
|
||
),
|
||
TextButton(
|
||
onPressed: () => Navigator.pop(c, true),
|
||
child: Text(yes),
|
||
),
|
||
],
|
||
),
|
||
) ??
|
||
false;
|
||
Future<void> message(
|
||
String title,
|
||
String text, {
|
||
String close = 'Keep going',
|
||
}) async {
|
||
await showDialog<void>(
|
||
context: context,
|
||
builder: (c) => AlertDialog(
|
||
title: Text(title, style: hand(29)),
|
||
content: SingleChildScrollView(child: Text(text, style: hand(23))),
|
||
actions: [
|
||
TextButton(onPressed: () => Navigator.pop(c), child: Text(close)),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
Future<void> turn(int direction) async {
|
||
final next = (g.storyIndex + direction).clamp(0, 5);
|
||
if (next == g.storyIndex) return;
|
||
if (g.storyIndex == 2 && direction > 0 && !g.won) {
|
||
unawaited(narrator.stop());
|
||
if (!await confirm(
|
||
'Leave a ribbon here?',
|
||
'Your puzzle marks are saved. You can read the memory now and come back to solve the pattern whenever you like.',
|
||
'Read ahead',
|
||
no: 'Keep solving',
|
||
)) {
|
||
return;
|
||
}
|
||
await prefs.set('notebook_read_ahead', true);
|
||
}
|
||
g.showStory(next);
|
||
}
|
||
|
||
void back() {
|
||
if (g.busy) {
|
||
g.home();
|
||
return;
|
||
}
|
||
switch (g.screen) {
|
||
case Screen.story:
|
||
if (g.storyIndex > 0) {
|
||
turn(-1);
|
||
} else {
|
||
g.home();
|
||
}
|
||
case Screen.briefing:
|
||
case Screen.reveal:
|
||
g.contents();
|
||
case Screen.game:
|
||
if (g.mode == Mode.campaign) {
|
||
g.contents();
|
||
} else {
|
||
g.home();
|
||
}
|
||
case Screen.contents:
|
||
g.home();
|
||
case Screen.home:
|
||
break;
|
||
}
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) => PopScope(
|
||
canPop: g.screen == Screen.home && !g.busy,
|
||
onPopInvokedWithResult: (didPop, result) {
|
||
if (!didPop) back();
|
||
},
|
||
child: Scaffold(
|
||
body: Stack(
|
||
children: [
|
||
switch (g.screen) {
|
||
Screen.home => home(),
|
||
Screen.story => story(),
|
||
Screen.contents => contents(),
|
||
Screen.briefing => briefing(),
|
||
Screen.game => game(),
|
||
Screen.reveal => reveal(),
|
||
},
|
||
if (g.busy)
|
||
Positioned.fill(
|
||
child: ColoredBox(
|
||
color: cream.withValues(alpha: .9),
|
||
child: Center(
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: [
|
||
const CircularProgressIndicator(color: blue),
|
||
writing('Finding a fresh pattern…'),
|
||
InkButton('Back to the notebook', g.home),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
Widget column(List<Widget> children) => Column(
|
||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||
children: children,
|
||
);
|
||
Widget action(String title, VoidCallback run, {bool primary = false}) =>
|
||
Padding(
|
||
padding: const EdgeInsets.symmetric(vertical: 5),
|
||
child: InkButton(title, run, primary: primary),
|
||
);
|
||
Widget gap([double n = 16]) => SizedBox(height: n);
|
||
Widget divider() => Padding(
|
||
padding: const EdgeInsets.symmetric(vertical: 18),
|
||
child: Row(
|
||
children: [
|
||
Expanded(child: Divider(color: muted.withValues(alpha: .3))),
|
||
Padding(
|
||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||
child: Text('❦', style: hand(27, color: muted)),
|
||
),
|
||
Expanded(child: Divider(color: muted.withValues(alpha: .3))),
|
||
],
|
||
),
|
||
);
|
||
Widget folio(String text) => writing(text, size: 15, color: blue);
|
||
Widget home() => ColoredBox(
|
||
color: cream,
|
||
child: SafeArea(
|
||
child: SingleChildScrollView(
|
||
key: const ValueKey('home-scroll'),
|
||
padding: const EdgeInsets.fromLTRB(28, 26, 28, 36),
|
||
child: Center(
|
||
child: ConstrainedBox(
|
||
constraints: const BoxConstraints(maxWidth: 650),
|
||
child: column([
|
||
folio('L U M E N / AN ISLAND STORY'),
|
||
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',
|
||
size: 25,
|
||
color: const Color(0xff70503b),
|
||
),
|
||
Cover(onTap: g.openNotebook),
|
||
action(
|
||
'Open Mara’s notebook · ${g.recoveredCount} / 12',
|
||
g.openNotebook,
|
||
primary: true,
|
||
),
|
||
gap(),
|
||
Row(
|
||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||
children: [
|
||
Text(
|
||
'${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),
|
||
),
|
||
],
|
||
),
|
||
divider(),
|
||
folio('A SMALL DAILY RITUAL'),
|
||
writing(
|
||
DateFormat('EEEE, d MMMM').format(DateTime.now()),
|
||
size: 27,
|
||
),
|
||
action(
|
||
'Play today’s puzzle →',
|
||
() => g.startDaily(DateTime.now()),
|
||
),
|
||
gap(),
|
||
folio('BY THE COTTAGE WINDOW'),
|
||
writing(
|
||
'A few spare pages for practice. For overlapping-area puzzles, follow the notebook’s story.',
|
||
size: 22,
|
||
color: muted,
|
||
),
|
||
action('Difficulty · ${g.difficulty.label} ▾', chooseDifficulty),
|
||
action(
|
||
'Practice · ${g.difficulty.label} · Level ${g.practiceLevel}',
|
||
() => unawaited(g.startPractice()),
|
||
),
|
||
action('How to play', rules),
|
||
action('Privacy & advertising', privacy),
|
||
action(
|
||
'Open-source licenses',
|
||
() =>
|
||
showLicensePage(context: context, applicationName: 'Lumen'),
|
||
),
|
||
gap(),
|
||
writing(
|
||
'Leave a light in the window.',
|
||
size: 26,
|
||
color: const Color(0xff70503b),
|
||
),
|
||
]),
|
||
),
|
||
),
|
||
),
|
||
),
|
||
);
|
||
Widget navigation() => column([
|
||
Row(
|
||
children: [
|
||
Expanded(child: InkButton('Contents', g.contents, size: 20)),
|
||
const SizedBox(width: 6),
|
||
Expanded(
|
||
child: InkButton('Bookmark', () {
|
||
unawaited(
|
||
prefs.set(
|
||
'notebook_manual_bookmark',
|
||
g.book.pages[g.storyIndex].id,
|
||
),
|
||
);
|
||
toast('A ribbon marks this page.');
|
||
}, size: 20),
|
||
),
|
||
const SizedBox(width: 6),
|
||
Expanded(child: InkButton('Close book', g.home, size: 20)),
|
||
],
|
||
),
|
||
Row(
|
||
children: [
|
||
Expanded(
|
||
child: InkButton(
|
||
'← Previous leaf',
|
||
g.storyIndex > 0 ? () => turn(-1) : null,
|
||
size: 21,
|
||
),
|
||
),
|
||
const SizedBox(width: 8),
|
||
Expanded(
|
||
child: InkButton(
|
||
g.storyIndex == 5 ? 'End of this trail' : 'Next leaf →',
|
||
g.storyIndex < 5 ? () => turn(1) : null,
|
||
size: 21,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
]);
|
||
Widget reading(String text) => ListenableBuilder(
|
||
listenable: narrator,
|
||
builder: (context, _) {
|
||
final passage = narrator.passage,
|
||
index = passage.isEmpty ? -1 : text.indexOf(passage);
|
||
return Padding(
|
||
padding: const EdgeInsets.symmetric(vertical: 8),
|
||
child: Text.rich(
|
||
TextSpan(
|
||
style: hand(g.storyIndex == 0 ? 22 : 21),
|
||
children: index < 0
|
||
? [TextSpan(text: text)]
|
||
: [
|
||
TextSpan(text: text.substring(0, index)),
|
||
TextSpan(
|
||
text: passage,
|
||
style: TextStyle(
|
||
backgroundColor: amber.withValues(alpha: .35),
|
||
),
|
||
),
|
||
TextSpan(text: text.substring(index + passage.length)),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
},
|
||
);
|
||
Widget audio() => ListenableBuilder(
|
||
listenable: narrator,
|
||
builder: (context, _) => column([
|
||
Row(
|
||
children: [
|
||
Expanded(
|
||
flex: 3,
|
||
child: InkButton(
|
||
narrator.label,
|
||
narrator.loading
|
||
? null
|
||
: () => narrator.toggle(
|
||
g.book.pages[g.storyIndex].id,
|
||
prefs.decimal('recording_speed'),
|
||
),
|
||
size: 21,
|
||
),
|
||
),
|
||
const SizedBox(width: 5),
|
||
Expanded(child: InkButton('Stop', () => narrator.stop(), size: 21)),
|
||
const SizedBox(width: 5),
|
||
Expanded(child: InkButton('Speed', speed, size: 21)),
|
||
],
|
||
),
|
||
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 body = <Widget>[
|
||
folio('MARA’S NOTEBOOK / ${g.storyIndex + 1} OF 6'),
|
||
writing(p.title, size: 31),
|
||
];
|
||
switch (g.storyIndex) {
|
||
case 0:
|
||
body.addAll([
|
||
writing('A few things worth keeping', size: 20, color: muted),
|
||
divider(),
|
||
reading(p.text),
|
||
audio(),
|
||
]);
|
||
case 1:
|
||
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),
|
||
reading(p.text),
|
||
audio(),
|
||
]);
|
||
case 2:
|
||
body.addAll([
|
||
writing(
|
||
'Restore a small light, or leave a bookmark and read on.',
|
||
size: 21,
|
||
color: muted,
|
||
),
|
||
puzzleBody(),
|
||
]);
|
||
case 3:
|
||
body.addAll([
|
||
const Sketch('match'),
|
||
writing(
|
||
g.recovered(0)
|
||
? 'A pattern restored · a memory kept'
|
||
: 'A memory to read · your puzzle can wait',
|
||
size: 17,
|
||
color: muted,
|
||
),
|
||
reading(p.text),
|
||
audio(),
|
||
]);
|
||
case 4:
|
||
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 5:
|
||
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.',
|
||
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);
|
||
}),
|
||
]);
|
||
}
|
||
return Leaf(
|
||
key: ValueKey('story-${g.storyIndex}'),
|
||
onTurn: (d) => turn(d),
|
||
body: column(body),
|
||
footer: navigation(),
|
||
);
|
||
}
|
||
|
||
void openLetter() {
|
||
unawaited(prefs.set('notebook_note_open', true));
|
||
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(() {});
|
||
}
|
||
|
||
Future<void> speed() async {
|
||
await narrator.pause();
|
||
if (!mounted) return;
|
||
await showDialog<void>(
|
||
context: context,
|
||
builder: (c) => SimpleDialog(
|
||
title: Text('Recording speed', style: hand(29)),
|
||
children: [
|
||
for (final entry in [
|
||
(0.85, 'Unhurried · 0.85×'),
|
||
(1.0, 'Original reading · 1.0×'),
|
||
(1.15, 'A little faster · 1.15×'),
|
||
])
|
||
SimpleDialogOption(
|
||
onPressed: () {
|
||
unawaited(prefs.set('recording_speed', entry.$1));
|
||
Navigator.pop(c);
|
||
},
|
||
child: Text(entry.$2, style: hand(23)),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
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),
|
||
],
|
||
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' : ''}',
|
||
i <= g.accessible
|
||
? () {
|
||
if (g.recovered(i)) {
|
||
g.reveal(i);
|
||
} else {
|
||
g.briefing(i);
|
||
}
|
||
}
|
||
: null,
|
||
),
|
||
),
|
||
],
|
||
action('Close the notebook', g.home),
|
||
]),
|
||
);
|
||
Widget briefing() {
|
||
final l = g.book.levels[g.campaignIndex];
|
||
return Leaf(
|
||
key: ValueKey('briefing-${g.campaignIndex}'),
|
||
body: column([
|
||
folio('MARA’S NOTEBOOK / LEAF ${g.campaignIndex + 1}'),
|
||
writing(l.chapter, size: 20, color: blue),
|
||
writing(l.title, size: 33),
|
||
gap(),
|
||
writing(l.before, size: 25),
|
||
divider(),
|
||
writing(
|
||
g.campaignIndex < 2
|
||
? 'Light the cells to match each row and column total. Cross out the cells that stay dark. The finished grid is a picture from the story.'
|
||
: 'A, B and C are outlined areas with their own light totals. Shared cells count in each area they belong to. Compare clues and subtract their shared parts to find new deductions.',
|
||
size: 22,
|
||
color: muted,
|
||
),
|
||
action(
|
||
prefs.contains('grid_story_v1_${g.campaignIndex}')
|
||
? 'Continue this pattern →'
|
||
: 'Restore the pattern →',
|
||
() => g.startCampaign(g.campaignIndex),
|
||
primary: true,
|
||
),
|
||
action('Back to notebook', g.contents),
|
||
]),
|
||
);
|
||
}
|
||
|
||
Widget puzzleBody() {
|
||
final p = g.puzzle;
|
||
if (p == null) return const SizedBox.shrink();
|
||
return column([
|
||
if (p.regions.isNotEmpty) ...[
|
||
Wrap(
|
||
spacing: 6,
|
||
children: [
|
||
for (var i = 0; i < p.regions.length; i++)
|
||
InkButton(
|
||
'${p.regions[i].label} · ${List.generate(g.cells.length, (j) => j).where((j) => p.regions[i].contains(j, p.size) && g.cells[j] == 1).length} / ${p.regionTotal(p.regions[i])}',
|
||
() => g.area(i),
|
||
size: 21,
|
||
primary: i == g.selectedArea,
|
||
),
|
||
],
|
||
),
|
||
writing('Tap A, B or C to highlight its area', size: 17, color: muted),
|
||
],
|
||
Board(
|
||
puzzle: p,
|
||
cells: g.cells,
|
||
onMark: g.mark,
|
||
selectedArea: g.selectedArea,
|
||
won: g.won,
|
||
),
|
||
writing(
|
||
g.won
|
||
? 'Already restored. Turn the leaf to revisit the memory.'
|
||
: 'Tap: light → cross → clear. Mark every cell.',
|
||
size: 18,
|
||
color: muted,
|
||
),
|
||
if (!g.won)
|
||
Row(
|
||
children: [
|
||
Expanded(
|
||
child: InkButton(
|
||
'Undo a mark',
|
||
g.canUndo ? g.undo : null,
|
||
size: 22,
|
||
),
|
||
),
|
||
const SizedBox(width: 8),
|
||
Expanded(
|
||
child: InkButton(
|
||
prefs.flag('hint_${g.key}')
|
||
? 'Hint · rewarded ad'
|
||
: 'Hint · free',
|
||
hint,
|
||
size: 22,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
]);
|
||
}
|
||
|
||
Widget game() => Leaf(
|
||
key: ValueKey('game-${g.key}'),
|
||
body: column([
|
||
folio(
|
||
g.mode == Mode.daily
|
||
? 'DAILY / ${DateFormat('d MMMM').format(g.date)}'
|
||
: g.mode == Mode.campaign
|
||
? 'THE LAST LIGHT / ${g.campaignIndex + 1} OF 12'
|
||
: 'CLASSIC / ${g.difficulty.label} / LEVEL ${g.playingLevel}',
|
||
),
|
||
writing(
|
||
g.mode == Mode.campaign
|
||
? g.book.levels[g.campaignIndex].title
|
||
: 'Find the light.',
|
||
size: 32,
|
||
),
|
||
writing(
|
||
g.puzzle!.regions.isEmpty
|
||
? 'Match the totals. Let the pattern emerge.'
|
||
: 'Compare rows, columns and overlapping areas.',
|
||
size: 21,
|
||
color: muted,
|
||
),
|
||
puzzleBody(),
|
||
if (g.won) ...[
|
||
writing('A moment of clarity.', size: 29),
|
||
action(
|
||
g.mode == Mode.daily ? 'Return to the notebook' : 'Next puzzle →',
|
||
g.mode == Mode.daily ? g.home : nextPractice,
|
||
primary: true,
|
||
),
|
||
],
|
||
action('How to play', rules),
|
||
action('Back to notebook', g.mode == Mode.campaign ? g.contents : g.home),
|
||
]),
|
||
);
|
||
Future<void> hint() async {
|
||
final requested = g.key;
|
||
void give() async {
|
||
if (!mounted ||
|
||
g.key != requested ||
|
||
g.won ||
|
||
!(g.screen == Screen.game ||
|
||
g.screen == Screen.story && g.storyIndex == 2)) {
|
||
return;
|
||
}
|
||
final h = g.applyHint();
|
||
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.'}',
|
||
);
|
||
if (mounted && g.key == requested) g.check();
|
||
}
|
||
|
||
if (!prefs.flag('hint_$requested')) {
|
||
await prefs.set('hint_$requested', true);
|
||
give();
|
||
return;
|
||
}
|
||
if (!await confirm(
|
||
'A little nudge?',
|
||
'Watch a rewarded ad for one explained hint.',
|
||
'Watch ad',
|
||
no: 'Keep thinking',
|
||
)) {
|
||
return;
|
||
}
|
||
if (!await ads.hint(give)) {
|
||
toast('No ad available. Please try again later.');
|
||
}
|
||
}
|
||
|
||
void nextPractice() {
|
||
final n = prefs.number('practiceCompleted');
|
||
if (n > 0 && n % 4 == 0) {
|
||
ads.between(() => unawaited(g.startPractice()));
|
||
} else {
|
||
unawaited(g.startPractice());
|
||
}
|
||
}
|
||
|
||
Widget reveal() {
|
||
final i = g.campaignIndex, l = g.book.levels[i];
|
||
return Leaf(
|
||
key: ValueKey('reveal-$i'),
|
||
body: column([
|
||
folio('MARA’S NOTEBOOK / LEAF ${i + 1}'),
|
||
writing(
|
||
'Something found. Something remembered.',
|
||
size: 23,
|
||
color: muted,
|
||
),
|
||
writing(l.object, size: 35),
|
||
PixelPicture(l.picture, label: l.object),
|
||
writing(l.after, size: 25),
|
||
gap(),
|
||
writing(
|
||
'Kept safe, between these pages. — M.',
|
||
size: 23,
|
||
color: const Color(0xff70503b),
|
||
),
|
||
divider(),
|
||
if (i == 11) ...[
|
||
folio('THE END · YOUR WATCH HAS BEGUN'),
|
||
writing(
|
||
'Twelve patterns. One light brought home. The daily puzzle will be here whenever you return.',
|
||
),
|
||
action('Return to the notebook', g.contents, primary: true),
|
||
action('Today’s puzzle', () => g.startDaily(DateTime.now())),
|
||
] else
|
||
action('Turn the page →', () {
|
||
void next() {
|
||
if (mounted) g.briefing(i + 1);
|
||
}
|
||
|
||
if ((i + 1) % 4 == 0 && !prefs.flag('storyAd_$i')) {
|
||
unawaited(prefs.set('storyAd_$i', true));
|
||
ads.between(next);
|
||
} else {
|
||
next();
|
||
}
|
||
}, primary: true),
|
||
action('Back to notebook', g.contents),
|
||
]),
|
||
);
|
||
}
|
||
|
||
Future<void> chooseDifficulty() async {
|
||
await showDialog<void>(
|
||
context: context,
|
||
builder: (c) => SimpleDialog(
|
||
title: Text('Classic practice pace', style: hand(29)),
|
||
children: [
|
||
for (final d in Difficulty.values)
|
||
SimpleDialogOption(
|
||
onPressed: () {
|
||
g.selectDifficulty(d);
|
||
Navigator.pop(c);
|
||
},
|
||
child: Text('${d.label} — ${d.description}', style: hand(23)),
|
||
),
|
||
],
|
||
),
|
||
);
|
||
}
|
||
|
||
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.',
|
||
close: 'Got it',
|
||
);
|
||
Future<void> privacy() async {
|
||
if (!await ads.privacy()) {
|
||
await message(
|
||
'Privacy & advertising',
|
||
'Game progress stays on this device. No account or game backend is used. Google advertising services may process device and ad interaction data when ads are available.\n\nNo advertising privacy options are currently required or available for your region.',
|
||
close: 'Close',
|
||
);
|
||
}
|
||
}
|
||
}
|