Enhance postcard puzzles and narration

This commit is contained in:
Hadrian Burkhardt
2026-11-14 08:55:48 +01:00
parent abaab927d9
commit b19295472d
158 changed files with 5257 additions and 1695 deletions
+123 -4
View File
@@ -8,9 +8,11 @@ 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/domain/postcards.dart';
import 'package:lumen/main.dart';
import 'package:lumen/services/ads.dart';
import 'package:lumen/services/progress.dart';
import 'package:lumen/ui/postcards.dart';
import 'postcards_test.dart' show solve;
@@ -51,6 +53,41 @@ void main() {
'MaraHand',
)..addFont(rootBundle.load('assets/fonts/DancingScript.ttf'))).load();
});
testWidgets('postcard reveal fades from a blurred memory to clear colour', (
tester,
) async {
await tester.pumpWidget(
MaterialApp(home: PostcardRevealArt(card: islandPostcards.first)),
);
final blur = find.byType(ImageFiltered);
final color = find.byKey(const ValueKey('postcard-reveal-color'));
final initial = tester.widget<ColorFiltered>(color).colorFilter;
expect(tester.widget<ImageFiltered>(blur).enabled, isTrue);
await tester.pump(const Duration(milliseconds: 900));
expect(tester.widget<ColorFiltered>(color).colorFilter, isNot(initial));
expect(tester.widget<ImageFiltered>(blur).enabled, isTrue);
await tester.pump(const Duration(milliseconds: 900));
expect(tester.widget<ImageFiltered>(blur).enabled, isFalse);
});
testWidgets('later postcard puzzles show both lantern markers and the rule', (
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 game = Game(book, Progress.memory())..startPostcard(2, 2);
await tester.pumpWidget(LumenApp(game: game, adsEnabled: false));
await tester.pumpAndSettle();
final pair = game.puzzle!.lanternPairs.single;
expect(find.byKey(ValueKey('lantern-${pair.first}')), findsOneWidget);
expect(find.byKey(ValueKey('lantern-${pair.second}')), findsOneWidget);
expect(
find.text('Matching lanterns: exactly one of the two cells is lit.'),
findsOneWidget,
);
expect(tester.takeException(), isNull);
});
testWidgets(
'three patterns collect a readable postcard before a single no-fill break',
(tester) async {
@@ -76,10 +113,39 @@ void main() {
),
);
await tester.pumpAndSettle();
await tester.runAsync(() async {
await precacheImage(
const AssetImage('assets/postcards/illustrations/washing-line.png'),
tester.element(find.byKey(const ValueKey('postcard-collection'))),
);
});
await tester.pump();
final lockedFilter = tester
.widget<ColorFiltered>(find.byKey(const ValueKey('postcard-art-0')))
.colorFilter;
expect(
tester
.widget<ImageFiltered>(
find.byKey(const ValueKey('postcard-blur-0')),
)
.enabled,
isTrue,
);
await capture(tester, 'collection');
await tester.tap(find.byKey(const ValueKey('start-postcard-0')));
await tester.tap(find.byKey(const ValueKey('postcard-0')));
await tester.pumpAndSettle();
expect(g.postcardSlot, 0);
expect(find.byKey(const ValueKey('area-0')), findsOneWidget);
expect(find.byKey(const ValueKey('area-1')), findsOneWidget);
expect(find.byKey(const ValueKey('area-2')), findsOneWidget);
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);
expect(
find.byKey(const ValueKey('selected-region-outline')),
findsOneWidget,
);
await capture(tester, 'puzzle');
for (var slot = 0; slot < 3; slot++) {
solve(g);
@@ -93,17 +159,66 @@ void main() {
expect(ads.opportunities, 0);
}
expect(find.text('Keep this postcard'), findsOneWidget);
final message = tester.widget<SelectableText>(
find.byKey(const ValueKey('postcard-message')),
);
expect(message.style?.fontFamily, 'MaraHand');
await capture(tester, 'collected');
await tester.tap(find.text('Keep this postcard'));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('postcard-reveal')), findsOneWidget);
final revealedImage = tester.widget<Image>(
find.descendant(
of: find.byKey(const ValueKey('postcard-reveal')),
matching: find.byType(Image),
),
);
expect(
(revealedImage.image as AssetImage).assetName,
'assets/postcards/illustrations/washing-line.png',
);
expect(ads.opportunities, 0);
await capture(tester, 'reveal');
await tester.tap(find.text('Back to collection'));
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')));
expect(
tester
.widget<ImageFiltered>(
find.byKey(const ValueKey('postcard-blur-0')),
)
.enabled,
isFalse,
);
expect(
tester
.widget<ImageFiltered>(
find.byKey(const ValueKey('postcard-blur-1')),
)
.enabled,
isTrue,
);
expect(
tester
.widget<ColorFiltered>(find.byKey(const ValueKey('postcard-art-0')))
.colorFilter,
isNot(lockedFilter),
);
expect(
tester
.widget<ColorFiltered>(find.byKey(const ValueKey('postcard-art-1')))
.colorFilter,
lockedFilter,
);
await tester.ensureVisible(find.byKey(const ValueKey('postcard-0')));
await tester.tap(find.byKey(const ValueKey('postcard-0')));
await tester.pumpAndSettle();
await tester.tap(find.text('Keep this postcard'));
await tester.pumpAndSettle();
await tester.tap(find.text('Back to collection'));
await tester.pumpAndSettle();
expect(ads.opportunities, 1);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox());
@@ -127,7 +242,7 @@ void main() {
g.startPostcard(0);
await tester.pumpAndSettle();
expect(tester.takeException(), isNull);
for (var i = 0; i < 25; i++) {
for (var i = 0; i < 49; i++) {
final bounds = tester.getRect(find.byKey(ValueKey('cell-$i')));
expect(bounds.top, greaterThanOrEqualTo(0));
expect(bounds.bottom, lessThanOrEqualTo(size.height));
@@ -144,6 +259,10 @@ void main() {
expect(find.text('Keep this postcard').hitTestable(), findsOneWidget);
await tester.tap(find.text('Keep this postcard'));
await tester.pumpAndSettle();
expect(find.byKey(const ValueKey('postcard-reveal')), findsOneWidget);
expect(tester.takeException(), isNull);
await tester.tap(find.text('Back to collection'));
await tester.pumpAndSettle();
await tester.pumpWidget(const SizedBox());
}
},