Migrate Lumen to Dart and Flutter 2.0

This commit is contained in:
Hadrian Burkhardt
2026-10-31 04:08:16 +01:00
parent 07e9253663
commit 302ad6d38e
145 changed files with 5856 additions and 101 deletions
+98
View File
@@ -0,0 +1,98 @@
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'],
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 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;
}
}
class StoryPage {
const StoryPage(this.id, this.title, this.text);
final String id, title, text;
}
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;
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>;
const ids = [
'cottage.dedication',
'cottage.window',
'cottage.match.puzzle',
'cottage.match.memory',
'cottage.folded.note',
'cottage.lantern.sketch',
];
const titles = [
'For you, when you are ready',
'By the cottage window',
'A spark in the drawer',
'One small light',
'A note I nearly forgot',
'The handle, carefully mended',
];
return Book(
campaign['premise'],
(campaign['levels'] as List).map((e) => CampaignLevel(e)).toList(),
List.generate(
6,
(i) => StoryPage(
ids[i],
titles[i],
scripts
.where((s) => s['pageId'] == ids[i])
.map((s) => s['text'] as String)
.firstOrNull ??
'',
),
),
tracks,
);
}
}