miaoda-game-turn-cocos
v0.2.0
Published
Cocos Creator skin for miaoda-game-turn-core: a thin @ccclass Component that owns a TurnEngine, mirrors its start/endTurn/spend/grant/canAfford API, and forwards its state changes to a Cocos-friendly onChange callback so your UI reacts to whose-turn-it-is
Maintainers
Readme
miaoda-game-turn-cocos
Use this Cocos Creator adapter to host a TurnEngine on a scene node and expose turn changes to HUDs and game input. Turns are event-driven; this component does not use update(dt).
Install and use
pnpm add miaoda-game-turn-core miaoda-game-turn-cocosimport { TurnManagerComponent } from 'miaoda-game-turn-cocos';
const turns = level.addComponent(TurnManagerComponent).setup({
order: 'initiative',
defaultActionPoints: 2,
actors: units.map((unit) => ({ id: unit.id, initiative: unit.speed })),
});
turns.onChange((state, events) => hud.render(state, events));
turns.start();
if (turns.spend(1)) commitMove(turns.activeId);
turns.endTurn();setup, start, endTurn, AP operations, roster updates, snapshots, and state queries mirror the core. Use .core for direct access or for the other three engine-neutral turn models.
The component is only a lifecycle holder. It does not select abilities, run AI, animate units, or advance on the clock. Cocos destruction releases its subscriptions and engine reference.
