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:
Hadrian Burkhardt
2026-11-05 14:29:50 +01:00
parent d45cd0698a
commit 0718e3f252
149 changed files with 16875 additions and 393 deletions
+7 -3
View File
@@ -72,8 +72,12 @@ void main() {
await tester.tap(target);
await tester.pumpAndSettle();
final marks = List<int>.of(game.cells);
await tap('Bookmark');
final savedId = game.progress.text('notebook_manual_bookmark');
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(game.screen, Screen.home);
game.openNotebook();
await tester.pumpAndSettle();
final savedId = game.progress.text('notebook_last_page');
expect(savedId, page.id);
final restored = Game(book, Progress.memory(game.progress.snapshot));
await restored.restore();
@@ -127,7 +131,7 @@ void main() {
final lastCell = tester.getRect(find.byKey(const ValueKey('cell-48')));
expect(
lastCell.bottom,
lessThan(tester.getTopLeft(find.text('Contents')).dy),
lessThan(tester.getTopLeft(find.text('Next leaf →')).dy),
);
await binding.takeScreenshot('cottage-compass-landscape');
for (var i = 0; i < 4; i++) {
+7
View File
@@ -0,0 +1,7 @@
import 'halloween_test.dart' as story;
import 'drama_test.dart' as audio;
void main() {
story.main();
audio.main();
}
+120
View File
@@ -0,0 +1,120 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:lumen/domain/game.dart';
import 'package:lumen/domain/library.dart';
import 'package:lumen/main.dart';
import 'package:lumen/services/ambience.dart';
import 'package:lumen/services/narrator.dart';
import 'package:lumen/services/progress.dart';
void main() {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets(
'two drama scenes play with atmosphere and live character labels',
(tester) async {
expect(const bool.fromEnvironment('QA_TEST'), true);
final library = await StoryLibrary.load();
final book = await library.open('midnight-invitation');
final game = Game(
book,
Progress.memory({'story_access_level': 11, 'language': 'en'}),
library: library,
);
final voice = Narrator(book.tracks);
final ambience = Ambience();
game.showStory(
book.pages.indexWhere((p) => p.id == 'midnight.feather.memory'),
);
await tester.pumpWidget(
MaterialApp(
debugShowCheckedModeBanner: false,
home: Notebook(
game: game,
adsEnabled: false,
narrator: voice,
ambience: ambience,
),
),
);
await tester.pumpAndSettle();
await voice.stop();
await ambience.settled;
expect(ambience.error, isEmpty);
await binding.convertFlutterSurfaceToImage();
Future<void> tap(String label) async {
await tester.ensureVisible(find.text(label));
await tester.pumpAndSettle();
await tester.tap(find.text(label));
await tester.pumpAndSettle();
}
Future<void> reach(int ms) async {
final deadline = DateTime.now().add(const Duration(seconds: 65));
while (voice.position.inMilliseconds < ms &&
DateTime.now().isBefore(deadline)) {
await Future<void>.delayed(const Duration(milliseconds: 180));
await tester.pump();
expect(voice.error, isEmpty);
}
expect(voice.position.inMilliseconds, greaterThanOrEqualTo(ms));
}
await tap('Play this reading');
debugPrint('DRAMA_MIX_READY: threshold atmosphere and cast reading');
final doorCues = book.tracks['midnight.feather.memory']['cues'] as List;
final firstIris =
doorCues.firstWhere((c) => c['speaker'] == 'Iris')['startMs'] as int;
for (final role in ['Iris', 'Elias']) {
final cue = (book.tracks['midnight.feather.memory']['cues'] as List)
.firstWhere(
(c) =>
c['speaker'] == role &&
c['startMs'] > (role == 'Elias' ? firstIris : 0),
);
await reach(cue['startMs'] + 150);
expect(voice.speaker, role);
expect(find.text('$role · recorded story'), findsOneWidget);
expect(ambience.error, isEmpty);
}
await tap('Pause recording');
final paused = voice.position;
await Future<void>.delayed(const Duration(milliseconds: 700));
expect((voice.position - paused).inMilliseconds.abs(), lessThan(150));
await tap('Resume recording');
await reach(paused.inMilliseconds + 500);
await binding.takeScreenshot('drama-threshold-playing');
game.showStory(
book.pages.indexWhere((p) => p.id == 'midnight.candle.entry'),
);
await tester.pumpAndSettle();
await voice.stop();
await ambience.settled;
expect(ambience.error, isEmpty);
expect(voice.page, isEmpty);
await tap('Play this reading');
final iris = (book.tracks['midnight.candle.entry']['cues'] as List)
.firstWhere((c) => c['speaker'] == 'Iris');
await reach(iris['startMs'] + 150);
expect(find.text('Iris · recorded story'), findsOneWidget);
await tap('Pause recording');
await tap('Sound & atmosphere');
await tester.tap(find.byType(SwitchListTile));
await tester.pumpAndSettle();
await ambience.settled;
expect(game.progress.flag('ambience_enabled'), false);
await tap('Keep going');
await binding.takeScreenshot('drama-kitchen-paused');
game.home();
await tester.pumpAndSettle();
await ambience.settled;
expect(voice.page, isEmpty);
expect(ambience.error, isEmpty);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox());
await tester.pumpAndSettle();
},
);
}
+175
View File
@@ -0,0 +1,175 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:lumen/domain/book.dart';
import 'package:lumen/domain/game.dart';
import 'package:lumen/domain/library.dart';
import 'package:lumen/main.dart';
import 'package:lumen/services/narrator.dart';
import 'package:lumen/services/progress.dart';
void main() {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets(
'complete Halloween story, twelve discoveries and all native recordings',
(tester) async {
expect(const bool.fromEnvironment('QA_TEST'), true);
Future<void> orient(DeviceOrientation orientation) async {
await SystemChrome.setPreferredOrientations([orientation]);
final portrait = orientation == DeviceOrientation.portraitUp;
for (var i = 0; i < 30; i++) {
await tester.pump(const Duration(milliseconds: 100));
final size = tester.view.physicalSize;
if ((size.height > size.width) == portrait) {
await tester.pumpAndSettle();
return;
}
}
fail('Device did not enter $orientation');
}
await orient(DeviceOrientation.portraitUp);
final library = await StoryLibrary.load();
final mara = await library.open('mara-island');
final store = Progress.memory({'language': 'en'});
final g = Game(mara, store, library: library);
final voice = Narrator(mara.tracks);
await tester.pumpWidget(
MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(fontFamily: 'MaraHand'),
home: Notebook(game: g, adsEnabled: false, narrator: voice),
),
);
await tester.pumpAndSettle();
await binding.convertFlutterSurfaceToImage();
Future<void> tap(String text) async {
final f = find.text(text);
await tester.ensureVisible(f);
await tester.pumpAndSettle();
await tester.tap(f);
await tester.pumpAndSettle();
}
Future<void> shot(String name) async {
await tester.pumpAndSettle();
await binding.takeScreenshot(name);
}
await tap('Story library');
await tap('The Midnight Invitation');
expect(g.book.id, 'midnight-invitation');
await shot('halloween-00-cover');
await tap('Open The Midnight Invitation · 0 / 12');
expect(g.storyPage.id, 'midnight.opening');
await voice.stop();
await tester.pumpAndSettle();
await shot('halloween-01-opening');
// The actual on-page controls must play, pause and resume a native WAV.
await tester.ensureVisible(find.text('Play this reading'));
await tester.tap(find.text('Play this reading'));
await Future<void>.delayed(const Duration(seconds: 2));
await tester.pumpAndSettle();
expect(voice.error, isEmpty);
expect(voice.playing, true);
await tester.ensureVisible(find.text('Pause recording'));
await tester.tap(find.text('Pause recording'));
await tester.pumpAndSettle();
final paused = voice.position;
expect(paused.inMilliseconds, greaterThan(500));
await tester.tap(find.text('Resume recording'));
await Future<void>.delayed(const Duration(seconds: 1));
await voice.pause();
expect(voice.position, greaterThan(paused));
await voice.stop();
// Decode every new bundled recording on the tablet, not just its metadata.
for (final id in g.book.tracks.keys) {
await voice.toggle(id, 1);
await Future<void>.delayed(const Duration(milliseconds: 350));
await voice.pause();
expect(voice.error, isEmpty, reason: id);
expect(voice.position.inMilliseconds, greaterThan(100), reason: id);
await voice.stop();
}
final book = g.book;
for (var index = 0; index < book.levels.length; index++) {
g.showStory(book.pageFor(index, StoryPageType.entry));
await tester.pumpAndSettle();
await tap('Next leaf →');
expect(g.storyPage.type, StoryPageType.puzzle);
final p = g.puzzle!;
expect(find.text('Undo a mark'), findsNothing);
expect(find.image(AssetImage(book.paperAsset!)), findsOneWidget);
if (index == 2) {
await tester.ensureVisible(find.byKey(const ValueKey('area-1')));
await tester.tap(find.byKey(const ValueKey('area-1')));
await tester.pumpAndSettle();
expect(g.selectedArea, 1);
await shot('halloween-region-selected-landscape');
await orient(DeviceOrientation.portraitUp);
await tester.ensureVisible(
find.byKey(const ValueKey('selected-region-outline')),
);
await shot('halloween-region-selected-portrait');
await orient(DeviceOrientation.landscapeLeft);
}
if (index == 0) {
final cell = p.given.indexOf(false);
await tester.ensureVisible(find.byKey(ValueKey('cell-$cell')));
await tester.tap(find.byKey(ValueKey('cell-$cell')));
await tester.pumpAndSettle();
final marks = List<int>.of(g.cells);
await tap('Next leaf →');
await tap('Read ahead');
expect(g.recoveredCount, 0);
expect(
find.image(AssetImage(book.levels[0].illustrationAsset!)),
findsNothing,
);
await tap('← Previous leaf');
expect(g.cells, marks);
await orient(DeviceOrientation.landscapeLeft);
await shot('halloween-02-puzzle-landscape');
}
for (var c = 0; c < g.cells.length; c++) {
while (g.cells[c] != (p.solution[c] == 1 ? 1 : 2)) {
g.mark(c);
}
}
await tester.pumpAndSettle();
expect(g.storyPage.type, StoryPageType.memory);
expect(g.recoveredCount, index + 1);
expect(g.solved, index + 1);
expect(
find.image(AssetImage(book.levels[index].illustrationAsset!)),
findsOneWidget,
);
if ([0, 5, 8, 11].contains(index)) {
await shot('halloween-discovery-$index');
}
expect(tester.takeException(), isNull);
}
await tap('Next leaf →');
expect(g.storyPage.id, 'midnight.ending');
await shot('halloween-03-ending');
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(g.screen, Screen.home);
g.openNotebook();
await tester.pumpAndSettle();
final restarted = Game(book, Progress.memory(store.snapshot));
await restarted.restore();
expect(restarted.storyPage.id, 'midnight.ending');
expect(restarted.recoveredCount, 12);
expect(restarted.progress.text('notebook_last_page'), 'midnight.ending');
await tap('Back to contents');
expect(g.screen, Screen.contents);
await shot('halloween-04-completed-contents');
expect(g.recoveredCount, 12);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox());
await SystemChrome.setPreferredOrientations([]);
},
);
}
+19 -5
View File
@@ -18,18 +18,28 @@ void main() {
await library.open('mara-island'),
Progress.memory({'language': 'en'}),
library: library,
);
)..showLibrary();
await tester.pumpWidget(LumenApp(game: g, adsEnabled: false));
await tester.pumpAndSettle();
await binding.convertFlutterSurfaceToImage();
Future<void> tap(String text) async {
// The shelf loads every installed book asynchronously.
Future<void> waitFor(String text) async {
for (var i = 0; i < 100 && find.text(text).evaluate().isEmpty; i++) {
await tester.pump(const Duration(milliseconds: 100));
}
await tester.ensureVisible(find.text(text));
await tester.pumpAndSettle();
}
Future<void> tap(String text) async {
await waitFor(text);
await tester.tap(find.text(text));
await tester.pumpAndSettle();
}
await tap('Story library');
expect(g.screen, Screen.library);
await waitFor('The paper boat');
await binding.takeScreenshot('library-shelf');
await tap('The paper boat');
expect(g.book.id, 'paper-boat');
await tap('Open The paper boat · 0 / 1');
@@ -38,13 +48,17 @@ void main() {
await tester.tap(find.byKey(const ValueKey('cell-0')));
await tester.pumpAndSettle();
final marks = List<int>.of(g.cells);
await tap('Bookmark');
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(g.screen, Screen.home);
await tap('Settings');
await tap('Language');
await tap('Deutsch');
expect(g.book.language, 'de');
g.openNotebook();
await tester.pumpAndSettle();
expect(g.cells, marks);
expect(g.canUndo, true);
expect(g.progress.text('notebook_manual_bookmark'), 'boat.puzzle');
expect(find.text('Eine kleine Überfahrt'), findsOneWidget);
await binding.takeScreenshot('library-german-puzzle');
await tap('Nächste Seite →');
+12 -5
View File
@@ -57,7 +57,7 @@ void main() {
tester
.getBottomRight(find.text('A recorded reading, kept with this page'))
.dy,
lessThan(tester.getTopLeft(find.text('Contents')).dy),
lessThan(tester.getTopLeft(find.text('Next leaf →')).dy),
);
await shot('02-cottage');
// Actual native WAV playback, all five files. Position must survive pause/resume.
@@ -82,7 +82,7 @@ void main() {
expect(g.storyIndex, 2);
expect(
tester.getBottomRight(find.text('Hint · rewarded ad')).dy,
lessThan(tester.getTopLeft(find.text('Contents')).dy),
lessThan(tester.getTopLeft(find.text('Next leaf →')).dy),
);
await shot('03-puzzle');
final before = List.of(g.cells);
@@ -115,7 +115,12 @@ void main() {
await tap('Unfold Gran’s note');
expect(store.flag('notebook_note_open'), true);
await shot('05-open-note');
await tap('Bookmark');
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(g.screen, Screen.home);
g.openNotebook();
await tester.pumpAndSettle();
expect(g.storyIndex, 4);
await tap('Next leaf →');
await shot('06-lantern');
expect(
@@ -125,8 +130,10 @@ void main() {
findsNothing,
);
expect(store.flag('notebook_handle_seen'), false);
await tap('Contents');
await tap('Return to my ribbon bookmark');
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
g.showStory(4);
await tester.pumpAndSettle();
expect(g.storyIndex, 4);
final restarted = Game(book, Progress.memory(store.snapshot));
await restarted.restore();
+126
View File
@@ -0,0 +1,126 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:lumen/domain/book.dart';
import 'package:lumen/domain/game.dart';
import 'package:lumen/domain/library.dart';
import 'package:lumen/main.dart';
import 'package:lumen/services/progress.dart';
import 'halloween_test.dart' as halloween;
import 'library_test.dart' as library_flow;
import 'region_test.dart' as regions;
void main() {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets('phone reading and puzzle controls fit default and larger text', (
tester,
) async {
expect(const bool.fromEnvironment('QA_TEST'), true);
final library = await StoryLibrary.load();
final book = await library.open('midnight-invitation');
final game = Game(
book,
Progress.memory({'language': 'en', 'ambience_enabled': false}),
library: library,
);
var scale = 1.0;
Widget app() => MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(fontFamily: 'MaraHand'),
builder: (context, child) => MediaQuery(
data: MediaQuery.of(context)
.copyWith(textScaler: TextScaler.linear(scale)),
child: child!,
),
home: Notebook(game: game, adsEnabled: false),
);
await tester.pumpWidget(app());
await tester.pumpAndSettle();
await binding.convertFlutterSurfaceToImage();
Future<void> orient(DeviceOrientation orientation) async {
await SystemChrome.setPreferredOrientations([orientation]);
for (var i = 0; i < 40; i++) {
await tester.pump(const Duration(milliseconds: 100));
final size = tester.view.physicalSize;
if ((size.height > size.width) ==
(orientation == DeviceOrientation.portraitUp)) {
await tester.pumpAndSettle();
return;
}
}
fail('Phone did not rotate to $orientation');
}
for (final textScale in [1.0, 1.3]) {
scale = textScale;
await tester.pumpWidget(app());
for (final orientation in [
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeLeft,
]) {
await orient(orientation);
final layout = orientation == DeviceOrientation.portraitUp
? 'portrait'
: 'landscape';
final tag = 'phone-$layout-${(scale * 100).round()}';
game.home();
await tester.pumpAndSettle();
expect(find.text(book.title), findsOneWidget);
await binding.takeScreenshot('$tag-home');
for (final pageId in [
'midnight.opening',
'midnight.key.puzzle',
'midnight.candle.entry',
'midnight.mirror.puzzle',
'midnight.ending',
]) {
game.showStory(book.pages.indexWhere((p) => p.id == pageId));
await tester.pumpAndSettle();
final next = pageId == 'midnight.ending'
? 'Back to contents'
: 'Next leaf →';
expect(
find.text(next).hitTestable(),
findsOneWidget,
reason: '$tag $pageId',
);
expect(find.text('Contents'), findsNothing, reason: '$tag $pageId');
if (game.storyPage.type == StoryPageType.puzzle) {
for (final index in [0, game.cells.length - 1]) {
final cell = find.byKey(ValueKey('cell-$index'));
expect(
cell.hitTestable(),
findsOneWidget,
reason: '$tag $pageId',
);
expect(
tester.getRect(cell).bottom,
lessThan(tester.getRect(find.text(next)).top),
reason: '$tag $pageId',
);
}
final hint = find.text('Hint · rewarded ad');
await tester.ensureVisible(hint);
await tester.pumpAndSettle();
expect(hint.hitTestable(), findsOneWidget, reason: '$tag $pageId');
final cell = find.byKey(const ValueKey('cell-0'));
debugPrint('PHONE_GRID $tag $pageId cell=${tester.getSize(cell)}');
await tester.ensureVisible(find.byKey(const ValueKey('area-1')));
await tester.tap(find.byKey(const ValueKey('area-1')));
await tester.pumpAndSettle();
expect(game.selectedArea, 1);
}
await binding.takeScreenshot('$tag-${pageId.replaceAll('.', '-')}');
expect(tester.takeException(), isNull, reason: '$tag $pageId');
}
}
}
await tester.pumpWidget(const SizedBox());
await SystemChrome.setPreferredOrientations([]);
});
halloween.main();
regions.main();
library_flow.main();
}
+72
View File
@@ -0,0 +1,72 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:lumen/domain/book.dart';
import 'package:lumen/domain/game.dart';
import 'package:lumen/domain/library.dart';
import 'package:lumen/main.dart';
import 'package:lumen/services/progress.dart';
void main() {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets(
'selected region keeps pencil marks visible in both orientations',
(tester) async {
expect(const bool.fromEnvironment('QA_TEST'), true);
final library = await StoryLibrary.load();
final book = await library.open('midnight-invitation');
final game = Game(book, Progress.memory(), library: library);
game.showStory(book.pageFor(2, StoryPageType.puzzle));
await tester.pumpWidget(LumenApp(game: game, adsEnabled: false));
await tester.pumpAndSettle();
await binding.convertFlutterSurfaceToImage();
for (final orientation in [
DeviceOrientation.portraitUp,
DeviceOrientation.landscapeLeft,
]) {
await SystemChrome.setPreferredOrientations([orientation]);
final portrait = orientation == DeviceOrientation.portraitUp;
for (var i = 0; i < 30; i++) {
await tester.pump(const Duration(milliseconds: 100));
if ((tester.view.physicalSize.height >
tester.view.physicalSize.width) ==
portrait) {
break;
}
}
await tester.pumpAndSettle();
await tester.ensureVisible(find.byKey(const ValueKey('area-1')));
await tester.tap(find.byKey(const ValueKey('area-1')));
await tester.pumpAndSettle();
final p = game.puzzle!;
final region = p.regions[1];
final targets = List.generate(p.size * p.size, (i) => i)
.where((i) => region.contains(i, p.size) && !p.given[i])
.take(2)
.toList();
for (var i = 0; i < targets.length; i++) {
final cell = targets[i];
final finder = find.byKey(ValueKey('cell-$cell'));
await tester.ensureVisible(finder);
while (game.cells[cell] != i + 1) {
await tester.tap(finder);
await tester.pumpAndSettle();
}
}
expect(find.text('Undo a mark'), findsNothing);
expect(find.image(AssetImage(book.paperAsset!)), findsOneWidget);
await tester.ensureVisible(
find.byKey(const ValueKey('selected-region-outline')),
);
await tester.pumpAndSettle();
await binding.takeScreenshot(
'halloween-region-selected-${portrait ? 'portrait' : 'landscape'}',
);
expect(tester.takeException(), isNull);
}
await tester.pumpWidget(const SizedBox());
await SystemChrome.setPreferredOrientations([]);
},
);
}