miaoda-game-mode-phaser
v0.3.3
Published
Phaser Scene gameplay-mode host for miaoda-game-mode-core.
Downloads
1,233
Readme
miaoda-game-mode-phaser
Use this Phaser 4 adapter to advance a miaoda-game-mode-core runner from the Scene update loop for a caller-owned gameplay context.
Install
pnpm add miaoda-game-mode-phaser miaoda-game-mode-corePhaser >=4 <5 is required.
Minimal controller
const modes = scene.modes.create(player, [
{ id: 'powered-up', duration: 12, cooldown: 3 },
{ id: 'boss', group: 'main', priority: 1 },
]);
modes.core.start('powered-up', player);
modes.core.onChange((event) => hud.showMode(event.mode));Register ModePlugin as a Scene Plugin to use scene.modes.create(), or construct new ModeController(scene.events, context, definitions) directly. Phaser update milliseconds are converted to core seconds.
Use setTicking(false) to pause all mode time without changing mode status. For strict fixed-step ownership, select manual time once and advance in seconds:
const modes = scene.modes.create(player, definitions, { tickSource: 'manual' });
fixedStepper.advance(frameDeltaSeconds, (dtSeconds) => {
modes.stepSimulation(dtSeconds);
});Calling stepSimulation in host mode, after destruction, or with malformed seconds fails before mode elapsed time or callbacks change. Legacy { autoUpdate: false } and update(deltaMs) remain supported; update still expects Phaser milliseconds. Scene shutdown destroys plugin-owned controllers and stops further updates.
Public API
ModeController, ModePlugin, ModeControllerOptions, ModeTickSource, and all mode-core types are exported. The adapter owns Scene timing only; start/complete/fail/cancel and context mutations remain explicit game calls.
