Spaces:
Running on Zero
Running on Zero
File size: 3,078 Bytes
c670567 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | /**
* ============================================================================
* CHAPTER SELECT SCENE - Stage/level/chapter selector
* ============================================================================
*
* Displays a grid or list of selectable chapters/stages/duels.
* Manages locked/unlocked/completed states using GameDataManager.
*
* HOOK METHODS:
* - getChapterList(): Return array of chapter configs (REQUIRED)
* - createBackground(): Custom background
* - createChapterButtons(): Custom button layout
* - onChapterSelected(chapterId): Handle chapter selection
* - isChapterUnlocked(chapterId): Check if chapter is accessible
*
* INTEGRATION:
* - Reads progress from GameDataManager
* - Launches the selected chapter scene
*/
import Phaser from 'phaser';
// ============================================================================
// TYPES & INTERFACES
// ============================================================================
export interface ChapterInfo {
/** Unique chapter ID */
id: string;
/** Display title */
title: string;
/** Scene key to launch */
sceneKey: string;
/** Short description */
description?: string;
/** Thumbnail image key */
thumbnailKey?: string;
/** Whether chapter is locked by default */
lockedByDefault?: boolean;
}
// ============================================================================
// BASE CLASS
// ============================================================================
export class ChapterSelectScene extends Phaser.Scene {
protected chapters: ChapterInfo[] = [];
constructor() {
super({ key: 'ChapterSelectScene' });
}
create(): void {
this.chapters = this.getChapterList();
this.createBackground();
this.createChapterButtons();
this.setupInputs();
}
// ============================================================================
// HOOKS
// ============================================================================
/**
* HOOK (REQUIRED): Return the list of chapters available for selection.
* Override in subclass or configure via gameConfig.json.
*/
protected getChapterList(): ChapterInfo[] {
// Override in subclass
return [];
}
/** HOOK: Create the background. */
protected createBackground(): void {}
/**
* HOOK: Create the chapter selection buttons.
* Default implementation creates a DOM-based button grid.
*/
protected createChapterButtons(): void {
// Implementation: create interactive chapter buttons
}
/**
* HOOK: Called when a chapter is selected.
* Default: start the chapter scene.
*/
protected onChapterSelected(chapter: ChapterInfo): void {
this.scene.start(chapter.sceneKey);
}
/**
* HOOK: Check if a chapter is unlocked.
* Override for custom unlock logic.
*/
protected isChapterUnlocked(chapterId: string): boolean {
// Default: first chapter always unlocked, others check GameDataManager
return true;
}
/** HOOK: Set up custom inputs. */
protected setupInputs(): void {}
}
|