Files
logic-puzzle/lib/domain/book.dart
T
Hadrian Burkhardt 68871ec573 Expand narrated story, preserve solved patterns, and add ambience
Connect the island story with new character memories and narrative transitions.
Blend each solved symbol into its artwork and retain a replayable pattern stamp.
Allow completed grids to be inspected after navigation and app restarts.
Reduce campaign difficulty spikes and keep explained story hints free.

Append 24 narrated continuations while preserving original PCM takes. Add
four offline environmental loops with saved mute/volume controls, scene
fades, narration ducking and lifecycle handling.

Validation: 31 unit/widget tests, Flutter analysis, narration and soundscape
asset checks, tablet discovery layouts and extended-audio integration,
including simultaneous active voice and ambience mixer tracks.
2026-11-02 05:04:57 +01:00

139 lines
4.0 KiB
Dart

import 'dart:convert';
import 'package:flutter/services.dart';
import 'puzzle.dart';
class CampaignLevel {
CampaignLevel(Map<String, dynamic> data)
: chapter = data['chapter'],
title = data['title'],
object = data['object'],
before = data['before'],
after = data['after'],
beforeContinuation = data['beforeContinuation'] as String? ?? '',
afterContinuation = data['afterContinuation'] as String? ?? '',
illustrationAsset = data['illustrationAsset'] as String?,
picture = (data['picture'] as String).split('').map(int.parse).toList(),
clues = data['clues'],
areas = data['areas'];
final String chapter, title, object, before, after, clues, areas;
final String beforeContinuation, afterContinuation;
final String? illustrationAsset;
final List<int> picture;
Puzzle puzzle() {
final p = Puzzle(7, picture);
if (clues.isNotEmpty) {
for (final c in clues.split(',')) {
p.given[int.parse(c)] = true;
}
}
if (areas.isNotEmpty) {
var i = 0;
for (final a in areas.split(';')) {
final v = a.split(',').map(int.parse).toList();
p.regions.add(
Region(String.fromCharCode(65 + i++), v[0], v[1], v[2], v[3]),
);
}
}
return p;
}
}
enum StoryPageType {
dedication,
entry,
puzzle,
memory,
note,
inspection,
closing,
}
class StoryPage {
const StoryPage(
this.id,
this.title,
this.text, {
this.type = StoryPageType.entry,
this.campaignIndex,
this.speaker = '',
this.illustrationAsset,
this.continuation = '',
});
final String id, title, text;
final String continuation;
final StoryPageType type;
final int? campaignIndex;
final String speaker;
final String? illustrationAsset;
}
class Book {
Book(this.premise, this.levels, this.pages, this.tracks);
final String premise;
final List<CampaignLevel> levels;
final List<StoryPage> pages;
final Map<String, dynamic> tracks;
int pageFor(int campaignIndex, StoryPageType type) => pages.indexWhere(
(p) => p.campaignIndex == campaignIndex && p.type == type,
);
static Future<Book> load() async {
final campaign = jsonDecode(
await rootBundle.loadString('assets/campaign.json'),
) as Map<String, dynamic>;
final scripts = jsonDecode(
await rootBundle.loadString('assets/narration/scripts.json'),
) as List;
final tracks =
jsonDecode(
await rootBundle.loadString(
'assets/audio/narration_manifest.json',
),
)['tracks']
as Map<String, dynamic>;
final levels = (campaign['levels'] as List)
.map((e) => CampaignLevel(e))
.toList();
final notebook = jsonDecode(
await rootBundle.loadString('assets/notebook.json'),
) as Map<String, dynamic>;
return Book(
campaign['premise'],
levels,
(notebook['pages'] as List).map((record) {
final index = record['campaignIndex'] as int?;
final text = switch (record['textSource']) {
'before' => levels[index!].before,
'after' => levels[index!].after,
'recording' =>
scripts
.where((s) => s['pageId'] == record['id'])
.map((s) => (s['baseText'] ?? s['text']) as String)
.firstOrNull ??
'',
_ => record['text'] as String? ?? '',
};
return StoryPage(
record['id'],
record['title'],
text,
type: StoryPageType.values.byName(record['type']),
campaignIndex: index,
speaker: record['speaker'] as String? ?? '',
illustrationAsset: record['illustrationAsset'] as String?,
continuation:
record['continuation'] as String? ??
switch (record['textSource']) {
'before' => levels[index!].beforeContinuation,
'after' => levels[index!].afterContinuation,
_ => '',
},
);
}).toList(),
tracks,
);
}
}