Files
Hadrian Burkhardt 0718e3f252 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.
2026-11-05 14:29:50 +01:00

180 lines
5.4 KiB
Dart

import 'package:flutter/material.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/ambience.dart';
import 'package:lumen/services/narrator.dart';
import 'package:lumen/services/progress.dart';
import 'support/story_fixtures.dart';
class _Output implements AmbienceOutput {
Soundscape? scene;
bool playing = false;
double gain = 0;
final List<String> loads = [];
@override
Future<void> load(Soundscape value) async {
scene = value;
loads.add(value.asset);
}
@override
Future<void> volume(double value) async => gain = value;
@override
Future<void> play() async => playing = true;
@override
Future<void> stop() async => playing = false;
@override
Future<void> dispose() async {}
}
class _Voice extends Narrator {
_Voice(super.tracks);
Duration at = Duration.zero;
bool active = false;
@override
Duration get position => at;
@override
bool get playing => active;
void cue(String id, int milliseconds) {
cancelAutoplay();
page = id;
at = Duration(milliseconds: milliseconds);
active = true;
notifyListeners();
}
@override
Future<void> stop() async {
active = false;
await super.stop();
}
}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
test(
'translated books share nonverbal atmosphere but never English speech',
() async {
final data = fixture();
data['fixture/atmosphere.json'] = {
'scenes': {
'room': {'asset': 'assets/room.wav'},
},
'pages': {'entry-0': 'room'},
};
final story = StoryDefinition({
'id': 'drama',
'title': 'Drama',
'campaignAsset': 'fixture/campaign.json',
'notebookAsset': 'fixture/notebook.json',
'tracksAsset': 'fixture/audio.json',
'atmosphereAsset': 'fixture/atmosphere.json',
'languages': {
'en': {},
'de': {'asset': 'fixture/de.json'},
},
});
final library = StoryLibrary([story], bundle: FixtureBundle(data));
final en = await library.open('drama');
final de = await library.open('drama', language: 'de');
expect(en.atmosphere['entry-0'], de.atmosphere['entry-0']);
expect(en.tracks, isNotEmpty);
expect(de.tracks, isEmpty);
expect(de.atmosphere['entry-1'], isNull);
data['fixture/atmosphere.json'] = {
'scenes': {
'room': {'asset': 'assets/room.wav'},
},
'pages': {'missing-page': 'room'},
};
await expectLater(
Book.loadDefinition(story, bundle: FixtureBundle(data)),
throwsFormatException,
);
},
);
testWidgets(
'cast labels follow cues; atmosphere ducks, changes and stops at home',
(tester) async {
final library = (await tester.runAsync(StoryLibrary.load))!;
final book = (await tester.runAsync(
() => library.open('midnight-invitation'),
))!;
final g = Game(
book,
Progress.memory({'story_access_level': 11}),
library: library,
);
final voice = _Voice(book.tracks);
final output = _Output();
final ambience = Ambience(output: output);
final doorIndex = book.pages.indexWhere(
(p) => p.id == 'midnight.feather.memory',
);
g.showStory(doorIndex);
await tester.pumpWidget(
MaterialApp(
home: Notebook(
game: g,
adsEnabled: false,
narrator: voice,
ambience: ambience,
),
),
);
Future<void> settleAudio() async {
for (var i = 0; i < 14; i++) {
await tester.pump(const Duration(milliseconds: 50));
}
await ambience.settled;
}
await settleAudio();
voice.cancelAutoplay();
expect(output.scene, book.atmosphere['midnight.feather.memory']);
expect(output.gain, closeTo(.28, .001));
for (final role in ['Iris', 'Elias']) {
final cue = (book.tracks['midnight.feather.memory']['cues'] as List)
.firstWhere((c) => c['speaker'] == role);
voice.cue('midnight.feather.memory', cue['startMs'] + 100);
await settleAudio();
expect(find.text('$role · recorded story'), findsOneWidget);
expect(voice.passage, cue['text']);
expect(output.gain, closeTo(.07, .001));
if (role == 'Iris') {
voice.cue('midnight.feather.memory', cue['endMs'] + 100);
await tester.pump();
expect(voice.speaker, 'Iris');
expect(voice.passage, isEmpty);
}
}
// Repeated position updates must not reload the same loop.
expect(output.loads.length, 1);
g.showStory(
book.pages.indexWhere((p) => p.id == 'midnight.candle.entry'),
);
await settleAudio();
voice.cancelAutoplay();
expect(output.scene, book.atmosphere['midnight.candle.entry']);
expect(output.loads.length, 2);
g.showStory(
book.pages.indexWhere((p) => p.id == 'midnight.candle.puzzle'),
);
await settleAudio();
expect(output.loads.length, 2);
g.home();
await settleAudio();
expect(output.playing, false);
expect(voice.page, isEmpty);
await tester.pumpWidget(const SizedBox());
await tester.pumpAndSettle();
},
);
}