Add browser debugging support

This commit is contained in:
2026-06-22 10:50:03 +09:00
parent 00f7af66e0
commit 48a1a9ccbb
8 changed files with 323 additions and 34 deletions

View File

@@ -10,9 +10,24 @@ import './styles/global.css';
declare global {
interface Window {
__HEROS_GAME__?: Phaser.Game;
__HEROS_DEBUG__?: HerosDebugApi;
}
}
type DebugBattleScene = Phaser.Scene & {
getDebugState?: () => unknown;
toggleDebugOverlay?: () => void;
};
type HerosDebugApi = {
game: Phaser.Game;
activeScenes: () => string[];
battle: () => unknown;
goToBattle: () => void;
scene: (key: string) => Phaser.Scene | undefined;
toggleBattleOverlay: () => void;
};
const config: Phaser.Types.Core.GameConfig = {
type: Phaser.AUTO,
parent: 'game',
@@ -32,4 +47,24 @@ const game = new Phaser.Game(config);
if (import.meta.env.DEV) {
window.__HEROS_GAME__ = game;
window.__HEROS_DEBUG__ = createDebugApi(game);
console.info('[Heros Debug] Use window.__HEROS_DEBUG__.battle() or press F9 in battle.');
}
function createDebugApi(game: Phaser.Game): HerosDebugApi {
const scene = (key: string) => game.scene.getScene(key);
const battleScene = () => scene('BattleScene') as DebugBattleScene | undefined;
return {
game,
activeScenes: () => game.scene.getScenes(true).map((activeScene) => activeScene.scene.key),
battle: () => battleScene()?.getDebugState?.() ?? { active: false, reason: 'BattleScene is not active yet.' },
goToBattle: () => {
game.scene.start('BattleScene');
},
scene,
toggleBattleOverlay: () => {
battleScene()?.toggleDebugOverlay?.();
}
};
}