0718e3f252
- 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.
157 lines
4.8 KiB
Dart
157 lines
4.8 KiB
Dart
// Temporary layout harness: renders the bookshelf at phone/tablet device
|
|
// metrics and writes PNGs to artifacts/library/. Not part of the normal suite.
|
|
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/game.dart';
|
|
import 'package:lumen/domain/library.dart';
|
|
import 'package:lumen/main.dart';
|
|
import 'package:lumen/services/progress.dart';
|
|
|
|
const _screen = ValueKey('screenshot-surface');
|
|
const _output = 'artifacts/library';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
Future<void> capture(
|
|
WidgetTester tester, {
|
|
required String name,
|
|
required Size logical,
|
|
required double dpr,
|
|
double textScale = 1,
|
|
bool captureEnd = false,
|
|
}) async {
|
|
addTearDown(tester.view.reset);
|
|
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
|
|
await tester.runAsync(() async {
|
|
final font = FontLoader('MaraHand')
|
|
..addFont(rootBundle.load('assets/fonts/DancingScript.ttf'));
|
|
await font.load();
|
|
});
|
|
final library = (await tester.runAsync(StoryLibrary.load))!;
|
|
await tester.runAsync(() async {
|
|
for (final story in library.stories) {
|
|
for (final language in story.languages.keys) {
|
|
await library.open(story.id, language: language);
|
|
}
|
|
}
|
|
});
|
|
final assets = <String>{
|
|
'assets/artwork/mara-single-page-v2.png',
|
|
for (final story in library.stories) ?story.coverAsset,
|
|
};
|
|
tester.view.devicePixelRatio = dpr;
|
|
tester.view.physicalSize = Size(logical.width * dpr, logical.height * dpr);
|
|
tester.platformDispatcher.textScaleFactorTestValue = textScale;
|
|
final book = (await tester.runAsync(() => library.open('mara-island')))!;
|
|
final g = Game(book, Progress.memory({'language': 'en'}), library: library)
|
|
..showLibrary();
|
|
await tester.pumpWidget(
|
|
RepaintBoundary(
|
|
key: _screen,
|
|
child: LumenApp(game: g, adsEnabled: false),
|
|
),
|
|
);
|
|
for (var i = 0; i < 3; i++) {
|
|
await tester.runAsync(
|
|
() => Future<void>.delayed(const Duration(milliseconds: 20)),
|
|
);
|
|
await tester.pump();
|
|
}
|
|
await tester.runAsync(() async {
|
|
final context = tester.element(find.byKey(_screen));
|
|
for (final asset in assets) {
|
|
await precacheImage(AssetImage(asset), context);
|
|
}
|
|
});
|
|
await tester.pump();
|
|
await tester.pump(const Duration(milliseconds: 100));
|
|
expect(g.screen, Screen.library, reason: name);
|
|
expect(find.text('Choose a book'), findsOneWidget, reason: name);
|
|
for (final story in library.stories) {
|
|
expect(
|
|
find.byKey(ValueKey('library-book-${story.id}')),
|
|
findsOneWidget,
|
|
reason: name,
|
|
);
|
|
}
|
|
expect(tester.takeException(), isNull, reason: name);
|
|
|
|
Future<void> write(String file) async {
|
|
await tester.runAsync(() async {
|
|
final boundary = tester.renderObject<RenderRepaintBoundary>(
|
|
find.byKey(_screen),
|
|
);
|
|
final image = await boundary.toImage(pixelRatio: dpr);
|
|
final data = await image.toByteData(format: ui.ImageByteFormat.png);
|
|
final target = File('$_output/$file.png');
|
|
await target.parent.create(recursive: true);
|
|
await target.writeAsBytes(data!.buffer.asUint8List());
|
|
image.dispose();
|
|
});
|
|
}
|
|
|
|
await write(name);
|
|
// Every book and Settings must remain reachable by scrolling, including on
|
|
// the smallest phone and at 1.5x text.
|
|
await tester.ensureVisible(find.text('Settings'));
|
|
await tester.pumpAndSettle();
|
|
expect(find.text('Settings').hitTestable(), findsOneWidget, reason: name);
|
|
expect(tester.takeException(), isNull, reason: name);
|
|
if (captureEnd) await write('$name-end');
|
|
await tester.pumpWidget(const SizedBox());
|
|
}
|
|
|
|
testWidgets('phone 360x640', (tester) async {
|
|
await capture(
|
|
tester,
|
|
name: 'shelf-phone-360x640',
|
|
logical: const Size(360, 640),
|
|
dpr: 2,
|
|
captureEnd: true,
|
|
);
|
|
});
|
|
|
|
testWidgets('phone 390x844', (tester) async {
|
|
await capture(
|
|
tester,
|
|
name: 'shelf-phone-390x844',
|
|
logical: const Size(390, 844),
|
|
dpr: 3,
|
|
);
|
|
});
|
|
|
|
testWidgets('phone 360x640 at 1.5x text', (tester) async {
|
|
await capture(
|
|
tester,
|
|
name: 'shelf-phone-360x640-text-1.5x',
|
|
logical: const Size(360, 640),
|
|
dpr: 2,
|
|
textScale: 1.5,
|
|
);
|
|
});
|
|
|
|
testWidgets('tablet portrait 800x1280', (tester) async {
|
|
await capture(
|
|
tester,
|
|
name: 'shelf-tablet-800x1280',
|
|
logical: const Size(800, 1280),
|
|
dpr: 1.5,
|
|
);
|
|
});
|
|
|
|
testWidgets('tablet landscape 1280x800', (tester) async {
|
|
await capture(
|
|
tester,
|
|
name: 'shelf-tablet-1280x800',
|
|
logical: const Size(1280, 800),
|
|
dpr: 2,
|
|
);
|
|
});
|
|
}
|