Expand Lumen stories and add island postcards
This commit is contained in:
+83
-3
@@ -4,13 +4,24 @@ import 'dart:math' as math;
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
import '../services/progress.dart';
|
||||
import '../services/play_metrics.dart';
|
||||
import 'book.dart';
|
||||
import 'library.dart';
|
||||
import 'puzzle.dart';
|
||||
import 'postcards.dart';
|
||||
|
||||
enum Screen { library, home, story, contents, briefing, game, reveal }
|
||||
enum Screen {
|
||||
library,
|
||||
home,
|
||||
story,
|
||||
contents,
|
||||
briefing,
|
||||
game,
|
||||
reveal,
|
||||
postcards,
|
||||
}
|
||||
|
||||
enum Mode { daily, classic, campaign }
|
||||
enum Mode { daily, classic, campaign, postcard }
|
||||
|
||||
Puzzle generatePractice(Map<String, Object> args) => Puzzle.generate(
|
||||
BigInt.parse(args['seed'] as String),
|
||||
@@ -78,6 +89,65 @@ class Game extends ChangeNotifier {
|
||||
String key = '';
|
||||
bool busy = false;
|
||||
int _request = 0;
|
||||
int postcardIndex = 0, postcardSlot = 0;
|
||||
IslandPostcard get postcard => islandPostcards[postcardIndex];
|
||||
int postcardSolved(int index) => List.generate(
|
||||
IslandPostcard.puzzlesPerOuting,
|
||||
(slot) => store.flag('done_${islandPostcards[index].puzzleKey(slot)}'),
|
||||
).where((done) => done).length;
|
||||
int get postcardsCollected => List.generate(
|
||||
islandPostcards.length,
|
||||
(i) => postcardSolved(i),
|
||||
).where((count) => count == 3).length;
|
||||
bool get todaySolved =>
|
||||
store.flag('done_d${DateTime.now().toIso8601String().substring(0, 10)}');
|
||||
|
||||
void showPostcards() {
|
||||
_request++;
|
||||
busy = false;
|
||||
screen = Screen.postcards;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void startPostcard(int index, [int? slot]) {
|
||||
RangeError.checkValidIndex(index, islandPostcards);
|
||||
_request++;
|
||||
busy = false;
|
||||
postcardIndex = index;
|
||||
postcardSlot =
|
||||
slot ??
|
||||
List.generate(3, (i) => i).firstWhere(
|
||||
(i) => !store.flag('done_${postcard.puzzleKey(i)}'),
|
||||
orElse: () => 0,
|
||||
);
|
||||
RangeError.checkValidIndex(postcardSlot, const [0, 1, 2]);
|
||||
mode = Mode.postcard;
|
||||
unawaited(store.set('postcard_last', index));
|
||||
_read(postcard.puzzle(postcardSlot), postcard.puzzleKey(postcardSlot));
|
||||
_route(Screen.game);
|
||||
}
|
||||
|
||||
/// One opportunity per completed outing, even after a replay or restart.
|
||||
bool claimPostcardBreak() {
|
||||
final placement = 'postcard_break_${postcard.id}';
|
||||
if (postcardSolved(postcardIndex) != 3 || store.flag(placement)) {
|
||||
return false;
|
||||
}
|
||||
unawaited(store.set(placement, true));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool claimPracticeBreak() {
|
||||
final count = store.number('practiceCompleted');
|
||||
if (count == 0 ||
|
||||
count % 4 != 0 ||
|
||||
store.number('practice_ad_claimed') >= count) {
|
||||
return false;
|
||||
}
|
||||
unawaited(store.set('practice_ad_claimed', count));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool get won => progress.flag('done_$key');
|
||||
bool get canUndo => _undo.isNotEmpty && !won;
|
||||
int get solved => progress.number('solved');
|
||||
@@ -135,6 +205,12 @@ class Game extends ChangeNotifier {
|
||||
|
||||
void _route(Screen value) {
|
||||
screen = value;
|
||||
// Postcard outings have their own resume state; never replace a book leaf.
|
||||
if (mode == Mode.postcard ||
|
||||
(value == Screen.game && mode != Mode.campaign)) {
|
||||
notifyListeners();
|
||||
return;
|
||||
}
|
||||
unawaited(progress.set('flutter_screen', value.name));
|
||||
unawaited(
|
||||
progress.set(
|
||||
@@ -384,6 +460,10 @@ class Game extends ChangeNotifier {
|
||||
if (won || puzzle == null || !puzzle!.solved(cells)) return;
|
||||
unawaited(progress.set('done_$key', true));
|
||||
unawaited(progress.set('solved', solved + 1));
|
||||
PlayMetrics(store).event('${mode.name}_completed');
|
||||
if (mode == Mode.postcard && postcardSolved(postcardIndex) == 3) {
|
||||
PlayMetrics(store).event('postcard_collected');
|
||||
}
|
||||
if (mode == Mode.daily) {
|
||||
final day = epochDay(date), last = progress.number('lastDaily', -99999);
|
||||
if (day > last) {
|
||||
@@ -406,7 +486,7 @@ class Game extends ChangeNotifier {
|
||||
),
|
||||
);
|
||||
reveal(campaignIndex);
|
||||
} else {
|
||||
} else if (mode == Mode.classic) {
|
||||
unawaited(progress.set('level_${difficulty.stored}', playingLevel + 1));
|
||||
unawaited(
|
||||
progress.set(
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
// Generated by tool/author_postcard_puzzles.dart. Stable v1 save identities.
|
||||
const postcardPatterns = <(String, List<int>)>[
|
||||
(
|
||||
'0101111010001010010000000',
|
||||
[0, 1, 2, 5, 6, 9, 10, 11, 13, 14, 16, 18, 19, 20, 21, 22, 23],
|
||||
),
|
||||
('0000000000111111110000010', [9, 12, 14, 16, 18, 19, 21, 24]),
|
||||
(
|
||||
'1011010111010101001110011',
|
||||
[0, 1, 3, 4, 5, 6, 7, 8, 12, 13, 14, 15, 16, 17, 20],
|
||||
),
|
||||
(
|
||||
'0110110011100100011101000',
|
||||
[0, 3, 4, 6, 7, 11, 12, 14, 15, 18, 19, 20, 22, 23, 24],
|
||||
),
|
||||
(
|
||||
'1010101011010000001111111',
|
||||
[1, 3, 4, 6, 7, 9, 10, 13, 15, 16, 17, 20, 23, 24],
|
||||
),
|
||||
(
|
||||
'0011010110101010000100101',
|
||||
[1, 2, 3, 5, 6, 8, 9, 10, 11, 12, 18, 20, 21, 23, 24],
|
||||
),
|
||||
(
|
||||
'1101111010000000111100101',
|
||||
[0, 2, 3, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 24],
|
||||
),
|
||||
('0101101110101100100111010', [4, 11, 19, 22]),
|
||||
('1100101001111111001101110', [0, 15, 16, 24]),
|
||||
(
|
||||
'1001101001010011100000010',
|
||||
[
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
8,
|
||||
9,
|
||||
10,
|
||||
11,
|
||||
12,
|
||||
13,
|
||||
14,
|
||||
15,
|
||||
17,
|
||||
18,
|
||||
20,
|
||||
21,
|
||||
22,
|
||||
23,
|
||||
24,
|
||||
],
|
||||
),
|
||||
('0110000110111101111010010', [6, 21, 22]),
|
||||
('0111001101101101001010011', [6, 9, 10, 15, 18, 21, 22]),
|
||||
(
|
||||
'0010000101110101111100000',
|
||||
[2, 3, 4, 6, 8, 9, 11, 12, 15, 16, 17, 18, 19, 21, 22],
|
||||
),
|
||||
('0110011001001011001011110', [7, 8, 14, 16, 17]),
|
||||
('1001101100001110110000100', [0, 3, 4, 11]),
|
||||
(
|
||||
'0111110000011101001011010',
|
||||
[0, 1, 2, 3, 6, 7, 8, 9, 11, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23],
|
||||
),
|
||||
('0010111001100011000101001', [2, 21]),
|
||||
('0111000110011110111010001', [20, 24]),
|
||||
(
|
||||
'1010100111010110001010010',
|
||||
[1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 19, 21, 22, 23],
|
||||
),
|
||||
('1101100110100010001011011', [1, 5, 9, 13, 22]),
|
||||
('1111010100111000111000001', [4, 7, 14, 15, 17, 18, 20, 21]),
|
||||
(
|
||||
'0100100001100010000100001',
|
||||
[1, 2, 3, 6, 7, 8, 12, 13, 14, 15, 17, 19, 21, 23],
|
||||
),
|
||||
('0010011110100000010001010', [12, 13, 21, 22]),
|
||||
('1111101110001011100011011', [8, 9, 12, 17, 19, 20, 23]),
|
||||
(
|
||||
'1110001110001110111010011',
|
||||
[0, 1, 3, 6, 8, 9, 10, 11, 16, 17, 18, 19, 20, 21, 23, 24],
|
||||
),
|
||||
('0001010101100110011111110', [3, 7, 15, 24]),
|
||||
('0110110110110011101011010', [2, 6, 9, 19, 20, 23]),
|
||||
('0001010010111100111010011', [0, 3, 4, 5, 6, 8, 11, 13, 14, 20, 21, 22, 24]),
|
||||
('1000110111010010101000101', [10, 12, 13, 16, 18, 22]),
|
||||
('0111010111011011101001000', [6, 14, 17]),
|
||||
(
|
||||
'0111101001000001110010100',
|
||||
[0, 1, 2, 3, 5, 7, 9, 10, 11, 13, 14, 15, 16, 18, 22, 23],
|
||||
),
|
||||
('1011100101111010011111001', [3, 18, 22]),
|
||||
('0011000100001111001011100', [1, 11, 15, 18, 20]),
|
||||
(
|
||||
'1110000100101000101011000',
|
||||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 11, 14, 15, 16, 17, 18, 19, 24],
|
||||
),
|
||||
('1010110010011010011101010', [7, 9, 10, 13, 18, 21, 23]),
|
||||
('1001111100111110011111001', [3, 9, 17, 18]),
|
||||
(
|
||||
'0010001100100011000110001',
|
||||
[0, 1, 3, 4, 5, 6, 8, 12, 14, 17, 18, 20, 21, 22, 23],
|
||||
),
|
||||
('1011100100100001000100110', [7, 22, 23]),
|
||||
('0001000111101010110110011', [3, 13, 16, 20, 23]),
|
||||
(
|
||||
'0000101000011000011010001',
|
||||
[0, 2, 3, 4, 5, 7, 8, 9, 10, 12, 13, 14, 15, 17, 20, 21, 23, 24],
|
||||
),
|
||||
('1011111000010110011011100', [3, 6, 11, 13, 14, 17, 18, 24]),
|
||||
('0101101111101100111011101', [10, 12, 17, 23]),
|
||||
];
|
||||
@@ -0,0 +1,108 @@
|
||||
import 'postcard_patterns.dart';
|
||||
import 'puzzle.dart';
|
||||
|
||||
/// A separate, unvoiced collection; it never changes a book's saved position.
|
||||
class IslandPostcard {
|
||||
const IslandPostcard(this.id, this.title, this.invitation, this.message);
|
||||
final String id, title, invitation, message;
|
||||
static const puzzlesPerOuting = 3;
|
||||
|
||||
String puzzleKey(int slot) => 'postcard_v1_${id}_$slot';
|
||||
Puzzle puzzle(int slot) {
|
||||
RangeError.checkValidIndex(slot, const [0, 1, 2]);
|
||||
final index = islandPostcards.indexOf(this);
|
||||
final (picture, clues) = postcardPatterns[index * puzzlesPerOuting + slot];
|
||||
final board = Puzzle(5, picture.split('').map(int.parse).toList());
|
||||
for (final clue in clues) {
|
||||
board.given[clue] = true;
|
||||
}
|
||||
return board;
|
||||
}
|
||||
}
|
||||
|
||||
const islandPostcards = <IslandPostcard>[
|
||||
IslandPostcard(
|
||||
'washing-line',
|
||||
'The washing line',
|
||||
'The morning after the light returned, Mara declared the island ready for ordinary adventures. First stop: the washing line.',
|
||||
'Mara pinned a postcard between two socks. On its front she had drawn the lighthouse, slightly crooked.\n\n“Artistic freedom,” she said.\n\nA gust took the sheet beside it and wrapped us both in white. For a moment the world was warm cotton, sunlight and Gran laughing somewhere near my elbow.\n\nWhen we escaped, the postcard was still there. On the back she had written: Nothing remarkable happened today. We were very pleased.\n\nI added a small drawing of the sheet. It looked like a ghost. Gran said that was artistic freedom too.',
|
||||
),
|
||||
IslandPostcard(
|
||||
'bakery-door',
|
||||
'Before the bakery opens',
|
||||
'There is a queue outside the bakery, although the only people in it are Mara, you, and a gull with unreasonable expectations.',
|
||||
'The baker opened the door with flour on one eyebrow.\n\n“Usual?”\n\n“Something adventurous,” said Gran.\n\nHe gave her the usual bun upside down. She considered it carefully and approved.\n\nWe ate on the sea wall, catching the crumbs in our palms. The gull watched with the grave disappointment of someone left out of a will. Gran saved a corner for later, wrapping it in the paper bag.\n\n“For the walk home?” I asked.\n\n“For the person I will be in ten minutes,” she said. “I expect she’ll be hungry.”',
|
||||
),
|
||||
IslandPostcard(
|
||||
'tidal-pool',
|
||||
'A sea in miniature',
|
||||
'Beyond the harbour steps, the falling tide has left a pool no wider than Mara’s kitchen table. Something small is moving beneath the weed.',
|
||||
'We crouched without speaking. A shrimp flickered beneath the water, almost invisible until its shadow moved.\n\nI wanted to point it out. Gran had already seen it. She touched my wrist, gently, and we waited.\n\nA crab emerged carrying a strand of weed like an inconvenient scarf. It climbed a pebble, reconsidered, and climbed down.\n\n“Busy morning,” Gran whispered.\n\nWe left everything where we found it. On our postcard I drew the pool larger than the island, because for those few minutes it had been.',
|
||||
),
|
||||
IslandPostcard(
|
||||
'mended-pocket',
|
||||
'The mended pocket',
|
||||
'A familiar coat hangs beside the cottage door. Today Mara is repairing the pocket that has been dropping treasures all week.',
|
||||
'Out came a button, two smooth stones and a shopping list that said only tea.\n\n“That explains yesterday,” Gran said.\n\nShe guided the needle through the lining while I held the cloth flat. Her stitches were small but not perfectly straight. Mine were neither. We decided the pocket would prefer character to elegance.\n\nWhen it was finished, she put one stone back.\n\n“What’s that for?”\n\n“Nothing yet.”\n\nI had thought a pocket was somewhere to keep things you needed. Gran seemed to think it could also be somewhere to keep a possibility.',
|
||||
),
|
||||
IslandPostcard(
|
||||
'borrowed-ladder',
|
||||
'A ladder between neighbours',
|
||||
'The harbour noticeboard has lost its top screw. A ladder appears outside the cottage with a note tied to the middle rung.',
|
||||
'The note said: Bring it back when the sky is fixed.\n\nGran read it twice. “Ambitious.”\n\nWe carried the ladder together, stopping whenever someone wanted to tell us where it had been before. It had rescued a kite, painted three kitchens and helped hang the Christmas lights in June, which apparently had been a complicated year.\n\nThe noticeboard took five minutes. Returning the ladder took an hour and two cups of tea.\n\nOn our postcard I drew all its rungs. Gran wrote the neighbours’ names in the spaces.',
|
||||
),
|
||||
IslandPostcard(
|
||||
'rain-in-shed',
|
||||
'Rain on the shed roof',
|
||||
'The clouds arrive halfway through your walk. Mara knows a shortcut to shelter, provided you do not mind sharing it with flowerpots.',
|
||||
'The shed smelled of earth and old string. Rain struck the roof in uneven handfuls, then settled into a steady rush.\n\nGran turned a flowerpot over for me to sit on. She took the one with a crack.\n\nWe watched a bright bead of water gather beneath the doorframe. It held on longer than seemed possible.\n\n“I thought we were going somewhere,” I said.\n\n“We are.”\n\n“Where?”\n\nShe listened to the roof. “At the moment, here.”\n\nBy the time the rain stopped, I had forgotten to be disappointed.',
|
||||
),
|
||||
IslandPostcard(
|
||||
'ferry-envelope',
|
||||
'An envelope from the ferry',
|
||||
'The afternoon ferry brings a parcel, a bicycle and a letter addressed to “the house with the stubborn roses.” Everyone knows where that is.',
|
||||
'The letter was from someone who had stayed on the island years ago. She remembered the roses. She remembered a cup with a chipped blue handle. She wanted to know whether the light still turned.\n\nGran read that line quietly. Then she fetched paper.\n\n“Yes,” she wrote.\n\nShe paused, looking towards the window, and passed the pen to me.\n\nI told the stranger about the harbour, the repaired lantern and the sound of Gran’s kettle. It took a whole page to explain that single yes.\n\nWe enclosed a rose petal, pressed flat.',
|
||||
),
|
||||
IslandPostcard(
|
||||
'bell-rope',
|
||||
'The spare bell rope',
|
||||
'A new rope waits beside the harbour bell. The old one has become too frayed for another winter, but Mara is reluctant to throw it away.',
|
||||
'We cut the sound lengths into shorter pieces. One would hold the shed door open. Another would tie the roses back. Gran kept the smallest.\n\n“That one won’t reach anything,” I said.\n\nShe made a loop through the hole in our postcard box. Now it had a handle.\n\nAt noon the harbour keeper tested the new rope. The bell sounded exactly as it always had.\n\nI looked at the old fibres resting in Gran’s palm. Their work had changed, that was all.\n\nOn the walk home, I carried the box.',
|
||||
),
|
||||
IslandPostcard(
|
||||
'hill-bench',
|
||||
'The bench above the roofs',
|
||||
'There is a bench halfway up the hill. Its plaque has weathered blank, but Mara says you can still tell what it was for.',
|
||||
'From the bench, the roofs fitted together like pieces of a puzzle. I could see the bakery chimney and the blue shed where we had waited out the rain.\n\n“Who put this here?” I asked.\n\n“I don’t remember.”\n\n“Doesn’t that bother you?”\n\nGran moved her bag to make room for a man coming slowly up the path. He sat with a grateful sigh. For a while, all three of us watched the ferry.\n\nLater, on the back of the postcard, Gran wrote: Whoever you were, thank you.\n\nWe left a space beneath it.',
|
||||
),
|
||||
IslandPostcard(
|
||||
'blue-cup',
|
||||
'The chipped blue cup',
|
||||
'Mara has invited a neighbour for tea. The good cups are on the high shelf. She reaches for the chipped blue one instead.',
|
||||
'“That’s my cup,” the neighbour said, pleased.\n\nI had thought it belonged to Gran.\n\n“It does,” she told me afterwards. “But it knows how he takes his tea.”\n\nHe stayed until the kitchen windows turned gold. They talked about a boat I had never seen and someone who used to sing very badly while mending it. Neither could remember the song. They tried anyway.\n\nAfter he left, I washed the blue cup carefully.\n\nThere was room on our postcard for the cup, the window, and three very wobbly musical notes.',
|
||||
),
|
||||
IslandPostcard(
|
||||
'kite-tail',
|
||||
'A tail for the kite',
|
||||
'A child on the common has made a kite that keeps diving into the grass. Mara stops to inspect it with great seriousness.',
|
||||
'“Too impatient,” she announced.\n\nThe child looked offended.\n\n“The kite,” Gran added.\n\nWe made a tail from scraps of cloth. I held the frame while the child tied each knot. Gran supplied advice, most of which concerned not standing on the string.\n\nThe first flight failed. The second nearly worked. On the third, the kite lifted above us and stayed.\n\nNobody said anything wise. We just shouted.\n\nI drew it in the corner of the postcard, very small, and left almost everything else blue.',
|
||||
),
|
||||
IslandPostcard(
|
||||
'evening-windows',
|
||||
'Windows at dusk',
|
||||
'You take the long way home as the island lights its windows. Mara asks you to notice how many different colours warmth can be.',
|
||||
'The bakery window was honey-yellow. The boat shed glowed pale green through its dusty glass. In one upstairs room, a reading lamp made a circle no bigger than an open book.\n\nI tried to count them all and lost track.\n\nGran pointed to our cottage. Its window was dark.\n\n“Forgot to leave a lamp on,” she said.\n\nSo we hurried the last little stretch. I turned the switch while she put the kettle on. Then I went outside again to look.\n\nOur light belonged among the others. I had never noticed how much I liked that.',
|
||||
),
|
||||
IslandPostcard(
|
||||
'empty-card',
|
||||
'The card we nearly missed',
|
||||
'Only two blank postcards remain in the box. You suggest saving them for something special. Mara puts one in her coat pocket.',
|
||||
'Nothing particularly special happened. We bought milk. We waited while a delivery van reversed. Gran stopped to free a leaf caught in a spider’s web without breaking the threads.\n\nBack at the cottage, the card was still blank.\n\n“Perhaps tomorrow,” I said.\n\nGran took a pencil and drew the leaf. I added the web, carefully, leaving the place where it had been caught empty.\n\nWe studied our work.\n\n“I’m glad we brought it,” she said.\n\nThe milk had gone warm while we were drawing. We drank it anyway.',
|
||||
),
|
||||
IslandPostcard(
|
||||
'room-for-more',
|
||||
'Room for more',
|
||||
'The postcard box is nearly full. Tonight you carry it up to the lighthouse, where the island looks small enough to hold in both hands.',
|
||||
'We laid the cards along the windowsill: the washing line, the pool, the borrowed ladder. Fourteen small places inside one familiar place.\n\nBelow us, the ferry moved through the evening water. Somewhere behind those roofs, the baker was setting dough for morning.\n\n“What shall we do tomorrow?” I asked.\n\nGran fitted the cards back into their box. There was still room along one side.\n\n“We’ll take a pencil,” she said.\n\nThe light passed over the window and went on across the sea. We stayed a little longer, with no particular reason to hurry home.',
|
||||
),
|
||||
];
|
||||
+141
-10
@@ -19,6 +19,10 @@ import 'services/translation.dart';
|
||||
import 'domain/book.dart';
|
||||
import 'domain/game.dart';
|
||||
import 'domain/puzzle.dart';
|
||||
import 'domain/postcards.dart';
|
||||
import 'services/ad_pacing.dart';
|
||||
import 'services/play_metrics.dart';
|
||||
import 'ui/postcards.dart';
|
||||
import 'services/ads.dart';
|
||||
import 'services/ambience.dart';
|
||||
import 'services/narrator.dart';
|
||||
@@ -204,6 +208,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
late final Narrator narrator;
|
||||
late final Ambience ambience;
|
||||
late final Ads ads;
|
||||
late final PlayMetrics metrics;
|
||||
bool _foreground = true;
|
||||
String _route = '';
|
||||
Future<List<Book>>? _shelf;
|
||||
@@ -217,7 +222,14 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
narrator = widget.narrator ?? Narrator(g.book.tracks);
|
||||
ambience = widget.ambience ?? Ambience();
|
||||
narrator.addListener(_syncAtmosphere);
|
||||
ads = widget.ads ?? Ads(enabled: widget.adsEnabled);
|
||||
metrics = PlayMetrics(g.store)..visit();
|
||||
ads =
|
||||
widget.ads ??
|
||||
Ads(
|
||||
enabled: widget.adsEnabled,
|
||||
pacing: AdPacing(g.store),
|
||||
metrics: metrics,
|
||||
);
|
||||
g.addListener(_changed);
|
||||
_route = route;
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
@@ -299,8 +311,11 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
_foreground = state == AppLifecycleState.resumed;
|
||||
ads.foreground = _foreground;
|
||||
if (_foreground) metrics.visit();
|
||||
_syncAtmosphere();
|
||||
if (state != AppLifecycleState.resumed) {
|
||||
metrics.endVisit();
|
||||
unawaited(narrator.stop());
|
||||
unawaited(prefs.flushed);
|
||||
}
|
||||
@@ -482,6 +497,20 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
}
|
||||
|
||||
void back() {
|
||||
if (g.screen == Screen.postcards) {
|
||||
g.library == null ? g.home() : g.showLibrary();
|
||||
return;
|
||||
}
|
||||
if (g.screen == Screen.game && g.mode == Mode.postcard) {
|
||||
g.showPostcards();
|
||||
return;
|
||||
}
|
||||
if (g.screen == Screen.game &&
|
||||
g.mode != Mode.campaign &&
|
||||
g.library != null) {
|
||||
g.showLibrary();
|
||||
return;
|
||||
}
|
||||
if (g.busy) {
|
||||
g.home();
|
||||
return;
|
||||
@@ -519,6 +548,12 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
Screen.briefing => briefing(),
|
||||
Screen.game => game(),
|
||||
Screen.reveal => reveal(),
|
||||
Screen.postcards => PostcardCollectionView(
|
||||
game: g,
|
||||
onBack: back,
|
||||
onOpen: g.startPostcard,
|
||||
onRead: (index) => unawaited(readPostcard(index)),
|
||||
),
|
||||
},
|
||||
if (g.busy)
|
||||
Positioned.fill(
|
||||
@@ -583,6 +618,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
return LibraryShelf(
|
||||
key: const ValueKey('library'),
|
||||
onSettings: settings,
|
||||
activities: ShelfActivities(game: g, onPostcards: g.showPostcards),
|
||||
builder: (context, width) => FutureBuilder<List<Book>>(
|
||||
future: shelfBooks(catalogue),
|
||||
builder: (context, snapshot) {
|
||||
@@ -792,6 +828,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
),
|
||||
divider(),
|
||||
folio('A SMALL DAILY RITUAL'),
|
||||
action('Island postcards', g.showPostcards),
|
||||
writing(
|
||||
DateFormat(
|
||||
'EEEE, d MMMM',
|
||||
@@ -851,6 +888,8 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
('Sound & atmosphere', soundSettings),
|
||||
('Recording speed', speed),
|
||||
('Privacy & advertising', privacy),
|
||||
if (kDebugMode || appFlavor == 'qa' || appFlavor == 'check')
|
||||
('Playtest report', playtestReport),
|
||||
])
|
||||
SimpleDialogOption(
|
||||
onPressed: () {
|
||||
@@ -863,6 +902,69 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
),
|
||||
);
|
||||
|
||||
Future<void> playtestReport() => showDialog<void>(
|
||||
context: context,
|
||||
builder: (c) => AlertDialog(
|
||||
title: const Text('Local playtest report'),
|
||||
content: SingleChildScrollView(child: SelectableText(metrics.export())),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await Clipboard.setData(ClipboardData(text: metrics.export()));
|
||||
if (c.mounted) Navigator.pop(c);
|
||||
},
|
||||
child: const Text('Copy report'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(c),
|
||||
child: const Text('Close'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Future<void> readPostcard(int index, {bool completedNow = false}) async {
|
||||
if (g.postcardSolved(index) != 3) return;
|
||||
final card = islandPostcards[index];
|
||||
final kept = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (c) => AlertDialog(
|
||||
title: Text(card.title),
|
||||
content: SingleChildScrollView(
|
||||
child: Text(
|
||||
card.message,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'serif',
|
||||
fontSize: 21,
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(c, true),
|
||||
child: const CopyText('Keep this postcard'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
if (kept != true ||
|
||||
!mounted ||
|
||||
!completedNow ||
|
||||
g.mode != Mode.postcard ||
|
||||
g.postcardIndex != index ||
|
||||
g.screen != Screen.game) {
|
||||
return;
|
||||
}
|
||||
if (g.claimPostcardBreak()) {
|
||||
await ads.between(() {
|
||||
if (mounted) g.showPostcards();
|
||||
});
|
||||
} else {
|
||||
g.showPostcards();
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> chooseLanguage() async {
|
||||
narrator.cancelAutoplay();
|
||||
final catalogue = g.library;
|
||||
@@ -1407,6 +1509,8 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
folio(
|
||||
g.mode == Mode.daily
|
||||
? 'DAILY / ${DateFormat('d MMMM', Localizations.localeOf(context).languageCode).format(g.date)}'
|
||||
: g.mode == Mode.postcard
|
||||
? 'POSTCARD / ${g.postcardIndex + 1} / PATTERN ${g.postcardSlot + 1} OF 3'
|
||||
: g.mode == Mode.campaign
|
||||
? '${g.book.title.toUpperCase()} / ${g.campaignIndex + 1} OF ${g.book.levels.length}'
|
||||
: 'CLASSIC / ${g.difficulty.label} / LEVEL ${g.playingLevel}',
|
||||
@@ -1414,6 +1518,8 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
writing(
|
||||
g.mode == Mode.campaign
|
||||
? g.book.levels[g.campaignIndex].title
|
||||
: g.mode == Mode.postcard
|
||||
? g.postcard.title
|
||||
: 'Find the light.',
|
||||
size: compact ? 27 : 32,
|
||||
),
|
||||
@@ -1428,13 +1534,21 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
final actions = <({String label, VoidCallback run, bool primary})>[
|
||||
if (g.won)
|
||||
(
|
||||
label: g.mode == Mode.daily
|
||||
? 'Return to the notebook'
|
||||
label: g.mode == Mode.postcard
|
||||
? (g.postcardSolved(g.postcardIndex) == 3
|
||||
? 'Read your postcard'
|
||||
: 'Next pattern →')
|
||||
: g.mode == Mode.daily
|
||||
? (g.library == null
|
||||
? 'Return to the notebook'
|
||||
: 'Back to the shelf')
|
||||
: g.mode == Mode.campaign
|
||||
? 'Revisit the memory →'
|
||||
: 'Next puzzle →',
|
||||
run: g.mode == Mode.daily
|
||||
? g.home
|
||||
run: g.mode == Mode.postcard
|
||||
? nextPostcard
|
||||
: g.mode == Mode.daily
|
||||
? back
|
||||
: g.mode == Mode.campaign
|
||||
? () => g.reveal(g.campaignIndex)
|
||||
: nextPractice,
|
||||
@@ -1442,8 +1556,16 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
),
|
||||
(label: 'How to play', run: rules, primary: false),
|
||||
(
|
||||
label: 'Back to notebook',
|
||||
run: g.mode == Mode.campaign ? g.contents : g.home,
|
||||
label: g.mode == Mode.postcard
|
||||
? 'Back to postcards'
|
||||
: g.mode != Mode.campaign && g.library != null
|
||||
? 'Back to the shelf'
|
||||
: 'Back to notebook',
|
||||
run: g.mode == Mode.postcard
|
||||
? g.showPostcards
|
||||
: g.mode == Mode.campaign
|
||||
? g.contents
|
||||
: back,
|
||||
primary: false,
|
||||
),
|
||||
];
|
||||
@@ -1558,14 +1680,23 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
}
|
||||
|
||||
void nextPractice() {
|
||||
final n = prefs.number('practiceCompleted');
|
||||
if (n > 0 && n % 4 == 0) {
|
||||
ads.between(() => unawaited(g.startPractice()));
|
||||
if (g.claimPracticeBreak()) {
|
||||
ads.between(() {
|
||||
if (mounted) unawaited(g.startPractice());
|
||||
});
|
||||
} else {
|
||||
unawaited(g.startPractice());
|
||||
}
|
||||
}
|
||||
|
||||
void nextPostcard() {
|
||||
if (g.postcardSolved(g.postcardIndex) == 3) {
|
||||
unawaited(readPostcard(g.postcardIndex, completedNow: true));
|
||||
} else {
|
||||
g.startPostcard(g.postcardIndex);
|
||||
}
|
||||
}
|
||||
|
||||
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.
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import 'progress.dart';
|
||||
|
||||
/// An opportunity is not an impression. Only actual fullscreen displays count.
|
||||
class AdPacing {
|
||||
AdPacing(this.store, {DateTime Function()? clock})
|
||||
: now = clock ?? DateTime.now {
|
||||
started = now();
|
||||
}
|
||||
final Progress store;
|
||||
final DateTime Function() now;
|
||||
late final DateTime started;
|
||||
bool get allowed {
|
||||
final time = now();
|
||||
if (time.difference(started) < const Duration(minutes: 3)) return false;
|
||||
final last = DateTime.tryParse(store.text('ad_last_fullscreen'));
|
||||
if (last != null && time.difference(last) < const Duration(minutes: 3)) {
|
||||
return false;
|
||||
}
|
||||
final day = time.toIso8601String().substring(0, 10);
|
||||
return store.text('ad_cap_day') != day || store.number('ad_cap_count') < 6;
|
||||
}
|
||||
|
||||
void shown({required bool automatic}) {
|
||||
final time = now();
|
||||
store.set('ad_last_fullscreen', time.toIso8601String());
|
||||
if (!automatic) return;
|
||||
final day = time.toIso8601String().substring(0, 10);
|
||||
final count = store.text('ad_cap_day') == day
|
||||
? store.number('ad_cap_count')
|
||||
: 0;
|
||||
store.set('ad_cap_day', day);
|
||||
store.set('ad_cap_count', count + 1);
|
||||
}
|
||||
}
|
||||
+76
-9
@@ -3,9 +3,32 @@ import 'dart:async';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:google_mobile_ads/google_mobile_ads.dart';
|
||||
|
||||
import 'ad_pacing.dart';
|
||||
import 'play_metrics.dart';
|
||||
|
||||
class Ads {
|
||||
Ads({this.enabled = true});
|
||||
Ads({this.enabled = true, this.pacing, this.metrics});
|
||||
final bool enabled;
|
||||
final AdPacing? pacing;
|
||||
final PlayMetrics? metrics;
|
||||
bool _showing = false;
|
||||
bool foreground = true;
|
||||
|
||||
void _paid(AdWithoutView ad, String format) {
|
||||
ad.onPaidEvent = (ad, value, precision, currency) {
|
||||
metrics?.paid(
|
||||
format: format,
|
||||
micros: value,
|
||||
currency: currency,
|
||||
precision: precision.name,
|
||||
test: ad.adUnitId.contains('3940256099942544'),
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
void _impression(Ad ad, String format) => metrics?.event(
|
||||
'${ad.adUnitId.contains('3940256099942544') ? 'test' : 'configured'}_${format}_impressions',
|
||||
);
|
||||
RewardedAd? _reward;
|
||||
InterstitialAd? _interstitial;
|
||||
bool _started = false,
|
||||
@@ -64,6 +87,7 @@ class Ads {
|
||||
return;
|
||||
}
|
||||
_reward = a;
|
||||
_paid(a, 'rewarded');
|
||||
_rewardAt = DateTime.now();
|
||||
},
|
||||
onAdFailedToLoad: (_) {
|
||||
@@ -90,6 +114,7 @@ class Ads {
|
||||
return;
|
||||
}
|
||||
_interstitial = a;
|
||||
_paid(a, 'interstitial');
|
||||
_interstitialAt = DateTime.now();
|
||||
},
|
||||
onAdFailedToLoad: (_) {
|
||||
@@ -101,9 +126,15 @@ class Ads {
|
||||
}
|
||||
|
||||
Future<bool> hint(VoidCallback earned) async {
|
||||
if (!supported || !await ConsentInformation.instance.canRequestAds()) {
|
||||
if (!supported ||
|
||||
_disposed ||
|
||||
_showing ||
|
||||
!foreground ||
|
||||
!await ConsentInformation.instance.canRequestAds()) {
|
||||
return false;
|
||||
}
|
||||
if (_disposed || _showing || !foreground) return false;
|
||||
metrics?.event('rewarded_opportunities');
|
||||
final a = _reward;
|
||||
_reward = null;
|
||||
if (a == null ||
|
||||
@@ -111,31 +142,58 @@ class Ads {
|
||||
DateTime.now().difference(_rewardAt!).inMinutes >= 58) {
|
||||
a?.dispose();
|
||||
unawaited(_load());
|
||||
metrics?.event('rewarded_unavailable');
|
||||
return false;
|
||||
}
|
||||
_showing = true;
|
||||
var granted = false;
|
||||
a.fullScreenContentCallback = FullScreenContentCallback(
|
||||
onAdShowedFullScreenContent: (_) => pacing?.shown(automatic: false),
|
||||
onAdImpression: (ad) => _impression(ad, 'rewarded'),
|
||||
onAdDismissedFullScreenContent: (ad) {
|
||||
_showing = false;
|
||||
ad.dispose();
|
||||
_load();
|
||||
},
|
||||
onAdFailedToShowFullScreenContent: (ad, e) {
|
||||
_showing = false;
|
||||
ad.dispose();
|
||||
_load();
|
||||
},
|
||||
);
|
||||
a.show(
|
||||
onUserEarnedReward: (ad, reward) {
|
||||
earned();
|
||||
},
|
||||
);
|
||||
try {
|
||||
await a.show(
|
||||
onUserEarnedReward: (ad, reward) {
|
||||
if (granted) return;
|
||||
granted = true;
|
||||
metrics?.event('rewarded_earned');
|
||||
earned();
|
||||
},
|
||||
);
|
||||
} catch (_) {
|
||||
_showing = false;
|
||||
a.dispose();
|
||||
unawaited(_load());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Future<void> between(VoidCallback next) async {
|
||||
if (!supported || !await ConsentInformation.instance.canRequestAds()) {
|
||||
if (!supported ||
|
||||
_disposed ||
|
||||
_showing ||
|
||||
!foreground ||
|
||||
!(pacing?.allowed ?? true) ||
|
||||
!await ConsentInformation.instance.canRequestAds()) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
if (_disposed || _showing || !foreground) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
metrics?.event('interstitial_opportunities');
|
||||
final a = _interstitial;
|
||||
_interstitial = null;
|
||||
if (a == null ||
|
||||
@@ -143,23 +201,32 @@ class Ads {
|
||||
DateTime.now().difference(_interstitialAt!).inMinutes >= 58) {
|
||||
a?.dispose();
|
||||
next();
|
||||
metrics?.event('interstitial_unavailable');
|
||||
unawaited(_load());
|
||||
return;
|
||||
}
|
||||
var routed = false;
|
||||
_showing = true;
|
||||
void finish() {
|
||||
if (routed) return;
|
||||
routed = true;
|
||||
_showing = false;
|
||||
a.dispose();
|
||||
next();
|
||||
_load();
|
||||
}
|
||||
|
||||
a.fullScreenContentCallback = FullScreenContentCallback(
|
||||
onAdShowedFullScreenContent: (_) => pacing?.shown(automatic: true),
|
||||
onAdImpression: (ad) => _impression(ad, 'interstitial'),
|
||||
onAdDismissedFullScreenContent: (_) => finish(),
|
||||
onAdFailedToShowFullScreenContent: (_, e) => finish(),
|
||||
);
|
||||
a.show();
|
||||
try {
|
||||
await a.show();
|
||||
} catch (_) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> privacy() async {
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'progress.dart';
|
||||
import '../domain/postcards.dart';
|
||||
|
||||
/// Local diagnostics only. No device identifier, upload or attribution claim.
|
||||
/// Keep currencies separate: an SDK USD receipt is never treated as EUR.
|
||||
class PlayMetrics {
|
||||
PlayMetrics(this.store, {DateTime Function()? clock})
|
||||
: now = clock ?? DateTime.now;
|
||||
final Progress store;
|
||||
final DateTime Function() now;
|
||||
Map<String, dynamic> get _data {
|
||||
final saved = store.text('play_metrics_v1');
|
||||
return saved.isEmpty
|
||||
? <String, dynamic>{}
|
||||
: Map<String, dynamic>.from(jsonDecode(saved) as Map);
|
||||
}
|
||||
|
||||
void _update(void Function(Map<String, dynamic>) edit) {
|
||||
final data = _data;
|
||||
data.putIfAbsent('firstObservedUtc', () => now().toUtc().toIso8601String());
|
||||
edit(data);
|
||||
store.set('play_metrics_v1', jsonEncode(data));
|
||||
}
|
||||
|
||||
void visit() => _update((data) {
|
||||
final stamp = now().toUtc();
|
||||
final last = DateTime.tryParse(data['lastVisitUtc'] as String? ?? '');
|
||||
if (last == null || stamp.difference(last).inMinutes >= 30) {
|
||||
data['sessions'] = (data['sessions'] as int? ?? 0) + 1;
|
||||
}
|
||||
data['lastVisitUtc'] = stamp.toIso8601String();
|
||||
final days = Map<String, dynamic>.from(data['days'] as Map? ?? {});
|
||||
days.putIfAbsent(
|
||||
stamp.toIso8601String().substring(0, 10),
|
||||
() => <String, dynamic>{},
|
||||
);
|
||||
data['days'] = days;
|
||||
});
|
||||
|
||||
void event(String name) => _update((data) {
|
||||
final days = Map<String, dynamic>.from(data['days'] as Map? ?? {});
|
||||
final day = now().toUtc().toIso8601String().substring(0, 10);
|
||||
final counts = Map<String, dynamic>.from(days[day] as Map? ?? {});
|
||||
counts[name] = (counts[name] as int? ?? 0) + 1;
|
||||
days[day] = counts;
|
||||
data['days'] = days;
|
||||
});
|
||||
|
||||
void endVisit() => _update((data) {
|
||||
data['lastVisitUtc'] = now().toUtc().toIso8601String();
|
||||
});
|
||||
|
||||
void paid({
|
||||
required String format,
|
||||
required double micros,
|
||||
required String currency,
|
||||
required String precision,
|
||||
required bool test,
|
||||
}) {
|
||||
if (!micros.isFinite || micros < 0 || currency.isEmpty) return;
|
||||
_update((data) {
|
||||
final revenue = Map<String, dynamic>.from(
|
||||
data['revenueMicros'] as Map? ?? {},
|
||||
);
|
||||
final key =
|
||||
'${test ? 'test' : 'configured'}:$format:$currency:$precision';
|
||||
revenue[key] = (revenue[key] as num? ?? 0) + micros;
|
||||
data['revenueMicros'] = revenue;
|
||||
final byDay = Map<String, dynamic>.from(
|
||||
data['dailyRevenueMicros'] as Map? ?? {},
|
||||
);
|
||||
final day = now().toUtc().toIso8601String().substring(0, 10);
|
||||
final daily = Map<String, dynamic>.from(byDay[day] as Map? ?? {});
|
||||
daily[key] = (daily[key] as num? ?? 0) + micros;
|
||||
byDay[day] = daily;
|
||||
data['dailyRevenueMicros'] = byDay;
|
||||
});
|
||||
event('${test ? 'test' : 'configured'}_${format}_paid_callbacks');
|
||||
}
|
||||
|
||||
String export() => const JsonEncoder.withIndent(' ').convert({
|
||||
'schema': 1,
|
||||
'scope': 'This installation only; observation starts with this app version. No campaign or country attribution. Configured units may still be SDK test devices. SDK revenue can be estimated or absent; reconcile with AdMob.',
|
||||
..._data,
|
||||
'patternsCompleted': store.number('solved'),
|
||||
'postcardsCompleted': islandPostcards
|
||||
.where(
|
||||
(card) => List.generate(
|
||||
3,
|
||||
(slot) => store.flag('done_${card.puzzleKey(slot)}'),
|
||||
).every((done) => done),
|
||||
)
|
||||
.length,
|
||||
});
|
||||
}
|
||||
@@ -23,10 +23,12 @@ class LibraryShelf extends StatelessWidget {
|
||||
super.key,
|
||||
required this.builder,
|
||||
required this.onSettings,
|
||||
this.activities,
|
||||
});
|
||||
|
||||
final Widget Function(BuildContext context, double width) builder;
|
||||
final VoidCallback onSettings;
|
||||
final Widget? activities;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ColoredBox(
|
||||
@@ -76,6 +78,7 @@ class LibraryShelf extends StatelessWidget {
|
||||
const SizedBox(height: 20),
|
||||
Divider(color: _shelfInk.withValues(alpha: .18)),
|
||||
SizedBox(height: compact ? 28 : 44),
|
||||
?activities,
|
||||
CopyText(
|
||||
'Choose a book',
|
||||
style: _type(compact ? 36 : 48, serif: true),
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../domain/game.dart';
|
||||
import '../domain/postcards.dart';
|
||||
import 'translation.dart';
|
||||
|
||||
class ShelfActivities extends StatelessWidget {
|
||||
const ShelfActivities({
|
||||
super.key,
|
||||
required this.game,
|
||||
required this.onPostcards,
|
||||
});
|
||||
final Game game;
|
||||
final VoidCallback onPostcards;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => Container(
|
||||
key: const ValueKey('shelf-activities'),
|
||||
margin: const EdgeInsets.only(bottom: 32),
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xffe5ebe2),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const CopyText(
|
||||
'A little light, every day',
|
||||
style: TextStyle(fontFamily: 'serif', fontSize: 27),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
CopyText(
|
||||
game.todaySolved
|
||||
? 'Today’s pattern is complete. Your next daily puzzle arrives tomorrow.'
|
||||
: 'One fresh daily pattern, or a short walk around Mara’s island.',
|
||||
style: const TextStyle(fontFamily: 'sans-serif', fontSize: 15),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Wrap(
|
||||
spacing: 12,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
FilledButton.icon(
|
||||
key: const ValueKey('shelf-daily'),
|
||||
onPressed: () => game.startDaily(DateTime.now()),
|
||||
icon: Icon(
|
||||
game.todaySolved ? Icons.check : Icons.wb_sunny_outlined,
|
||||
),
|
||||
label: CopyText(
|
||||
game.todaySolved ? 'Revisit today’s puzzle' : 'Today’s puzzle',
|
||||
),
|
||||
),
|
||||
OutlinedButton.icon(
|
||||
key: const ValueKey('shelf-postcards'),
|
||||
onPressed: onPostcards,
|
||||
icon: const Icon(Icons.local_post_office_outlined),
|
||||
label: const CopyText('Island postcards'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
CopyText(
|
||||
'${game.postcardsCollected} / 14 postcards collected',
|
||||
style: const TextStyle(fontFamily: 'sans-serif', fontSize: 13),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class PostcardCollectionView extends StatelessWidget {
|
||||
const PostcardCollectionView({
|
||||
super.key,
|
||||
required this.game,
|
||||
required this.onBack,
|
||||
required this.onOpen,
|
||||
required this.onRead,
|
||||
});
|
||||
final Game game;
|
||||
final VoidCallback onBack;
|
||||
final ValueChanged<int> onOpen, onRead;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => ColoredBox(
|
||||
color: const Color(0xfff6f1e7),
|
||||
child: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
key: const ValueKey('postcard-collection'),
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Center(
|
||||
child: ConstrainedBox(
|
||||
constraints: const BoxConstraints(maxWidth: 760),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: TextButton.icon(
|
||||
onPressed: onBack,
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
label: const CopyText('Back to the shelf'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
const CopyText(
|
||||
'Island postcards',
|
||||
style: TextStyle(fontFamily: 'serif', fontSize: 36),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
const CopyText(
|
||||
'Fourteen small outings after the lighthouse story. Solve three patterns to keep each postcard. Take them at your own pace; nothing expires.',
|
||||
style: TextStyle(fontFamily: 'sans-serif', fontSize: 16),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const CopyText(
|
||||
'Written postcards · English · No recorded reading',
|
||||
style: TextStyle(fontFamily: 'sans-serif', fontSize: 13),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
CopyText('${game.postcardsCollected} / 14 postcards collected'),
|
||||
if (game.store.contains('postcard_last') &&
|
||||
game.postcardSolved(
|
||||
game.store.number('postcard_last').clamp(0, 13),
|
||||
) <
|
||||
3)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 12),
|
||||
child: FilledButton(
|
||||
onPressed: () => onOpen(
|
||||
game.store.number('postcard_last').clamp(0, 13),
|
||||
),
|
||||
child: const CopyText('Continue your outing'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
for (var i = 0; i < islandPostcards.length; i++)
|
||||
Card(
|
||||
margin: const EdgeInsets.only(bottom: 16),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
'${i + 1}. ${islandPostcards[i].title}',
|
||||
style: const TextStyle(
|
||||
fontFamily: 'serif',
|
||||
fontSize: 25,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
islandPostcards[i].invitation,
|
||||
style: const TextStyle(
|
||||
fontFamily: 'sans-serif',
|
||||
fontSize: 16,
|
||||
height: 1.5,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
CopyText(
|
||||
'${game.postcardSolved(i)} / 3 patterns found',
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
if (game.postcardSolved(i) == 3)
|
||||
FilledButton.tonal(
|
||||
key: ValueKey('read-postcard-$i'),
|
||||
onPressed: () => onRead(i),
|
||||
child: const CopyText('Read your postcard'),
|
||||
)
|
||||
else
|
||||
OutlinedButton(
|
||||
key: ValueKey('start-postcard-$i'),
|
||||
onPressed: () => onOpen(i),
|
||||
child: CopyText(
|
||||
game.postcardSolved(i) == 0
|
||||
? 'Begin outing'
|
||||
: 'Continue outing',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user