miaoda-game-turn-phaser
v0.3.3
Published
Phaser-friendly observable owner for miaoda-game-turn-core.
Readme
miaoda-game-turn-phaser
Use this Phaser 4 adapter to expose a TurnEngine to Scene UI and input code. Turns advance only through explicit calls; Phaser frame time is not involved.
Install and use
pnpm add miaoda-game-turn-core miaoda-game-turn-phaserconst turns = new TurnController({
actors: [{ id: 'hero', initiative: 12 }, { id: 'enemy', initiative: 8 }],
order: 'initiative',
defaultActionPoints: 2,
});
turns.onChange((state, events) => this.hud.render(state, events));
turns.start();
if (turns.spend(1)) performAction(turns.activeId);The controller mirrors roster changes, AP operations, stop, nextId, remainingIds, snapshots, and loadSnapshot. Scene shutdown removes its listeners. Call adopt() only between onChange notification batches; defer replacement until the callback returns. The package re-exports PhaseTurnEngine, PlayerTurnEngine, and SimultaneousRoundEngine; use them directly because they have no Phaser-specific lifecycle to wrap.
