import 'dart:convert'; import 'package:flutter/services.dart'; import 'puzzle.dart'; class CampaignLevel { CampaignLevel(Map 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 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 levels; final List pages; final Map tracks; static Future load() async { final campaign = jsonDecode( await rootBundle.loadString('assets/campaign.json'), ) as Map; 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; 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, ); } }