Skip to content

Pile Options

Pile Elements take a third optional argument which is an object containing different options.

Option Properties

PropertyTypeDescriptionDefaultAlternative Options
cardElementsArray of CardElements<T>CardElements are any extension of CardElementEmpty ArrayProvide Array
layoutstringAppearance of the Cards in the pilestack'cascade' 'visibleStack'
rulesclass Rule When cards are passed or received these rules determine if its allowednew Rules()Provide Rules
draggablebooleanWhether or not drag and drop is allowed on cards in this piletruefalse
groupDragbooleanAllow dragging a whole stack of cards from this piletruefalse
receiveCardCallbackfunctionPerform game specific logic after a card is received in this pile( ) => trueProvide a function
passCardCallbackfunctionPerform game specific logic after a card is passed from this pile( ) => trueProvide a function
moveCardAnimationfunctionAnimation that occurs when a card is passedanimateMoveCardToNewPileProvide a function

Option Type

typescript
type pileOptionsType<T extends Card> = {
  cardElements: CardElementType<T>[];
  layout: "stack" | "cascade" | "visibleStack";
  rules: Rules<T>;
  draggable: boolean;
  groupDrag: boolean;
  receiveCardCallback: (
    card: CardElementType<T>,
    source: PileElementType<T>,
    destination: PileElementType<T>,
    ...extraArgs: unknown[]
  ) => boolean;
  passCardCallback: (
    card: CardElementType<T>,
    source: PileElementType<T>,
    destination: PileElementType<T>,
    ...extraArgs: unknown[]
  ) => boolean;
  moveCardAnimation:
    | ((
        source: PileElementType<T>,
        destination: PileElementType<T>,
        cardThatWasPassed: CardElementType<T>,
        index: number,
        groupOffset?: number,
      ) => Promise<Animation | undefined>)
    | null;
};

How to use options

Options can be set directly when creating a pileElement, or altered after the pileElement is created.

Suggested: using deck to create piles

Its suggested to use a deck to create pileElements, the drag and drop system works more cohesively when decks are used to create individual piles.

typescript
import { StandardDeckOfCards } from "card-factory";

const deck = StandardDeckOfCards();
const handOptions = {
  layout: "cascade",
  groupDrag: false,
};
const drawPileOptions = {
  rules: new Rules([() => true], [() => false]), // always pass, never receive
  groupDrag: false,
};
const hand = deck.createPileElement("hand", [], handOptions);
const drawPile = deck.createPileElement(
  "drawPile",
  deck.cards,
  drawPileOptions,
);

Please see Rules for more info on the Rules class

Please see Callbacks for more info on callbacks

Please see animations for more info on animations