Complete cottage notebook with narration and discovery-only artwork
This commit is contained in:
+56
-30
@@ -38,9 +38,31 @@ class CampaignLevel {
|
||||
}
|
||||
}
|
||||
|
||||
enum StoryPageType {
|
||||
dedication,
|
||||
entry,
|
||||
puzzle,
|
||||
memory,
|
||||
note,
|
||||
inspection,
|
||||
closing,
|
||||
}
|
||||
|
||||
class StoryPage {
|
||||
const StoryPage(this.id, this.title, this.text);
|
||||
const StoryPage(
|
||||
this.id,
|
||||
this.title,
|
||||
this.text, {
|
||||
this.type = StoryPageType.entry,
|
||||
this.campaignIndex,
|
||||
this.speaker = '',
|
||||
this.illustrationAsset,
|
||||
});
|
||||
final String id, title, text;
|
||||
final StoryPageType type;
|
||||
final int? campaignIndex;
|
||||
final String speaker;
|
||||
final String? illustrationAsset;
|
||||
}
|
||||
|
||||
class Book {
|
||||
@@ -49,6 +71,9 @@ class Book {
|
||||
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'),
|
||||
@@ -63,37 +88,38 @@ class Book {
|
||||
),
|
||||
)['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',
|
||||
];
|
||||
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'],
|
||||
(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 ??
|
||||
'',
|
||||
),
|
||||
),
|
||||
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['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?,
|
||||
);
|
||||
}).toList(),
|
||||
tracks,
|
||||
);
|
||||
}
|
||||
|
||||
+34
-10
@@ -25,6 +25,8 @@ class Game extends ChangeNotifier {
|
||||
Difficulty get difficulty =>
|
||||
Difficulty.fromStored(progress.text('difficulty', 'EASY'));
|
||||
int storyIndex = 0, campaignIndex = 0, playingLevel = 1, selectedArea = 0;
|
||||
int contentsChapter = 0;
|
||||
StoryPage get storyPage => book.pages[storyIndex];
|
||||
DateTime date = DateTime.now();
|
||||
Puzzle? puzzle;
|
||||
List<int> cells = [];
|
||||
@@ -38,8 +40,10 @@ class Game extends ChangeNotifier {
|
||||
int get recoveredCount =>
|
||||
List.generate(12, (i) => recovered(i)).where((v) => v).length;
|
||||
int get unlocked => progress.number('campaignUnlocked').clamp(0, 11);
|
||||
int get accessible =>
|
||||
math.max(unlocked, progress.number('story_access_level').clamp(0, 11));
|
||||
int get accessible => math.max(
|
||||
3,
|
||||
math.max(unlocked, progress.number('story_access_level').clamp(0, 11)),
|
||||
);
|
||||
int get practiceLevel => progress.number('level_${difficulty.stored}', 1);
|
||||
int get streak => visibleStreak(
|
||||
progress.number('lastDaily', -99999),
|
||||
@@ -54,10 +58,10 @@ class Game extends ChangeNotifier {
|
||||
showStory(
|
||||
book.pages
|
||||
.indexWhere((p) => p.id == progress.text('notebook_last_page'))
|
||||
.clamp(0, 5),
|
||||
.clamp(0, book.pages.length - 1),
|
||||
);
|
||||
} else if (saved == 'contents') {
|
||||
contents();
|
||||
contents(progress.number('notebook_contents_chapter'));
|
||||
} else if (saved == 'briefing') {
|
||||
briefing(campaignIndex);
|
||||
} else if (saved == 'reveal' &&
|
||||
@@ -109,25 +113,37 @@ class Game extends ChangeNotifier {
|
||||
void showStory(int i) {
|
||||
_request++;
|
||||
busy = false;
|
||||
storyIndex = i.clamp(0, 5);
|
||||
storyIndex = i.clamp(0, book.pages.length - 1);
|
||||
mode = Mode.campaign;
|
||||
campaignIndex = 0;
|
||||
if (storyIndex == 2 && key != 'story_v1_0') {
|
||||
_read(book.levels[0].puzzle(), 'story_v1_0');
|
||||
campaignIndex = storyPage.campaignIndex ?? 0;
|
||||
if (storyPage.type == StoryPageType.puzzle &&
|
||||
key != 'story_v1_$campaignIndex') {
|
||||
_read(book.levels[campaignIndex].puzzle(), 'story_v1_$campaignIndex');
|
||||
}
|
||||
unawaited(progress.set('notebook_last_page', book.pages[storyIndex].id));
|
||||
unawaited(progress.set('viewed_${book.pages[storyIndex].id}', true));
|
||||
_route(Screen.story);
|
||||
}
|
||||
|
||||
void contents() {
|
||||
void contents([int? chapter]) {
|
||||
_request++;
|
||||
busy = false;
|
||||
contentsChapter = (chapter ?? campaignIndex ~/ 4).clamp(0, accessible ~/ 4);
|
||||
unawaited(progress.set('notebook_contents_chapter', contentsChapter));
|
||||
_route(Screen.contents);
|
||||
}
|
||||
|
||||
void leaveCottage() {
|
||||
unawaited(progress.set('story_access_level', math.max(accessible, 4)));
|
||||
briefing(4);
|
||||
}
|
||||
|
||||
void briefing(int i) {
|
||||
campaignIndex = i.clamp(0, accessible);
|
||||
if (campaignIndex < 4) {
|
||||
showStory(book.pageFor(campaignIndex, StoryPageType.entry));
|
||||
return;
|
||||
}
|
||||
mode = Mode.campaign;
|
||||
_route(Screen.briefing);
|
||||
}
|
||||
@@ -138,6 +154,10 @@ class Game extends ChangeNotifier {
|
||||
return;
|
||||
}
|
||||
campaignIndex = i;
|
||||
if (i < 4) {
|
||||
showStory(book.pageFor(i, StoryPageType.memory));
|
||||
return;
|
||||
}
|
||||
mode = Mode.campaign;
|
||||
_route(Screen.reveal);
|
||||
}
|
||||
@@ -187,6 +207,10 @@ class Game extends ChangeNotifier {
|
||||
}
|
||||
campaignIndex = i;
|
||||
mode = Mode.campaign;
|
||||
if (i < 4) {
|
||||
showStory(book.pageFor(i, StoryPageType.puzzle));
|
||||
return;
|
||||
}
|
||||
_read(book.levels[i].puzzle(), 'story_v1_$i');
|
||||
_route(Screen.game);
|
||||
}
|
||||
@@ -287,7 +311,7 @@ class Game extends ChangeNotifier {
|
||||
),
|
||||
);
|
||||
if (screen == Screen.story) {
|
||||
showStory(3);
|
||||
showStory(book.pageFor(campaignIndex, StoryPageType.memory));
|
||||
} else {
|
||||
reveal(campaignIndex);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user