miaoda-game-euchre-react
v0.3.3
Published
React DOM bindings for the fixed four-player partnership Euchre rules profile.
Maintainers
Readme
miaoda-game-euchre-react
React bindings and a framework-neutral controller for the fixed four-player partnership Euchre profile.
pnpm add miaoda-game-euchre-reactimport {
createEuchreGame,
EuchreController,
useEuchreView,
} from 'miaoda-game-euchre-react';
const controller = new EuchreController(
createEuchreGame({ playerIds: ['north', 'east', 'south', 'west'] }),
'north',
);
function BidControls() {
const view = useEuchreView(controller);
return view.legalActions.canOrderUp ? (
<button onClick={() => controller.dispatch({ type: 'order-up', playerId: view.viewerId })}>
Order up
</button>
) : null;
}Render bidding from canOrderUp, callSuits, and canPass, then use the exhaustive dealer-discard
and trick-play card id lists. The view contains only the selected player's hand and public game facts.
Commits and reconnects
const unsubscribe = controller.onCommit(({ revision, view, events }) => {
queueAnimations(events);
persistRevision(revision);
renderHud(view);
});
controller.replaceSnapshot(JSON.parse(savedJson), serverRevision);
controller.setViewerId('east');Only accepted actions advance revision or publish commits. Snapshot replacement validates replay
history and updates the view without fabricating historical events. Invalid viewers, corrupt snapshots,
and lower revisions throw without partially changing the controller.
Phaser
pnpm add miaoda-game-command-phaserimport { PhaserGameBridge } from 'miaoda-game-command-phaser';
const bridge = new PhaserGameBridge().setup(controller);
bridge.consumeWith((event) => animateEuchreEvent(event));
bridge.dispatch({ type: 'pass', playerId: controller.state.activePlayerId });
bridge.destroy();
unsubscribe();The bridge consumes successful commits in order and exposes the same player-safe view and public events as React. Dealer discard remains eventless and private.
