Open Lumen on a responsive bookshelf and land pending story work
- Start the app on a shelf of every installed book instead of the last book's home. Cards show the cover, translated metadata, available languages, restored patterns and either "Continue reading" or a way in. - Keep each book's saved route: the shelf is never written to flutter_screen, so choosing a book resumes its own leaf. - Lay the shelf out responsively: dense single-column cards on phones, a two-column grid from 720 logical pixels, a centred 860 px column on tablets and a chevron that exists in the bundled handwriting font. - Keep Settings reachable from the shelf and let the home page's story library button open the shelf instead of a dialog. - Add tool/shelf_screenshots_test.dart, which renders the shelf at phone and tablet metrics, checks that every card and Settings stay reachable without overflow, and writes artifacts/library/shelf-*.png. - Commit the pending Midnight Invitation package (campaign, notebook, narration and artwork), cast drama and ambience tooling, region selection, phone/tablet integration coverage and related docs. flutter analyze is clean and all 74 widget/domain tests pass.
This commit is contained in:
+24
-1
@@ -4,6 +4,7 @@ import 'package:flutter/services.dart';
|
||||
|
||||
import 'puzzle.dart';
|
||||
import 'library.dart';
|
||||
import 'soundscape.dart';
|
||||
|
||||
class CampaignLevel {
|
||||
CampaignLevel(Map<String, dynamic> data)
|
||||
@@ -97,13 +98,15 @@ class Book {
|
||||
this.defaultLanguage = 'en',
|
||||
this.presentation = 'mara',
|
||||
this.coverAsset = 'assets/artwork/home-notebook-cover-v2.png',
|
||||
this.paperAsset,
|
||||
this.continueAt = 4,
|
||||
this.initiallyAccessible = 3,
|
||||
this.fontFamily = 'MaraHand',
|
||||
this.copy = const {},
|
||||
this.atmosphere = const {},
|
||||
});
|
||||
final String id, title, description, language, defaultLanguage, presentation;
|
||||
final String? coverAsset, fontFamily;
|
||||
final String? coverAsset, paperAsset, fontFamily;
|
||||
final int? continueAt;
|
||||
final int initiallyAccessible;
|
||||
final Map<String, String> copy;
|
||||
@@ -111,6 +114,7 @@ class Book {
|
||||
final List<CampaignLevel> levels;
|
||||
final List<StoryPage> pages;
|
||||
final Map<String, dynamic> tracks;
|
||||
final Map<String, Soundscape> atmosphere;
|
||||
bool get isMara => presentation == 'mara';
|
||||
List<String> get chapters => levels.map((l) => l.chapterId).toSet().toList();
|
||||
List<int> chapterLevels(int chapter) => [
|
||||
@@ -281,11 +285,29 @@ class Book {
|
||||
final tracks = trackPath == null
|
||||
? <String, dynamic>{}
|
||||
: Map<String, dynamic>.from((await read(trackPath))['tracks']);
|
||||
final atmosphere = <String, Soundscape>{};
|
||||
if (definition.atmosphereAsset != null) {
|
||||
final data = await read(definition.atmosphereAsset!);
|
||||
final scenes = data['scenes'] as Map;
|
||||
final pageIds = pages.map((p) => p.id).toSet();
|
||||
for (final entry in (data['pages'] as Map).entries) {
|
||||
final asset = scenes[entry.value]?['asset'];
|
||||
if (!pageIds.contains(entry.key) ||
|
||||
asset is! String ||
|
||||
!asset.startsWith('assets/') ||
|
||||
asset.contains('..') ||
|
||||
!asset.endsWith('.wav')) {
|
||||
throw FormatException('Invalid atmosphere: ${entry.key}');
|
||||
}
|
||||
atmosphere[entry.key as String] = Soundscape(asset);
|
||||
}
|
||||
}
|
||||
return Book(
|
||||
translation['premise'] as String? ?? campaign['premise'],
|
||||
levels,
|
||||
pages,
|
||||
tracks,
|
||||
atmosphere: Map.unmodifiable(atmosphere),
|
||||
id: definition.id,
|
||||
title: translation['title'] as String? ?? definition.title,
|
||||
description:
|
||||
@@ -294,6 +316,7 @@ class Book {
|
||||
defaultLanguage: definition.defaultLanguage,
|
||||
presentation: definition.presentation,
|
||||
coverAsset: translation['coverAsset'] as String? ?? definition.coverAsset,
|
||||
paperAsset: translation['paperAsset'] as String? ?? definition.paperAsset,
|
||||
continueAt: definition.continueAt,
|
||||
initiallyAccessible: definition.initiallyAccessible.clamp(
|
||||
0,
|
||||
|
||||
+30
-1
@@ -8,7 +8,7 @@ import 'book.dart';
|
||||
import 'library.dart';
|
||||
import 'puzzle.dart';
|
||||
|
||||
enum Screen { home, story, contents, briefing, game, reveal }
|
||||
enum Screen { library, home, story, contents, briefing, game, reveal }
|
||||
|
||||
enum Mode { daily, classic, campaign }
|
||||
|
||||
@@ -149,6 +149,35 @@ class Game extends ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
/// Claim one of three reading breaks, persisted independently for each book.
|
||||
/// Existing chapter-ad records count toward the same lifetime cap.
|
||||
bool claimBookAd(int position, int total) {
|
||||
final oldCount = List.generate(
|
||||
book.levels.length,
|
||||
(i) => i,
|
||||
).where((i) => progress.flag('storyAd_$i')).length;
|
||||
final used = List.generate(
|
||||
3,
|
||||
(i) => i + 1,
|
||||
).where((slot) => progress.flag('storyAd_break_$slot')).length;
|
||||
if (oldCount + used >= 3) return false;
|
||||
final slot = (position * 3 ~/ total).clamp(0, 3);
|
||||
if (slot == 0 || progress.flag('storyAd_break_$slot')) return false;
|
||||
unawaited(progress.set('storyAd_break_$slot', true));
|
||||
return true;
|
||||
}
|
||||
|
||||
/// The shelf is the app's first window. It is deliberately not written to a
|
||||
/// story's saved route (`flutter_screen`), so every book keeps its own reading
|
||||
/// position and the next launch still opens the shelf.
|
||||
void showLibrary() {
|
||||
if (library == null) return;
|
||||
_request++;
|
||||
busy = false;
|
||||
screen = Screen.library;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void home() {
|
||||
_request++;
|
||||
busy = false;
|
||||
|
||||
@@ -12,6 +12,7 @@ class StoryDefinition {
|
||||
title = data['title'],
|
||||
description = data['description'] ?? '',
|
||||
coverAsset = data['coverAsset'],
|
||||
paperAsset = data['paperAsset'],
|
||||
defaultLanguage = (data['defaultLanguage'] as String? ?? 'en')
|
||||
.replaceAll('_', '-')
|
||||
.toLowerCase(),
|
||||
@@ -19,6 +20,7 @@ class StoryDefinition {
|
||||
notebookAsset = data['notebookAsset'],
|
||||
scriptsAsset = data['scriptsAsset'],
|
||||
tracksAsset = data['tracksAsset'],
|
||||
atmosphereAsset = data['atmosphereAsset'],
|
||||
presentation = data['presentation'] ?? 'standard',
|
||||
continueAt = data['continueAt'],
|
||||
initiallyAccessible = data['initiallyAccessible'] ?? 0,
|
||||
@@ -29,7 +31,11 @@ class StoryDefinition {
|
||||
|
||||
final String id, title, description, defaultLanguage, presentation;
|
||||
final String campaignAsset, notebookAsset;
|
||||
final String? coverAsset, scriptsAsset, tracksAsset;
|
||||
final String? coverAsset,
|
||||
paperAsset,
|
||||
scriptsAsset,
|
||||
tracksAsset,
|
||||
atmosphereAsset;
|
||||
final int? continueAt;
|
||||
final int initiallyAccessible;
|
||||
final Map<String, dynamic> languages;
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/// A bundled, language-independent loop. Story packages can supply their own.
|
||||
class Soundscape {
|
||||
const Soundscape(this.asset);
|
||||
final String asset;
|
||||
|
||||
static const cottage = Soundscape('assets/audio/ambience_cottage.wav');
|
||||
static const harbour = Soundscape('assets/audio/ambience_harbour.wav');
|
||||
static const bridge = Soundscape('assets/audio/ambience_bridge.wav');
|
||||
static const tower = Soundscape('assets/audio/ambience_tower.wav');
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) => other is Soundscape && asset == other.asset;
|
||||
@override
|
||||
int get hashCode => asset.hashCode;
|
||||
}
|
||||
+408
-186
@@ -53,6 +53,9 @@ Future<void> main() async {
|
||||
final game = Game(book, progress, library: library)
|
||||
..deviceLanguage = deviceLanguage;
|
||||
await game.restore();
|
||||
// The shelf is the first window. `restore()` has already positioned each
|
||||
// book's saved leaf, so choosing a book resumes exactly where it was left.
|
||||
game.showLibrary();
|
||||
runApp(LumenApp(game: game));
|
||||
}
|
||||
|
||||
@@ -126,11 +129,13 @@ class Notebook extends StatefulWidget {
|
||||
required this.game,
|
||||
required this.adsEnabled,
|
||||
this.narrator,
|
||||
this.ambience,
|
||||
this.ads,
|
||||
});
|
||||
final Game game;
|
||||
final bool adsEnabled;
|
||||
final Narrator? narrator;
|
||||
final Ambience? ambience;
|
||||
final Ads? ads;
|
||||
@override
|
||||
State<Notebook> createState() => _NotebookState();
|
||||
@@ -144,6 +149,8 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
late final Ads ads;
|
||||
bool _foreground = true;
|
||||
String _route = '';
|
||||
Future<List<Book>>? _shelf;
|
||||
String _shelfLanguage = '';
|
||||
String get route =>
|
||||
'${g.book.id}:${g.book.language}:${g.screen.name}:${g.screen == Screen.story ? g.storyIndex : g.campaignIndex}';
|
||||
@override
|
||||
@@ -151,7 +158,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
super.initState();
|
||||
unawaited(initializeDateFormatting());
|
||||
narrator = widget.narrator ?? Narrator(g.book.tracks);
|
||||
ambience = Ambience();
|
||||
ambience = widget.ambience ?? Ambience();
|
||||
narrator.addListener(_syncAtmosphere);
|
||||
ads = widget.ads ?? Ads(enabled: widget.adsEnabled);
|
||||
g.addListener(_changed);
|
||||
@@ -204,7 +211,13 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
Screen.reveal,
|
||||
].contains(g.screen);
|
||||
ambience.update(
|
||||
scene: inStory && g.book.isMara ? soundscapeFor(g.campaignIndex) : null,
|
||||
scene: !inStory
|
||||
? null
|
||||
: g.book.isMara
|
||||
? soundscapeFor(g.campaignIndex)
|
||||
: g.screen == Screen.story
|
||||
? g.book.atmosphere[g.storyPage.id]
|
||||
: null,
|
||||
enabled: atmosphereEnabled,
|
||||
foreground: _foreground,
|
||||
narrating: narrator.playing || narrator.loading,
|
||||
@@ -300,7 +313,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
|
||||
Future<void> turn(int direction) async {
|
||||
if (direction > 0 && g.storyIndex == g.book.pages.length - 1) {
|
||||
crossToHarbour();
|
||||
readingBreak(g.book.pages.length, crossToHarbour);
|
||||
return;
|
||||
}
|
||||
final next = (g.storyIndex + direction).clamp(0, g.book.pages.length - 1);
|
||||
@@ -318,7 +331,29 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
}
|
||||
await prefs.set('notebook_read_ahead', true);
|
||||
}
|
||||
if (mounted && g.storyPage.id == pageId) g.showStory(next);
|
||||
if (mounted && g.storyPage.id == pageId) {
|
||||
if (direction > 0) {
|
||||
readingBreak(next, () => g.showStory(next));
|
||||
} else {
|
||||
g.showStory(next);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void readingBreak(int position, VoidCallback next) {
|
||||
final book = g.book;
|
||||
final legacyLevels = book.continueAt == null
|
||||
? 0
|
||||
: book.levels.length - book.continueAt!;
|
||||
final total = book.pages.length + legacyLevels * 3;
|
||||
if (g.claimBookAd(position, total)) {
|
||||
unawaited(narrator.stop());
|
||||
ads.between(() {
|
||||
if (mounted && g.book == book) next();
|
||||
});
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
}
|
||||
|
||||
void crossToHarbour() {
|
||||
@@ -369,7 +404,10 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
void nextCampaign() {
|
||||
final index = g.campaignIndex;
|
||||
if (index == g.book.levels.length - 1) {
|
||||
g.contents();
|
||||
readingBreak(
|
||||
g.book.pages.length + (index - (g.book.continueAt ?? 0) + 1) * 3,
|
||||
g.contents,
|
||||
);
|
||||
return;
|
||||
}
|
||||
// Reading access is distinct from completed puzzles and their awards.
|
||||
@@ -380,14 +418,10 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
if (mounted) g.briefing(index + 1);
|
||||
}
|
||||
|
||||
if (g.recovered(index) &&
|
||||
g.book.chapterLevels(g.book.chapterFor(index)).last == index &&
|
||||
!prefs.flag('storyAd_$index')) {
|
||||
unawaited(prefs.set('storyAd_$index', true));
|
||||
ads.between(next);
|
||||
} else {
|
||||
next();
|
||||
}
|
||||
readingBreak(
|
||||
g.book.pages.length + (index - (g.book.continueAt ?? 0) + 1) * 3,
|
||||
next,
|
||||
);
|
||||
}
|
||||
|
||||
void back() {
|
||||
@@ -395,64 +429,59 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
g.home();
|
||||
return;
|
||||
}
|
||||
switch (g.screen) {
|
||||
case Screen.story:
|
||||
if (g.storyIndex > 0) {
|
||||
turn(-1);
|
||||
} else {
|
||||
g.home();
|
||||
}
|
||||
case Screen.reveal:
|
||||
g.startCampaign(g.campaignIndex);
|
||||
case Screen.briefing:
|
||||
g.contents();
|
||||
case Screen.game:
|
||||
if (g.mode == Mode.campaign) {
|
||||
g.contents();
|
||||
} else {
|
||||
g.home();
|
||||
}
|
||||
case Screen.contents:
|
||||
g.home();
|
||||
case Screen.home:
|
||||
break;
|
||||
if (g.screen == Screen.library) return;
|
||||
if (g.screen == Screen.home) {
|
||||
// With a catalogue the shelf is the app's root; without one (widget tests
|
||||
// and embedders) the book's home stays the first and last leaf.
|
||||
if (g.library != null) g.showLibrary();
|
||||
return;
|
||||
}
|
||||
g.home();
|
||||
}
|
||||
|
||||
@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 build(BuildContext context) => PaperSkin(
|
||||
// The shelf is shared by every book, so it uses the default notebook page
|
||||
// rather than the paper of whichever book was last open.
|
||||
asset: g.screen == Screen.library ? null : g.book.paperAsset,
|
||||
child: PopScope(
|
||||
canPop:
|
||||
(g.screen == Screen.library ||
|
||||
(g.screen == Screen.home && g.library == null)) &&
|
||||
!g.busy,
|
||||
onPopInvokedWithResult: (didPop, result) {
|
||||
if (!didPop) back();
|
||||
},
|
||||
child: Scaffold(
|
||||
body: Stack(
|
||||
children: [
|
||||
switch (g.screen) {
|
||||
Screen.library => libraryScreen(),
|
||||
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),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -480,7 +509,233 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
),
|
||||
);
|
||||
Widget folio(String text) => writing(text, size: 15, color: blue);
|
||||
|
||||
/// The app's first window: every installed book on one shelf. Tapping a card
|
||||
/// selects that story and lets `Game.restore()` reopen its saved leaf.
|
||||
Widget libraryScreen() {
|
||||
final catalogue = g.library;
|
||||
if (catalogue == null) {
|
||||
return Leaf(
|
||||
key: const ValueKey('library'),
|
||||
body: column([
|
||||
folio('L U M E N / STORY LIBRARY'),
|
||||
writing('No stories are installed.', size: 24, color: muted),
|
||||
action('Back to the notebook', g.home),
|
||||
]),
|
||||
);
|
||||
}
|
||||
return Leaf(
|
||||
key: const ValueKey('library'),
|
||||
body: LayoutBuilder(
|
||||
builder: (context, c) {
|
||||
final compact = c.maxWidth < 480;
|
||||
// Wide tablets get two columns of books; phones keep one dense column.
|
||||
final width = math.min(c.maxWidth, 860.0);
|
||||
final columns = width >= 720 ? 2 : 1;
|
||||
return Center(
|
||||
child: SizedBox(
|
||||
width: width,
|
||||
child: column([
|
||||
folio('L U M E N / STORY LIBRARY'),
|
||||
writing('Choose a book', size: compact ? 34 : 40),
|
||||
writing(
|
||||
'Open a book to continue where you left off.',
|
||||
size: compact ? 19 : 23,
|
||||
color: const Color(0xff70503b),
|
||||
),
|
||||
gap(compact ? 10 : 16),
|
||||
FutureBuilder<List<Book>>(
|
||||
future: shelfBooks(catalogue),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasError) {
|
||||
return column([
|
||||
writing(
|
||||
'This story could not be opened. Please try again.',
|
||||
size: 21,
|
||||
color: muted,
|
||||
),
|
||||
action(
|
||||
'Try again',
|
||||
() => setState(() {
|
||||
_shelf = null;
|
||||
_shelfLanguage = '';
|
||||
}),
|
||||
),
|
||||
]);
|
||||
}
|
||||
final books = snapshot.data;
|
||||
if (books == null) {
|
||||
return const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 40),
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(color: blue),
|
||||
),
|
||||
);
|
||||
}
|
||||
if (books.isEmpty) {
|
||||
return writing(
|
||||
'No stories are installed.',
|
||||
size: 22,
|
||||
color: muted,
|
||||
);
|
||||
}
|
||||
final cards = [
|
||||
for (final story in books)
|
||||
bookCard(story, compact: compact),
|
||||
];
|
||||
if (columns == 1) return column(cards);
|
||||
final cardWidth = (width - 14) / 2;
|
||||
return Wrap(
|
||||
spacing: 14,
|
||||
runSpacing: 2,
|
||||
children: [
|
||||
for (final card in cards)
|
||||
SizedBox(width: cardWidth, child: card),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
gap(4),
|
||||
action('Settings', settings),
|
||||
]),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// One book on the shelf: cover, translated metadata, progress and the way
|
||||
/// back into the reader. A book with a saved leaf offers "Continue reading".
|
||||
/// Phones get a denser card so several books fit the narrow notebook page.
|
||||
Widget bookCard(Book story, {required bool compact}) {
|
||||
final catalogue = g.library;
|
||||
if (catalogue == null) return const SizedBox.shrink();
|
||||
final store = g.store.forStory(story.id);
|
||||
final restored = [
|
||||
for (var i = 0; i < story.levels.length; i++)
|
||||
store.flag('done_${story.puzzleKey(i)}'),
|
||||
].where((done) => done).length;
|
||||
final saved = store.text('flutter_screen', 'home');
|
||||
final resuming = saved != Screen.home.name && saved != Screen.library.name;
|
||||
final current = story.id == g.book.id;
|
||||
final languages = catalogue
|
||||
.definition(story.id)
|
||||
.languages
|
||||
.values
|
||||
.map((entry) => entry['label'] as String? ?? '')
|
||||
.where((label) => label.isNotEmpty)
|
||||
.toList();
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: compact ? 5 : 7),
|
||||
child: InkWell(
|
||||
key: ValueKey('library-book-${story.id}'),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
onTap: () => unawaited(openStory(story.id)),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: blue.withValues(alpha: current ? .55 : .18),
|
||||
width: current ? 1.5 : 1,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(compact ? 9 : 12),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (story.coverAsset case final asset?)
|
||||
Padding(
|
||||
padding: EdgeInsets.only(right: compact ? 10 : 14),
|
||||
child: SizedBox(
|
||||
width: compact ? 54 : 78,
|
||||
height: compact ? 74 : 104,
|
||||
child: Image.asset(
|
||||
asset,
|
||||
fit: BoxFit.contain,
|
||||
semanticLabel: story.title,
|
||||
errorBuilder: (_, _, _) => const SizedBox.shrink(),
|
||||
),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: column([
|
||||
writing(story.title, size: compact ? 23 : 29),
|
||||
if (!compact && story.description.isNotEmpty)
|
||||
writing(
|
||||
story.description,
|
||||
size: 20,
|
||||
color: const Color(0xff70503b),
|
||||
),
|
||||
if (languages.length > 1)
|
||||
writing(
|
||||
languages.join(' · '),
|
||||
size: compact ? 14 : 16,
|
||||
color: muted,
|
||||
),
|
||||
if (story.levels.isNotEmpty)
|
||||
writing(
|
||||
'$restored / ${story.levels.length} memories restored',
|
||||
size: compact ? 14 : 17,
|
||||
color: muted,
|
||||
),
|
||||
writing(
|
||||
resuming ? 'Continue reading' : 'Open this book ›',
|
||||
size: compact ? 17 : 19,
|
||||
color: blue,
|
||||
),
|
||||
]),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// Loads the whole catalogue once per requested language. A broken package is
|
||||
/// skipped so the rest of the shelf stays usable.
|
||||
Future<List<Book>> shelfBooks(StoryLibrary catalogue) {
|
||||
final language = g.requestedLanguage;
|
||||
final cached = _shelf;
|
||||
if (cached != null && _shelfLanguage == language) return cached;
|
||||
_shelfLanguage = language;
|
||||
return _shelf = () async {
|
||||
final books = <Book>[];
|
||||
for (final story in catalogue.stories) {
|
||||
try {
|
||||
books.add(await catalogue.open(story.id, language: language));
|
||||
} catch (_) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return books;
|
||||
}();
|
||||
}
|
||||
|
||||
/// Waits for the shelf before switching screens, so the home button never
|
||||
/// flashes a loading state and its tap settles in one pump.
|
||||
Future<void> openLibrary() async {
|
||||
narrator.cancelAutoplay();
|
||||
final catalogue = g.library;
|
||||
if (catalogue == null) return;
|
||||
await shelfBooks(catalogue);
|
||||
if (mounted) g.showLibrary();
|
||||
}
|
||||
|
||||
Future<void> openStory(String id) async {
|
||||
narrator.cancelAutoplay();
|
||||
try {
|
||||
await g.selectStory(id);
|
||||
} catch (_) {
|
||||
if (mounted) toast('This story could not be opened. Please try again.');
|
||||
}
|
||||
}
|
||||
|
||||
Widget home() => ColoredBox(
|
||||
key: ValueKey('home-${g.book.id}'),
|
||||
color: cream,
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
@@ -545,8 +800,8 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
g.openNotebook,
|
||||
primary: true,
|
||||
),
|
||||
action('Story library', storyLibrary),
|
||||
action('Language', chooseLanguage),
|
||||
action('Story library', () => unawaited(openLibrary())),
|
||||
action('Settings', settings),
|
||||
if (g.requestedLanguage
|
||||
.replaceAll('_', '-')
|
||||
.split('-')
|
||||
@@ -606,8 +861,6 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
() => unawaited(g.startPractice()),
|
||||
),
|
||||
action('How to play', rules),
|
||||
action('Sound & atmosphere', soundSettings),
|
||||
action('Privacy & advertising', privacy),
|
||||
action(
|
||||
'Open-source licenses',
|
||||
() => showLicensePage(
|
||||
@@ -630,62 +883,27 @@ 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),
|
||||
),
|
||||
],
|
||||
Future<void> settings() => showDialog<void>(
|
||||
context: context,
|
||||
builder: (c) => SimpleDialog(
|
||||
title: const CopyText('Settings'),
|
||||
children: [
|
||||
for (final option in <(String, VoidCallback)>[
|
||||
('Language', chooseLanguage),
|
||||
('Sound & atmosphere', soundSettings),
|
||||
('Recording speed', speed),
|
||||
('Privacy & advertising', privacy),
|
||||
])
|
||||
SimpleDialogOption(
|
||||
onPressed: () {
|
||||
Navigator.pop(c);
|
||||
option.$2();
|
||||
},
|
||||
child: CopyText(option.$1),
|
||||
),
|
||||
),
|
||||
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();
|
||||
@@ -770,20 +988,32 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
key: ValueKey('${g.book.id}-story-${p.id}'),
|
||||
onTurn: (d) => turn(d),
|
||||
body: column(body),
|
||||
fittedBody: p.type == StoryPageType.puzzle
|
||||
? fittedPuzzle(
|
||||
details: [
|
||||
areaPicker(),
|
||||
...puzzleNotes(),
|
||||
...heading,
|
||||
if (p.text.isNotEmpty) reading(p.text),
|
||||
if (p.continuation.isNotEmpty) reading(p.continuation),
|
||||
if (g.book.tracks.containsKey(p.id)) audio(),
|
||||
],
|
||||
)
|
||||
: null,
|
||||
wideBody: p.type == StoryPageType.puzzle
|
||||
? splitPuzzle(side: [...heading, areaPicker(), ...puzzleNotes()])
|
||||
? splitPuzzle(
|
||||
side: [
|
||||
...heading,
|
||||
if (p.text.isNotEmpty) reading(p.text, size: 18),
|
||||
areaPicker(),
|
||||
...puzzleNotes(),
|
||||
],
|
||||
)
|
||||
: null,
|
||||
footer: navigation(),
|
||||
);
|
||||
}
|
||||
|
||||
void bookmark() {
|
||||
unawaited(
|
||||
prefs.set('notebook_manual_bookmark', g.book.pages[g.storyIndex].id),
|
||||
);
|
||||
toast('A ribbon marks this page.');
|
||||
}
|
||||
|
||||
Widget navigation() {
|
||||
final wide = MediaQuery.orientationOf(context) == Orientation.landscape;
|
||||
final previous = InkButton(
|
||||
@@ -798,43 +1028,13 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
() => turn(1),
|
||||
size: wide ? 19 : 21,
|
||||
);
|
||||
if (wide) {
|
||||
// One row keeps the shorter landscape page free for the illustration
|
||||
// and the puzzle beside it.
|
||||
return Row(
|
||||
children: [
|
||||
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),
|
||||
Expanded(child: previous),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(child: next),
|
||||
],
|
||||
);
|
||||
}
|
||||
return column([
|
||||
Row(
|
||||
children: [
|
||||
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)),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(child: previous),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(child: next),
|
||||
],
|
||||
),
|
||||
]);
|
||||
return Row(
|
||||
children: [
|
||||
Expanded(child: previous),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(child: next),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
String get recordingId => g.screen == Screen.story
|
||||
@@ -880,7 +1080,7 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
? 'Narrator · recorded story'
|
||||
: g.book.isMara
|
||||
? 'Mara · diary reading'
|
||||
: '${g.book.tracks[recordingId]?['speaker'] ?? g.storyPage.speaker} · recorded story',
|
||||
: '${narrator.page == recordingId ? narrator.speaker : g.book.tracks[recordingId]?['speaker'] ?? g.storyPage.speaker} · recorded story',
|
||||
size: 17,
|
||||
color: muted,
|
||||
),
|
||||
@@ -1012,8 +1212,8 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
body: column([
|
||||
folio('${g.book.title.toUpperCase()} · CONTENTS'),
|
||||
writing(g.book.levels[first].chapter, size: 34),
|
||||
if (chapter == 0 && !g.book.isMara) ...[
|
||||
reading(g.book.premise),
|
||||
if (!g.book.isMara) ...[
|
||||
if (chapter == 0) reading(g.book.premise),
|
||||
action('Continue reading', g.openNotebook),
|
||||
if (ribbon != null)
|
||||
action(
|
||||
@@ -1137,11 +1337,12 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
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,
|
||||
RegionButton(
|
||||
key: ValueKey('area-$i'),
|
||||
label:
|
||||
'${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])}',
|
||||
onPressed: () => g.area(i),
|
||||
selected: i == g.selectedArea,
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -1172,21 +1373,33 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
size: 18,
|
||||
color: muted,
|
||||
),
|
||||
if (!g.won)
|
||||
Row(
|
||||
if (!g.won) InkButton('Hint · rewarded ad', hint, size: 22),
|
||||
];
|
||||
|
||||
/// The board stays in the viewport while supporting text scrolls separately.
|
||||
Widget fittedPuzzle({required List<Widget> details}) => LayoutBuilder(
|
||||
builder: (context, constraints) {
|
||||
final grid = math.min(
|
||||
math.min(constraints.maxWidth, 350.0),
|
||||
constraints.maxHeight * .70,
|
||||
);
|
||||
return Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: grid,
|
||||
child: board(maxWidth: grid),
|
||||
),
|
||||
Expanded(
|
||||
child: InkButton(
|
||||
'Undo a mark',
|
||||
g.canUndo ? g.undo : null,
|
||||
size: 22,
|
||||
child: SingleChildScrollView(
|
||||
key: const ValueKey('puzzle-details-scroll'),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4),
|
||||
child: column(details),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(child: InkButton('Hint · rewarded ad', hint, size: 22)),
|
||||
],
|
||||
),
|
||||
];
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
/// Landscape puzzle leaf: the grid keeps the left column at its full height
|
||||
/// while the heading, area clues and notes sit beside it, so nothing has to
|
||||
@@ -1284,6 +1497,15 @@ class _NotebookState extends State<Notebook> with WidgetsBindingObserver {
|
||||
if (g.won) clarity,
|
||||
for (final a in actions) action(a.label, a.run, primary: a.primary),
|
||||
]),
|
||||
fittedBody: fittedPuzzle(
|
||||
details: [
|
||||
areaPicker(),
|
||||
...puzzleNotes(),
|
||||
...heading(compact: true),
|
||||
if (g.won) clarity,
|
||||
for (final a in actions) action(a.label, a.run, primary: a.primary),
|
||||
],
|
||||
),
|
||||
// Landscape: the heading and notes sit beside the grid while the leaf's
|
||||
// actions stay in a compact bar that does not take room from the board.
|
||||
wideBody: Column(
|
||||
|
||||
@@ -4,7 +4,8 @@ import 'package:audio_session/audio_session.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:just_audio/just_audio.dart';
|
||||
|
||||
enum Soundscape { cottage, harbour, bridge, tower }
|
||||
import '../domain/soundscape.dart';
|
||||
export '../domain/soundscape.dart';
|
||||
|
||||
Soundscape soundscapeFor(int campaignIndex) => switch (campaignIndex) {
|
||||
4 || 5 || 7 => Soundscape.harbour,
|
||||
@@ -34,7 +35,7 @@ class _AudioOutput implements AmbienceOutput {
|
||||
throw StateError('Audio focus unavailable');
|
||||
}
|
||||
await _player.setLoopMode(LoopMode.one);
|
||||
await _player.setAsset('assets/audio/ambience_${scene.name}.wav');
|
||||
await _player.setAsset(scene.asset);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -61,13 +61,13 @@ class Narrator extends ChangeNotifier {
|
||||
}
|
||||
|
||||
String get speaker {
|
||||
var current = tracks[page]?['speaker'] as String? ?? '';
|
||||
for (final cue in tracks[page]?['cues'] ?? []) {
|
||||
if (position.inMilliseconds >= cue['startMs'] &&
|
||||
position.inMilliseconds < cue['endMs']) {
|
||||
return cue['speaker'] ?? tracks[page]?['speaker'] ?? '';
|
||||
}
|
||||
if (position.inMilliseconds < cue['startMs']) break;
|
||||
current = cue['speaker'] as String? ?? current;
|
||||
}
|
||||
return tracks[page]?['speaker'] ?? '';
|
||||
// Hold the role through its pause, instead of flashing back to Narrator.
|
||||
return current;
|
||||
}
|
||||
|
||||
void scheduleAutoplay(String? id, double speed) {
|
||||
|
||||
+177
-105
@@ -6,6 +6,42 @@ import '../domain/puzzle.dart';
|
||||
import 'paper.dart';
|
||||
import 'translation.dart';
|
||||
|
||||
const regionInk = Color(0xff84421f);
|
||||
|
||||
class RegionButton extends StatelessWidget {
|
||||
const RegionButton({
|
||||
super.key,
|
||||
required this.label,
|
||||
required this.onPressed,
|
||||
required this.selected,
|
||||
});
|
||||
final String label;
|
||||
final VoidCallback onPressed;
|
||||
final bool selected;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => PageSwipeBlocker(
|
||||
child: Semantics(
|
||||
selected: selected,
|
||||
child: TextButton(
|
||||
onPressed: onPressed,
|
||||
style: TextButton.styleFrom(
|
||||
foregroundColor: selected ? cream : regionInk,
|
||||
backgroundColor: selected ? regionInk : cream.withValues(alpha: .5),
|
||||
textStyle: hand(21).copyWith(
|
||||
fontWeight: selected ? FontWeight.bold : FontWeight.normal,
|
||||
),
|
||||
minimumSize: const Size(48, 48),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8),
|
||||
side: BorderSide(color: regionInk, width: selected ? 2.4 : 1),
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(6)),
|
||||
),
|
||||
child: CopyText(label),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
class Board extends StatelessWidget {
|
||||
const Board({
|
||||
super.key,
|
||||
@@ -57,120 +93,156 @@ class Board extends StatelessWidget {
|
||||
indices.where((i) => cells[i] == 1).length == total;
|
||||
return Align(
|
||||
alignment: Alignment.center,
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(width: u, height: u),
|
||||
for (var col = 0; col < n; col++)
|
||||
clue(
|
||||
'${puzzle.cols[col]}',
|
||||
complete(
|
||||
List.generate(n, (i) => i * n + col),
|
||||
puzzle.cols[col],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
for (var row = 0; row < n; row++)
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
child: SizedBox(
|
||||
width: (n + 1) * u,
|
||||
height: (n + 1) * u,
|
||||
child: Stack(
|
||||
children: [
|
||||
Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
clue(
|
||||
'${puzzle.rows[row]}',
|
||||
complete(
|
||||
List.generate(n, (i) => row * n + i),
|
||||
puzzle.rows[row],
|
||||
),
|
||||
),
|
||||
for (var col = 0; col < n; col++)
|
||||
Builder(
|
||||
builder: (context) {
|
||||
final i = row * n + col,
|
||||
value = cells[i],
|
||||
fixed = puzzle.given[i],
|
||||
inside = r?.contains(i, n) ?? false;
|
||||
final state = value == 0
|
||||
? 'empty'
|
||||
: value == 1
|
||||
? 'lit'
|
||||
: 'crossed out';
|
||||
return Semantics(
|
||||
label: CopyScope.text(
|
||||
context,
|
||||
'Row ${row + 1}, column ${col + 1}, $state${fixed ? ', fixed clue' : ''}',
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(width: u, height: u),
|
||||
for (var col = 0; col < n; col++)
|
||||
clue(
|
||||
'${puzzle.cols[col]}',
|
||||
complete(
|
||||
List.generate(n, (i) => i * n + col),
|
||||
puzzle.cols[col],
|
||||
),
|
||||
button: !fixed && !won,
|
||||
enabled: !fixed && !won,
|
||||
onTap: fixed || won
|
||||
? null
|
||||
: () => onMark(i),
|
||||
excludeSemantics: true,
|
||||
child: GestureDetector(
|
||||
key: ValueKey('cell-$i'),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: fixed || won
|
||||
? null
|
||||
: () => onMark(i),
|
||||
child: SizedBox(
|
||||
width: u,
|
||||
height: u,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(2),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: inside
|
||||
? amber.withValues(alpha: .22)
|
||||
: Colors.transparent,
|
||||
borderRadius:
|
||||
BorderRadius.circular(2),
|
||||
border: Border.all(
|
||||
color: inside
|
||||
? const Color(0xffaa5b2a)
|
||||
: muted.withValues(
|
||||
alpha: .48,
|
||||
),
|
||||
width: inside ? 1.4 : .65,
|
||||
),
|
||||
],
|
||||
),
|
||||
for (var row = 0; row < n; row++)
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
clue(
|
||||
'${puzzle.rows[row]}',
|
||||
complete(
|
||||
List.generate(n, (i) => row * n + i),
|
||||
puzzle.rows[row],
|
||||
),
|
||||
),
|
||||
for (var col = 0; col < n; col++)
|
||||
Builder(
|
||||
builder: (context) {
|
||||
final i = row * n + col,
|
||||
value = cells[i],
|
||||
fixed = puzzle.given[i],
|
||||
inside = r?.contains(i, n) ?? false;
|
||||
final state = value == 0
|
||||
? 'empty'
|
||||
: value == 1
|
||||
? 'lit'
|
||||
: 'crossed out';
|
||||
return Semantics(
|
||||
selected: inside,
|
||||
label: CopyScope.text(
|
||||
context,
|
||||
'Row ${row + 1}, column ${col + 1}, $state${fixed ? ', fixed clue' : ''}',
|
||||
),
|
||||
button: !fixed && !won,
|
||||
enabled: !fixed && !won,
|
||||
onTap: fixed || won
|
||||
? null
|
||||
: () => onMark(i),
|
||||
excludeSemantics: true,
|
||||
child: GestureDetector(
|
||||
key: ValueKey('cell-$i'),
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: fixed || won
|
||||
? null
|
||||
: () => onMark(i),
|
||||
child: SizedBox(
|
||||
width: u,
|
||||
height: u,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(
|
||||
2,
|
||||
),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: inside
|
||||
? amber.withValues(
|
||||
alpha: .38,
|
||||
)
|
||||
: Colors.transparent,
|
||||
borderRadius:
|
||||
BorderRadius.circular(
|
||||
2,
|
||||
),
|
||||
border: Border.all(
|
||||
color: inside
|
||||
? regionInk
|
||||
: muted.withValues(
|
||||
alpha: .48,
|
||||
),
|
||||
width: inside ? 1.4 : .65,
|
||||
),
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
if (value != 0)
|
||||
Positioned.fill(
|
||||
child: CustomPaint(
|
||||
painter: PencilMark(
|
||||
value: value,
|
||||
variation: i,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (fixed)
|
||||
Positioned(
|
||||
right: 3,
|
||||
bottom: 3,
|
||||
child: Container(
|
||||
width: 4,
|
||||
height: 4,
|
||||
decoration:
|
||||
BoxDecoration(
|
||||
color: muted,
|
||||
shape: BoxShape
|
||||
.circle,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
if (value != 0)
|
||||
Positioned.fill(
|
||||
child: CustomPaint(
|
||||
painter: PencilMark(
|
||||
value: value,
|
||||
variation: i,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (fixed)
|
||||
Positioned(
|
||||
right: 3,
|
||||
bottom: 3,
|
||||
child: Container(
|
||||
width: 4,
|
||||
height: 4,
|
||||
decoration: BoxDecoration(
|
||||
color: muted,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
if (r != null)
|
||||
Positioned(
|
||||
left: u * (1 + r.left),
|
||||
top: u * (1 + r.top),
|
||||
width: u * r.width,
|
||||
height: u * r.height,
|
||||
child: IgnorePointer(
|
||||
child: DecoratedBox(
|
||||
key: const ValueKey('selected-region-outline'),
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(
|
||||
color: regionInk,
|
||||
width: 3.2,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(3),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -11,6 +11,7 @@ extension _MaraStory on _NotebookState {
|
||||
];
|
||||
final body = <Widget>[...heading];
|
||||
Widget? wideBody;
|
||||
Widget? fittedBody;
|
||||
switch (p.type) {
|
||||
case StoryPageType.dedication:
|
||||
body.addAll([
|
||||
@@ -44,6 +45,9 @@ extension _MaraStory on _NotebookState {
|
||||
color: muted,
|
||||
);
|
||||
body.addAll([intro, puzzleBody()]);
|
||||
fittedBody = fittedPuzzle(
|
||||
details: [areaPicker(), ...puzzleNotes(), ...heading, intro],
|
||||
);
|
||||
wideBody = splitPuzzle(
|
||||
side: [...heading, intro, areaPicker(), ...puzzleNotes()],
|
||||
);
|
||||
@@ -139,6 +143,7 @@ extension _MaraStory on _NotebookState {
|
||||
key: ValueKey('story-${g.storyIndex}'),
|
||||
onTurn: (d) => turn(d),
|
||||
body: column(body),
|
||||
fittedBody: fittedBody,
|
||||
wideBody: wideBody,
|
||||
footer: navigation(),
|
||||
);
|
||||
|
||||
+29
-9
@@ -66,12 +66,26 @@ class Paper extends StatefulWidget {
|
||||
State<Paper> createState() => _PaperState();
|
||||
}
|
||||
|
||||
/// Artwork follows the selected story on reading, contents and puzzle pages.
|
||||
class PaperSkin extends InheritedWidget {
|
||||
const PaperSkin({super.key, required this.asset, required super.child});
|
||||
final String? asset;
|
||||
|
||||
static String? assetOf(BuildContext context) =>
|
||||
context.dependOnInheritedWidgetOfExactType<PaperSkin>()?.asset;
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(PaperSkin oldWidget) => asset != oldWidget.asset;
|
||||
}
|
||||
|
||||
class _PaperState extends State<Paper> {
|
||||
Offset _drag = Offset.zero;
|
||||
Offset _origin = Offset.zero;
|
||||
@override
|
||||
Widget build(BuildContext context) => ColoredBox(
|
||||
color: const Color(0xff314345),
|
||||
color: PaperSkin.assetOf(context) == null
|
||||
? const Color(0xff314345)
|
||||
: const Color(0xff241e27),
|
||||
child: SafeArea(
|
||||
child: LayoutBuilder(
|
||||
builder: (context, c) {
|
||||
@@ -139,7 +153,8 @@ class _PaperState extends State<Paper> {
|
||||
width: w,
|
||||
height: h,
|
||||
child: Image.asset(
|
||||
'assets/artwork/mara-single-page-v2.png',
|
||||
PaperSkin.assetOf(context) ??
|
||||
'assets/artwork/mara-single-page-v2.png',
|
||||
fit: BoxFit.fill,
|
||||
excludeFromSemantics: true,
|
||||
),
|
||||
@@ -175,11 +190,15 @@ class Leaf extends StatelessWidget {
|
||||
super.key,
|
||||
required this.body,
|
||||
this.wideBody,
|
||||
this.fittedBody,
|
||||
this.footer,
|
||||
this.onTurn,
|
||||
});
|
||||
final Widget body;
|
||||
|
||||
/// A bounded portrait layout, used to keep the complete puzzle in view.
|
||||
final Widget? fittedBody;
|
||||
|
||||
/// Replaces [body] on a landscape page. The shorter page suits side-by-side
|
||||
/// columns better than one long scroll, so it should arrange its own panes.
|
||||
final Widget? wideBody;
|
||||
@@ -197,13 +216,14 @@ class Leaf extends StatelessWidget {
|
||||
Expanded(
|
||||
child: wide
|
||||
? wideBody!
|
||||
: SingleChildScrollView(
|
||||
// Each newly opened leaf starts at the top, including
|
||||
// leaves revisited with Previous or a bookmark.
|
||||
key: const ValueKey('leaf-scroll'),
|
||||
padding: const EdgeInsets.fromLTRB(4, 8, 4, 8),
|
||||
child: body,
|
||||
),
|
||||
: fittedBody ??
|
||||
SingleChildScrollView(
|
||||
// Each newly opened leaf starts at the top, including
|
||||
// leaves revisited with Previous or a bookmark.
|
||||
key: const ValueKey('leaf-scroll'),
|
||||
padding: const EdgeInsets.fromLTRB(4, 8, 4, 8),
|
||||
child: body,
|
||||
),
|
||||
),
|
||||
?footer,
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user