Expand Lumen stories and add island postcards

This commit is contained in:
Hadrian Burkhardt
2026-11-13 10:18:42 +01:00
parent 7e6b203a02
commit abaab927d9
211 changed files with 10839 additions and 7278 deletions
+196
View File
@@ -0,0 +1,196 @@
import 'dart:io';
import 'dart:ui' as ui;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_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/ads.dart';
import 'package:lumen/services/progress.dart';
import 'postcards_test.dart' show solve;
class NoFillAds extends Ads {
NoFillAds() : super(enabled: false);
int opportunities = 0;
@override
Future<void> between(VoidCallback next) async {
opportunities++;
next();
}
}
Future<void> capture(WidgetTester tester, String name) async {
if (!const bool.fromEnvironment('CAPTURE_POSTCARDS')) return;
final boundary = tester.renderObject<RenderRepaintBoundary>(
find.byKey(const ValueKey('capture')),
);
await tester.runAsync(() async {
final image = await boundary.toImage();
final bytes = await image.toByteData(format: ui.ImageByteFormat.png);
final dir = Directory('artifacts/postcard-review')
..createSync(recursive: true);
File('${dir.path}/$name.png').writeAsBytesSync(bytes!.buffer.asUint8List());
image.dispose();
});
}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
setUpAll(() async {
for (final family in ['sans-serif', 'serif', 'Roboto']) {
await (FontLoader(
family,
)..addFont(rootBundle.load('assets/fonts/NotoSans-Regular.ttf'))).load();
}
await (FontLoader(
'MaraHand',
)..addFont(rootBundle.load('assets/fonts/DancingScript.ttf'))).load();
});
testWidgets(
'three patterns collect a readable postcard before a single no-fill break',
(tester) async {
tester.view.physicalSize = const Size(600, 960);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final book = (await tester.runAsync(Book.load))!;
final g = Game(book, Progress.memory())..showPostcards();
final ads = NoFillAds();
await tester.pumpWidget(
RepaintBoundary(
key: const ValueKey('capture'),
child: MaterialApp(
theme: ThemeData(
fontFamily: 'MaraHand',
colorScheme: ColorScheme.fromSeed(
seedColor: const Color(0xff355751),
surface: const Color(0xfff6f1e7),
),
),
home: Notebook(game: g, adsEnabled: false, ads: ads),
),
),
);
await tester.pumpAndSettle();
await capture(tester, 'collection');
await tester.tap(find.byKey(const ValueKey('start-postcard-0')));
await tester.pumpAndSettle();
expect(g.postcardSlot, 0);
await capture(tester, 'puzzle');
for (var slot = 0; slot < 3; slot++) {
solve(g);
await tester.pumpAndSettle();
final next = find.text(
slot == 2 ? 'Read your postcard' : 'Next pattern →',
);
await tester.ensureVisible(next);
await tester.tap(next);
await tester.pumpAndSettle();
expect(ads.opportunities, 0);
}
expect(find.text('Keep this postcard'), findsOneWidget);
await capture(tester, 'collected');
await tester.tap(find.text('Keep this postcard'));
await tester.pumpAndSettle();
expect(g.screen, Screen.postcards);
expect(g.postcardsCollected, 1);
expect(ads.opportunities, 1);
await tester.ensureVisible(find.byKey(const ValueKey('read-postcard-0')));
await tester.tap(find.byKey(const ValueKey('read-postcard-0')));
await tester.pumpAndSettle();
await tester.tap(find.text('Keep this postcard'));
await tester.pumpAndSettle();
expect(ads.opportunities, 1);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox());
},
);
testWidgets(
'postcard collection, puzzle and letter fit large text on small and wide screens',
(tester) async {
addTearDown(tester.view.reset);
tester.platformDispatcher.textScaleFactorTestValue = 1.5;
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
final book = (await tester.runAsync(Book.load))!;
for (final size in [const Size(360, 640), const Size(960, 600)]) {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
final g = Game(book, Progress.memory())..showPostcards();
await tester.pumpWidget(LumenApp(game: g, adsEnabled: false));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
g.startPostcard(0);
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
for (var i = 0; i < 25; i++) {
final bounds = tester.getRect(find.byKey(ValueKey('cell-$i')));
expect(bounds.top, greaterThanOrEqualTo(0));
expect(bounds.bottom, lessThanOrEqualTo(size.height));
}
for (var slot = 0; slot < 3; slot++) {
g.startPostcard(0, slot);
solve(g);
}
await tester.pumpAndSettle();
await tester.ensureVisible(find.text('Read your postcard'));
await tester.tap(find.text('Read your postcard'));
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
expect(find.text('Keep this postcard').hitTestable(), findsOneWidget);
await tester.tap(find.text('Keep this postcard'));
await tester.pumpAndSettle();
await tester.pumpWidget(const SizedBox());
}
},
);
testWidgets(
'shelf daily play preserves the book leaf and returns to the shelf',
(tester) async {
tester.view.physicalSize = const Size(600, 960);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final library = (await tester.runAsync(StoryLibrary.load))!;
await tester.runAsync(() async {
for (final story in library.stories) {
await library.open(story.id);
}
});
final book = (await tester.runAsync(() => library.open('mara-island')))!;
final store = Progress.memory({'language': 'en'});
final g = Game(book, store, library: library)
..showStory(2)
..showLibrary();
await tester.pumpWidget(
RepaintBoundary(
key: const ValueKey('capture'),
child: LumenApp(game: g, adsEnabled: false),
),
);
// Cached asset futures were loaded in the real event loop above.
for (var i = 0; i < 3; i++) {
await tester.runAsync(
() => Future<void>.delayed(const Duration(milliseconds: 20)),
);
await tester.pump();
}
await tester.pumpAndSettle();
await capture(tester, 'shelf');
await tester.tap(find.byKey(const ValueKey('shelf-daily')));
await tester.pumpAndSettle();
expect(g.mode, Mode.daily);
expect(store.text('flutter_screen'), 'story');
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(g.screen, Screen.library);
expect(store.text('notebook_last_page'), book.pages[2].id);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox());
},
);
}