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
|
Extends
- Array
Classes
Methods
addCard(card) → {Deck}
Adds a single card to the deck.
Parameters:
Name | Type | Description |
---|---|---|
card |
Card | The card to add. |
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. |
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. |
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'). |
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. |
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. |
removeCard(card) → {boolean}
Removes a card from the deck.
Parameters:
Name | Type | Description |
---|---|---|
card |
Card | The card to remove. |
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
|
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. |
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
|
Returns:
- The sorted deck.
- Type
- Deck
toString() → {string}
Converts the deck to its string representation.
Returns:
- A string representing the deck.
- Type
- string
topCard() → {Card}
Gets the top card of the deck.
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. |