miaoda-game-deck-cocos
v0.2.0
Published
Cocos Creator skin for miaoda-game-deck-core: a thin @ccclass Component that owns a Deck, mirrors its draw/move/moveMany/moveAll/shuffle API, and forwards zone-change events so card sprites can animate what moved. For deckbuilders, TCGs and card games.
Maintainers
Readme
miaoda-game-deck-cocos
Use this Cocos Creator adapter to own a miaoda-game-deck-core deck on a node and forward deck events to card sprites. Decks are event-driven, not frame-driven.
Install and use
pnpm add miaoda-game-deck-core miaoda-game-deck-cocosCocos Creator provides the optional cc peer dependency at runtime.
import { DeckComponent } from 'miaoda-game-deck-cocos';
const deck = level.addComponent(DeckComponent).setup({
seed,
zones: [{ id: 'draw', cards: cards }, { id: 'hand', limit: 10 }, { id: 'discard' }],
});
deck.onChange((event) => cardView.animate(event));
deck.shuffle();
deck.draw(5);
for (const card of deck.cardsIn('hand')) spawnCardSprite(card);Queue animation events yourself: a reshuffle-draw emits reshuffle and draw back-to-back. setup, adopt, and loadJSON preserve component listeners, so subscribe once. The component does not advance on update(dt); call deck operations from turn or command logic.
Snapshots are authoritative and contain hidden zones and RNG state. Redact them before sending to another player. Code-created card nodes must use a camera-visible layer.
