Class: Deck

Deck(owner, optionsopt)

Represents a deck of cards.

Constructor

new Deck(owner, optionsopt)

Creates a new deck instance.
Parameters:
Name Type Attributes Description
owner Object The owner or parent of the deck (e.g., game or table).
options Object <optional>
Options for deck initialization.
Properties
Name Type Attributes Default Description
center Object <optional>
Center position of the deck.
x number <optional>
center.x X-coordinate of the deck.
y number <optional>
center.y Y-coordinate of the deck.
faceUp boolean <optional>
false Whether the deck is face-up.
type string <optional>
'pile' Type of the deck (e.g., hand, column, pile).
seenFrom string <optional>
'south' Perspective from which the deck is viewed.
label string <optional>
'' Label for the deck.
sticky string <optional>
'bottom' Sticky position of the deck label.
Source:

Extends

  • Array

Classes

Deck

Methods

addCard(card) → {Deck}

Adds a single card to the deck.
Parameters:
Name Type Description
card Card The card to add.
Source:
Returns:
- The deck instance for method chaining.
Type
Deck

addCards(cards) → {Deck}

Adds multiple cards to the deck.
Parameters:
Name Type Description
cards Array.<Card> Array of cards to add.
Source:
Returns:
- The deck instance for method chaining.
Type
Deck

cardPosition(cardIndex) → {Object}

Calculates the position of a card in the deck.
Parameters:
Name Type Description
cardIndex number The index of the card in the deck.
Source:
Returns:
- The position of the card with top, left, bottom, right, centerX, and centerY.
Type
Object

changePerspective(newPerspective)

Changes the perspective of the deck.
Parameters:
Name Type Description
newPerspective string The new perspective (e.g., 'northEast').
Source:

deal(count, hands, speed) → {Promise.<void>}

Deals a specified number of cards to multiple hands.
Parameters:
Name Type Description
count number Number of cards to deal to each hand.
hands Array.<Deck> Array of hands to deal cards to.
speed number Animation speed in milliseconds.
Source:
Returns:
- Resolves after all cards are dealt.
Type
Promise.<void>

on(eventName, func, contextopt)

Attaches an event handler to the deck.
Parameters:
Name Type Attributes Description
eventName string The name of the event (e.g., 'click', 'mousedown', 'mouseup').
func function The function to call on the event.
context Object <optional>
The context to bind the function to.
Source:

removeCard(card) → {boolean}

Removes a card from the deck.
Parameters:
Name Type Description
card Card The card to remove.
Source:
Returns:
- True if the card was removed, false otherwise.
Type
boolean

render(optionsopt) → {Promise.<void>}

Renders the deck visually, positioning cards and updating styles.
Parameters:
Name Type Attributes Description
options Object <optional>
Rendering options.
Properties
Name Type Attributes Default Description
speed number <optional>
Animation speed in milliseconds.
force boolean <optional>
false Whether to force a render.
immediate boolean <optional>
false Whether to render immediately.
Source:
Returns:
- Resolves after rendering is complete.
Type
Promise.<void>

shuffle(optionsopt) → {Deck}

Shuffles the deck.
Parameters:
Name Type Attributes Description
options Object <optional>
Options for rendering after shuffling.
Source:
Returns:
- The deck instance for method chaining.
Type
Deck

sort(optionsopt) → {Deck}

Sorts the cards in the deck.
Parameters:
Name Type Attributes Description
options Object <optional>
Sorting options.
Properties
Name Type Attributes Default Description
compare function | string <optional>
CardsJS.compareByRank Comparison function or sorting type ('suit', 'rank', etc.).
descending boolean <optional>
false Whether to sort in descending order.
Source:
Returns:
- The sorted deck.
Type
Deck

toString() → {string}

Converts the deck to its string representation.
Source:
Returns:
- A string representing the deck.
Type
string

topCard() → {Card}

Gets the top card of the deck.
Source:
Returns:
- The top card of the deck.
Type
Card

trigger(eventName, …args)

Dispatches an event.
Parameters:
Name Type Attributes Description
eventName string The name of the event to dispatch.
args any <repeatable>
Arguments to pass to the event handler.
Source: