Class Deck<TCard>

Stores a first-in-last-out stack of cards. Only the top card is visible, but players can see how many cards are in the stack.

Type Parameters

Hierarchy

Constructors

  • Stores a first-in-last-out stack of cards.

    Type Parameters

    Parameters

    • CardType: CardType<TCard>

      Constructor for the type of card stored in this container. Used to find the card dimensions.

    • Optional options: IDeckOptions

      Optional configuration for the deck.

    Returns Deck<TCard>

Properties

_lastActionIndex: number
alwaysShowCount: boolean
autoSort?: CardComparer<TCard>

Comparison function to use to automatically sort added cards.

defaultOrientation: CardOrientation

Default orientation of cards added to this container.

emptyOutlineStyle: OutlineStyle = OutlineStyle.DASHED
hiddenName?: string

Optional display name for this object when hidden.

name?: string

Optional display name for this object.

outlineStyle: OutlineStyle = OutlineStyle.NONE
promptOutlineStyle: OutlineStyle = OutlineStyle.SOLID_FILLED

Accessors

  • get cardDimensions(): ICardDimensions
  • Gets the dimensions of the card type stored in this container.

    Returns ICardDimensions

  • get count(): number
  • Gets the number of cards in this container.

    Returns number

  • get isEmpty(): boolean
  • If true, this container has no cards.

    Returns boolean

  • get localBounds(): Bounds
  • How much space does this object take up.

    Returns Bounds

  • get selected(): readonly TCard[]
  • Gets all cards in this container that are marked as selected.

    Returns readonly TCard[]

  • get top(): TCard
  • Top-most card, the one that will be next drawn. This is null for empty decks.

    Returns TCard

  • get unselected(): readonly TCard[]
  • Gets all cards in this container that aren't marked as selected.

    Returns readonly TCard[]

Methods

  • Add a single card to the default place in this container.

    Parameters

    • card: TCard

      Card to add.

    Returns void

  • Add a whole wad of cards to the default place in this container.

    Parameters

    • cards: TCard[] | Iterable<TCard>

      Cards to add.

    Returns void

  • Deal up to the given number of cards to each target.

    Parameters

    • targets: ICardReceiver<TCard>[] | TCard[][]

      Recipients of the deal.

    • count: number = 1

      Maximum number of cards to deal to each recipient.

    • firstTargetIndex: number = 0

      Index of the first recipient in targets.

    Returns void

  • Deals up to the given total number of cards, divided between the given targets.

    Parameters

    • targets: ICardReceiver<TCard>[] | TCard[][]

      Recipients of the deal.

    • totalCount: number

      Maximum number of cards to deal in total.

    • Optional handLimit: number
    • firstTargetIndex: number = 0

      Index of the first recipient in targets.

    Returns void

  • Take a single card from this container. The index of the card depends on the container type.

    Returns TCard

    Drawn card.

  • Take a number of cards from this container. The index and order of the cards depend on the container type.

    Parameters

    • count: number

      Number of cards to draw.

    Returns TCard[]

    Drawn cards.

  • Gets a card by index.

    Parameters

    • index: number

      Index of the card to get, starting at 0 and strictly less than count.

    Returns TCard

    Retrieved card.

  • Gets whether the given card is marked as selected.

    Parameters

    • index: number

      Index of the card to get.

    Returns boolean

    Selection state of the given card.

  • Gets whether the given card is marked as selected.

    Parameters

    • card: TCard

      Card to get.

    Returns boolean

    Selection state of the given card.

  • Add a single card to the given place in this container.

    Parameters

    • index: number

      Where to insert the card, starting at 0.

    • card: TCard

      Card to add.

    Returns void

  • Add a wad of cards to the given place in this container.

    Parameters

    • index: number

      Where to insert the cards, starting at 0.

    • cards: TCard[] | Iterable<TCard>

      Cards to add.

    Returns void

  • Called when a card is to be added to this container.

    Parameters

    • card: TCard

      Card to add.

    Returns void

  • Called when a card is to be removed from this container.

    Parameters

    • card: TCard

      Card to remove.

    Returns void

  • Called when cards matching a predicate are to be removed.

    Parameters

    • Optional predicate: ((card) => boolean)

      Function that returns true for cards that should be removed.

        • (card): boolean
        • Parameters

          • card: TCard

          Returns boolean

    Returns TCard[]

  • Remove a specific card from this container. The given card must actually be inside this container.

    Parameters

    • card: TCard

      Card to remove.

    Returns TCard

    The removed card.

  • Remove all cards from this container.

    Returns TCard[]

    The removed cards.

  • Remove the given cards from this container.

    Parameters

    • cards: Iterable<TCard>

    Returns TCard[]

    The removed cards.

  • Remove all cards matching a predicate from this container.

    Parameters

    • predicate: ((card) => boolean)

      Predicate to match for each card.

        • (card): boolean
        • Parameters

          • card: TCard

          Returns boolean

    Returns TCard[]

    The removed cards.

  • Adds or removes cards from this container until there are exactly the given number. Uses the given factory function to create new cards.

    Parameters

    • count: number

      Desired number of cards in this container.

    • factory: (() => TCard)

      Function to create new cards if we need them.

        • (): TCard
        • Returns TCard

    Returns void

  • Set all cards to the given orientation.

    Parameters

    Returns void

  • Sets whether the given card is face up or down.

    Parameters

    • index: number

      Index of the card to set.

    • orientation: CardOrientation

      Orientation to set the card to.

    Returns void

  • Sets whether the given card is face up or down.

    Parameters

    • card: TCard

      Card to set.

    • orientation: CardOrientation

      Orientation to set the card to.

    Returns void

  • Set all cards to be either selected or deselected.

    Parameters

    • selected: boolean

      Selection state to set all cards to.

    Returns void

  • Sets whether the given card is marked as selected.

    Parameters

    • index: number

      Index of the card to set.

    • selected: boolean

      Selection state to set the card to.

    Returns void

  • Sets whether the given card is marked as selected.

    Parameters

    • card: TCard

      Card to set.

    • selected: boolean

      Selection state to set the card to.

    Returns void

  • Shuffle all cards in this container.

    Returns void

  • Shuffle a range of cards in this container.

    Parameters

    • from: number

      Start of the range to shuffle, from 0.

    • to: number

      Exclusive end of the range to shuffle.

    Returns void

  • Toggles the selection state of the given card.

    Parameters

    • index: number

      Index of the card to toggle.

    Returns boolean

  • Toggles the selection state of the given card.

    Parameters

    • card: TCard

    Returns boolean

  • If this container holds enough cards, deals the given number to each target and returns true. Otherwise nothing is dealt and returns false.

    Parameters

    • targets: ICardReceiver<TCard>[]

      Recipients of the deal.

    • count: number = 1

      Exact number of cards to deal to each recipient, if possible.

    Returns boolean

    True if the given number of cards were dealt, otherwise false.

Generated using TypeDoc