bga-cards
    Preparing search index...

    Class GridStock<T>

    A grid stock with fixed slots (some can be empty)

    Type Parameters

    • T

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    Methods

    addCard addCardElementToParent addCards addColumnToTheLeft addColumnToTheRight addExistingCardElement addRowToTheBottom addRowToTheTop addSlotsIds addUnexistingCardElement animationFromElement bindClick canAddCard cardClick cardNumberUpdated cardOrderChanged cardRemoved contains createSlot extendToX extendToY flipCard getCardClickEventFilter getCardCount getCardElement getCards getGridSlotId getLastPlayedCardStyle getMaxX getMaxY getMinX getMinY getNewCardIndex getSelectableCardStyle getSelectableSlotStyle getSelectedCardStyle getSelectedSlotStyle getSelection getSelectionMode getSlotSelection getSlotsIds getUnselectableCardStyle getUnselectableSlotStyle gridSlotExists isEmpty isSelectable isSelected isSlotSelected makeSlotForCoordinates makeSlotsForCoordinates remove removeAll removeBottomRow removeCard removeCards removeEmptySurroundingSlots removeLastPlayedCardsClass removeLeftmostColumn removeRightmostColumn removeSelectionClasses removeSelectionClassesFromElement removeSlot removeSlotSelectionClasses removeSlotSelectionClassesFromElement removeTopRow selectAll selectAllSlots selectCard selectSlot setCardVisible setGridSlotSelectionMode setLastPlayedCards setSelectableCard setSelectableCards setSelectableGridSlot setSelectableGridSlots setSelectableSlot setSelectableSlots setSelectionMode setSelectionStyleOverrides setSlotSelectionMode setSlotSelectionStyleOverrides setSlotsIds setSort shouldPlaceCard swapCards unselectAll unselectAllSlots unselectCard unselectSlot updateGridTemplateAreas

    Constructors

    Properties

    cards: T[] = []
    counter: CardCounter<T> = null
    element: HTMLElement

    the stock element (should be an empty HTML Element)

    manager: CardManager<T>

    the card manager

    mapCardToCoordinates: (card: T) => GridStockCoordinates
    mapCardToSlot: (card: T) => SlotId
    maxX: number = null
    maxY: number = null
    minX: number = null
    minY: number = null
    onCardAdded?: (card: T) => void

    Called when a card is added to the stock. Returns the added card.

    card: the added card

    onCardClick?: (card: T) => void

    Called when a card is clicked. Returns the clicked card.

    card: the clicked card (can be selected or unselected)

    onCardCountChange?: (cardCount: number) => void

    Called when card count change. Returns the clicked card.

    card: the clicked card (can be selected or unselected)

    onCardRemoved?: (card: T) => void

    Called when a card is removed from the stock. Returns the removed card.

    card: the removed card

    onSelectionChange?: (selection: T[], lastChange: T) => void

    Called when selection change. Returns the selection.

    selection: the selected cards of the stock
    lastChange: the last change on selection card (can be selected or unselected)

    onSlotClick?: (slotId: SlotId) => void

    Called when slot selection change. Returns the clicked slot.

    slot: the clicked slot (can be selected or unselected)

    onSlotSelectionChange?: (selection: SlotId[], lastChange: SlotId) => void

    Called when the slot selection change. Returns the selection.

    selection: the selected SlotId of the stock
    lastChange: the last change on selection slot (can be selected or unselected)

    selectableCards: T[] = []
    selectedCards: T[] = []
    selectedSlots: SlotId[] = []
    selectionMode: CardSelectionMode = 'none'
    settings?: CardStockSettings<T>

    the optional stock settings

    slotClasses: string[]
    slots: HTMLDivElement[] = []
    slotSelectionMode: CardSelectionMode = 'none'
    slotsIds: SlotId[] = []
    sort?: SortFunction<T>

    Methods

    • Add a card to the stock.

      Parameters

      Returns Promise<boolean>

      the promise when the animation is done (true if it was animated, false if it wasn't)

    • Add an array of cards to the stock.

      Parameters

      • cards: T[]

        the cards to add

      • Optionalsettings: AddCardSettings

        a AddCardSettings object

      • shift: number | boolean = false

        if number, the number of milliseconds between each card. if true, chain animations

      Returns Promise<boolean>

    • Add slots to the left of the grid.

      Returns void

    • Add slots to the right of the grid.

      Returns void

    • Add slots to the bottom of the grid.

      Returns void

    • Add slots to the top of the grid.

      Returns void

    • Add new slots ids. Will not change nor empty the existing ones.

      Parameters

      • newSlotsIds: string[]

        the new slotsIds. Will be merged with the old ones.

      Returns void

    • Parameters

      • card: T
      • element: HTMLElement

        The element to animate. The element is added to the destination stock before the animation starts.

      • fromElement: HTMLElement
      • toElement: HTMLElement

        The HTMLElement to attach the card to.

      • insertBefore: HTMLElement
      • settings: AddCardSettings

      Returns Promise<boolean>

    • Returns void

    • Checks if the card can be added. By default, only if it isn't already present in the stock.

      Parameters

      Returns boolean

      if the card can be added

    • Parameters

      • card: T

      Returns void

    • Updates the cards number, if the counter is visible.

      Returns void

    • Triggered after card order is changed, when setting a new sort function.

      Returns void

    • Parameters

      • card: T

        a card

      Returns boolean

      if the card is present in the stock

    • Expand the grid until slots exists for the given x.

      Parameters

      • x: number

      Returns void

    • Expand the grid until slots exists for the given y.

      Parameters

      • y: number

      Returns void

    • Returns the card count in the deck (what the player think there is, for decks, the real number of cards for all visible card stocks).

      Returns number

      the number of card in the stock

    • Parameters

      • card: T

        a card in the stock

      Returns HTMLElement

      the HTML element generated for the card

    • Returns T[]

      the cards on the stock

    • Returns number

    • Returns number

    • Returns number

    • Returns number

    • Parameters

      • card: T

      Returns number

    • Returns T[]

      the selected cards

    • Returns boolean

      if the stock is empty

    • Parameters

      • card: T

      Returns boolean

      if the card is selectable

    • Parameters

      • card: T

      Returns boolean

      if the card is selected

    • Parameters

      Returns boolean

      if the slot is selectd

    • Expand the grid until a slot exists for the given coordinates.

      Parameters

      Returns void

    • Expand the grid until slots exists for the given coordinates.

      Parameters

      Returns void

    • Removes the stock and unregister it on the manager.

      Returns void

    • Remove the slots on the bottom row of the grid. Remove the cards in it if there are some.

      Returns void

    • Remove a card from the stock.

      Parameters

      Returns Promise<boolean>

    • Remove a set of card from the stock.

      Parameters

      Returns Promise<boolean>

    • Remove all slots at the border (top/bottom lines and left/right columns) until there is no unnecessary space surrounding the cards.

      Returns void

    • Remove the mark of the last play cards.

      Parameters

      • OptionalcardClass: string

      Returns void

    • Remove the slots on the leftmost column of the grid. Remove the cards in it if there are some.

      Returns void

    • Remove the slots on the rightmost column of the grid. Remove the cards in it if there are some.

      Returns void

    • Remove the slots on the top row of the grid. Remove the cards in it if there are some.

      Returns void

    • Select all cards

      Parameters

      • silent: boolean = false

      Returns void

    • Select all slots

      Returns void

    • Set selected state to a card.

      Parameters

      • card: T

        the card to select

      • silent: boolean = false

      Returns void

    • Set selected state to a slot.

      Parameters

      • slotId: SlotId

        the slot to select

      Returns void

    • Set the card to its front (visible) or back (not visible) side.

      Parameters

      Returns void

    • Mark the last play cards. Remove the other last play card classes.

      Parameters

      • cards: T[]

        the cards to mark as last played

      • Optionalcolor: string

        the color to use to mark the last played card, usually the player color

      • OptionalcardClass: string

        a class applied on this type of cards, to limit removal to these type of cards.

      Returns void

    • Parameters

      • card: T
      • selectable: boolean

      Returns void

    • Set the selectable class for each card.

      Parameters

      • OptionalselectableCards: T[]

        the selectable cards. If unset, all cards are marked selectable. Default unset.

      Returns void

    • Parameters

      Returns void

    • Parameters

      • slotId: SlotId
      • selectable: boolean

      Returns void

    • Set the selectable class for each slot.

      Parameters

      • OptionalslotIds: SlotId[]

        the selectable slots. If unset, all slots are marked selectable. Default unset.

      Returns void

    • Set if the stock is selectable, and if yes if it can be multiple. If set to 'none', it will unselect all selected cards.

      Parameters

      • selectionMode: CardSelectionMode

        the selection mode

      • OptionalselectableCards: T[]

        the selectable cards (all if unset). Calls setSelectableCards method

      Returns void

    • Parameters

      • element: HTMLElement

      Returns void

    • Set if the stock slot are selectable, and if yes if it can be multiple. If set to 'none', it will unselect all selected slots.

      Parameters

      • selectionMode: CardSelectionMode

        the selection mode

      • OptionalselectableSlots: SlotId[]

        the selectable slats (all if unset). Calls setSelectableSlots method

      Returns void

    • Change the slots ids. Will empty the stock before re-creating the slots.

      Parameters

      • slotsIds: SlotId[]

        the new slotsIds. Will replace the old ones.

      Returns void

    • Changes the sort function of the stock.

      Parameters

      • Optionalsort: SortFunction<T>

        the new sort function. If defined, the stock will be sorted with this new function.

      Returns void

    • Returns if a card should be placed on this stock (with the autoPlace setting).

      Parameters

      • card: T

      Returns boolean

    • Swap cards inside the slot stock.

      Parameters

      • cards: T[]

        the cards to swap

      • Optionalsettings: AddCardSettings

        for updateInformations and selectable

      Returns any

    • Unselect all cards

      Parameters

      • silent: boolean = false

      Returns void

    • Unselect all slots

      Returns void

    • Set unselected state to a card.

      Parameters

      • card: T

        the card to unselect

      • silent: boolean = false

      Returns void

    • Set unselected state to a slot.

      Parameters

      • slotId: SlotId

        the slot to unselect

      Returns void

    • Must be called each time new slots are created.

      Returns void