Class Deck

All Implemented Interfaces:
PlayerRoster.SideChangeListener, PropertySource, GamePiece, StateMergeable, Auditable, ImageSearchTarget

public class Deck extends Stack implements PlayerRoster.SideChangeListener
A collection of pieces that behaves like a deck, i.e.: Doesn't move. Can't be expanded. Can be shuffled. Can be turned face-up and face-down.
  • Field Details

  • Constructor Details

    • Deck

      @Deprecated(since="2021-12-01", forRemoval=true) public Deck()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Not for internal use, but required for initial build of module
    • Deck

      public Deck(GameModule gameModule)
      Create an empty deck
      Parameters:
      gameModule - The game module
    • Deck

      public Deck(GameModule gameModule, String type)
      Creates an empty deck using specified type information
      Parameters:
      gameModule - The game module
      type - Type information for the deck (the configuration information that does not change during the game)
    • Deck

      public Deck(GameModule gameModule, String type, PropertySource source)
      Creates an empty deck using specified type information
      Parameters:
      gameModule - The game module
      type - Type information for the deck (the configuration information that does not change during the game)
      source - PropertySource
  • Method Details

    • sendEmptyKey

      protected void sendEmptyKey()
      Sends the I-am-empty key for this deck (whether to send it was already determined when the last piece was removed)
    • getComponentTypeName

      public String getComponentTypeName()
      Description copied from interface: Auditable
      Return a description of the Type of trait or Component an Auditable is
      Specified by:
      getComponentTypeName in interface Auditable
      Returns:
      Component Type
    • getComponentName

      public String getComponentName()
      Description copied from interface: Auditable
      Return the name of the trait or Component an Auditable is
      Specified by:
      getComponentName in interface Auditable
      Returns:
      Component name
    • setPropertySource

      public void setPropertySource(PropertySource source)
      Sets the Deck's property source
      Parameters:
      source - PropertySource
    • getOwners

      public String[] getOwners()
    • setOwners

      public void setOwners(String[] o)
    • isRestrictAccess

      public boolean isRestrictAccess()
    • setRestrictAccess

      public void setRestrictAccess(boolean b)
    • sideChanged

      public void sideChanged(String oldSide, String newSide)
      Listener for when the local player changes side. Updates all of our counts of expressions of pieces configured to be counted.
      Specified by:
      sideChanged in interface PlayerRoster.SideChangeListener
      Parameters:
      oldSide - local player's old side
      newSide - local player's new side
    • addGlobalKeyCommand

      public void addGlobalKeyCommand(DeckGlobalKeyCommand globalCommand)
      Adds a Deck Global Key Command (DGKC).
      Parameters:
      globalCommand - The command to add
    • removeGlobalKeyCommand

      public void removeGlobalKeyCommand(DeckGlobalKeyCommand globalCommand)
      Removes a Deck Global Key Command (DGKC).
      Parameters:
      globalCommand - The command to remove
    • getGlobalCommands

      protected String[] getGlobalCommands()
      Returns:
      A list of Deck Global Key Commands for this deck, serialized by their encoder.
    • setGlobalCommands

      protected void setGlobalCommands(String[] commands)
      Sets the list of Deck Global Key Commands for this deck
      Parameters:
      commands - The list of commands to set (in serialized string form)
    • fireNumCardsProperty

      protected void fireNumCardsProperty()
      Set the _numPieces property in the containing Map
    • insertPieceAt

      protected void insertPieceAt(GamePiece p, int index)
      Inserts a piece into a specific position into the Deck (counting down from the top)
      Overrides:
      insertPieceAt in class Stack
      Parameters:
      p - Piece to insert
      index - "How many cards down into the Deck" to put it.
    • insertPieceAt

      protected void insertPieceAt(GamePiece p, int index, boolean suppressDeckCounts)
      Inserts a piece into a specific position into the Deck (counting down from the top)
      Overrides:
      insertPieceAt in class Stack
      Parameters:
      p - Piece to insert
      index - "How many cards down into the Deck" to put it.
      suppressDeckCounts - true if ONLY the Stack part of the operation should be performed (we're just rearranging deck order and so don't want extra property updates). Ignored at Stack level.
    • removePieceAt

      protected void removePieceAt(int index)
      Removes a piece from a specific location in the deck
      Overrides:
      removePieceAt in class Stack
      Parameters:
      index - Piece to remove, counting down from the top
    • removePieceAt

      protected void removePieceAt(int index, boolean suppressDeckCounts)
      Removes a piece from a specific location in the deck
      Overrides:
      removePieceAt in class Stack
      Parameters:
      index - Piece to remove, counting down from the top
      suppressDeckCounts - true if deck counts and firing last card keystroke should be suppressed (because we're actually just rearranging deck order)
    • removeAll

      public void removeAll()
      Removes all pieces from the Deck.
      Overrides:
      removeAll in class Stack
    • setMap

      public void setMap(Map map)
      Sets the Map this Deck appears on
      Specified by:
      setMap in interface GamePiece
      Overrides:
      setMap in class Stack
      Parameters:
      map - Map to assign Deck to
    • addListeners

      public void addListeners()
    • removeListeners

      public void removeListeners()
    • myRefreshType

      public void myRefreshType(String type)
      Sets or refreshes the information for this Deck. See Decorator.myGetType()
      Parameters:
      type - a serialized configuration string to set the "type information" of this Deck, which is information that doesn't change during the course of a single game (e.g. Image Files, Context Menu strings, etc, rules about when deck is shuffled, whether it is face-up or face down, etc).
    • mySetType

      protected void mySetType(String type)
    • getFaceDownOption

      public String getFaceDownOption()
    • isDrawFaceUp

      public boolean isDrawFaceUp()
      Returns:
      true if cards are turned face up when drawn from this deck
    • setDrawFaceUp

      public void setDrawFaceUp(boolean drawFaceUp)
    • setFaceDownOption

      public void setFaceDownOption(String faceDownOption)
    • getSize

      public Dimension getSize()
    • setSize

      public void setSize(Dimension size)
    • getShuffleOption

      public String getShuffleOption()
    • setShuffleOption

      public void setShuffleOption(String shuffleOption)
    • isShuffle

      public boolean isShuffle()
    • getMaxStack

      public int getMaxStack()
    • getMaximumVisiblePieceCount

      public int getMaximumVisiblePieceCount()
      Description copied from class: Stack
      Return the number of pieces that could possible be drawn in the stack, regardless of visibility to any particular player
      Overrides:
      getMaximumVisiblePieceCount in class Stack
      Returns:
      Piece Count
    • getCountExpressions

      public String[] getCountExpressions()
    • doesExpressionCounting

      public boolean doesExpressionCounting()
    • getFaceDownMsgFormat

      public String getFaceDownMsgFormat()
    • setFaceDownMsgFormat

      public void setFaceDownMsgFormat(String faceDownMsgFormat)
    • getReverseMsgFormat

      public String getReverseMsgFormat()
    • setReverseMsgFormat

      public void setReverseMsgFormat(String reverseMsgFormat)
    • getReverseCommand

      public String getReverseCommand()
    • setReverseCommand

      public void setReverseCommand(String s)
    • getReverseKey

      public NamedKeyStroke getReverseKey()
    • setReverseKey

      public void setReverseKey(NamedKeyStroke reverseKey)
    • getShuffleMsgFormat

      public String getShuffleMsgFormat()
    • setShuffleMsgFormat

      public void setShuffleMsgFormat(String shuffleMsgFormat)
    • getShuffleKey

      public NamedKeyStroke getShuffleKey()
    • setShuffleKey

      public void setShuffleKey(NamedKeyStroke shuffleKey)
    • getShuffleCommand

      public String getShuffleCommand()
    • setShuffleCommand

      public void setShuffleCommand(String s)
    • setShuffle

      public void setShuffle(boolean shuffle)
    • isAllowMultipleDraw

      public boolean isAllowMultipleDraw()
    • setAllowMultipleDraw

      public void setAllowMultipleDraw(boolean allowMultipleDraw)
    • isAllowSelectDraw

      public boolean isAllowSelectDraw()
    • setMaxStack

      public void setMaxStack(int maxStack)
    • setCountExpressions

      public void setCountExpressions(String[] countExpressionsString)
    • setExpressionCounting

      public void setExpressionCounting(boolean expressionCounting)
    • setAllowSelectDraw

      public void setAllowSelectDraw(boolean allowSelectDraw)
    • isReversible

      public boolean isReversible()
    • setReversible

      public void setReversible(boolean reversible)
    • setDeckName

      public void setDeckName(String n)
    • getDeckName

      public String getDeckName()
    • getLocalizedDeckName

      public String getLocalizedDeckName()
    • getReshuffleCommand

      public String getReshuffleCommand()
      Returns:
      The popup menu text for the command that sends the entire deck to another deck
    • setReshuffleCommand

      public void setReshuffleCommand(String reshuffleCommand)
    • getReshuffleKey

      public NamedKeyStroke getReshuffleKey()
    • setReshuffleKey

      public void setReshuffleKey(NamedKeyStroke reshuffleKey)
    • getReshuffleTarget

      public String getReshuffleTarget()
      The name of the DrawPile to which the contents of this deck will be sent when the reshuffle command is selected
    • setReshuffleTarget

      public void setReshuffleTarget(String reshuffleTarget)
    • getReshuffleMsgFormat

      public String getReshuffleMsgFormat()
      Returns:
      The message to send to the chat window when the deck is reshuffled to another deck
    • setReshuffleMsgFormat

      public void setReshuffleMsgFormat(String reshuffleMsgFormat)
    • getDrawMultipleMessage

      public String getDrawMultipleMessage()
    • setDrawMultipleMessage

      public void setDrawMultipleMessage(String m)
    • getDrawSpecificMessage

      public String getDrawSpecificMessage()
    • setDrawSpecificMessage

      public void setDrawSpecificMessage(String m)
    • getFaceUpMessage

      public String getFaceUpMessage()
    • setFaceUpMessage

      public void setFaceUpMessage(String m)
    • getFaceDownMessage

      public String getFaceDownMessage()
    • setFaceDownMessage

      public void setFaceDownMessage(String m)
    • getFaceUpMsgFormat

      public String getFaceUpMsgFormat()
    • setFaceUpMsgFormat

      public void setFaceUpMsgFormat(String m)
    • getFaceUpKey

      public NamedKeyStroke getFaceUpKey()
    • setFaceUpKey

      public void setFaceUpKey(NamedKeyStroke k)
    • getFaceDownKey

      public NamedKeyStroke getFaceDownKey()
    • setFaceDownKey

      public void setFaceDownKey(NamedKeyStroke k)
    • getFaceFlipKey

      public NamedKeyStroke getFaceFlipKey()
    • setFaceFlipKey

      public void setFaceFlipKey(NamedKeyStroke k)
    • getSaveMessage

      public String getSaveMessage()
    • setSaveMessage

      public void setSaveMessage(String s)
    • getLoadMessage

      public String getLoadMessage()
    • setLoadMessage

      public void setLoadMessage(String s)
    • getSaveKey

      public NamedKeyStroke getSaveKey()
    • setSaveKey

      public void setSaveKey(NamedKeyStroke k)
    • getLoadKey

      public NamedKeyStroke getLoadKey()
    • setLoadKey

      public void setLoadKey(NamedKeyStroke k)
    • getSaveReport

      public String getSaveReport()
    • setSaveReport

      public void setSaveReport(String s)
    • getLoadReport

      public String getLoadReport()
    • setLoadReport

      public void setLoadReport(String s)
    • isHotkeyOnEmpty

      public boolean isHotkeyOnEmpty()
    • setHotkeyOnEmpty

      public void setHotkeyOnEmpty(boolean b)
    • getNamedEmptyKey

      public NamedKeyStroke getNamedEmptyKey()
    • setEmptyKey

      public void setEmptyKey(NamedKeyStroke k)
    • setRestrictOption

      public void setRestrictOption(boolean restrictOption)
    • isRestrictOption

      public boolean isRestrictOption()
    • setRestrictExpression

      public void setRestrictExpression(PropertyExpression restrictExpression)
    • getRestrictExpression

      public PropertyExpression getRestrictExpression()
    • mayContain

      public boolean mayContain(GamePiece piece)
      Does the specified GamePiece meet the rules to be contained in this Deck.
    • getType

      public String getType()
      Specified by:
      getType in interface GamePiece
      Overrides:
      getType in class Stack
      Returns:
      the encoding type
      See Also:
    • shuffle

      public Command shuffle()
      Shuffle the contents of the Deck
    • getOrderedPieces

      public List<GamePiece> getOrderedPieces()
      Return a list if pieces in the Deck in Dealable order. If this is an Always shuffle Deck, then shuffle the list of pieces, otherwise just reverse the list order so that we deal from the top.
      Returns:
      List of pieces in Dealable order
    • drawCards

      public PieceIterator drawCards()
      Return an iterator of pieces to be drawn from the Deck. Normally, a random piece will be drawn, but if the Deck supports it, the user may have specified a particular set of pieces or a fixed number of pieces to select with the next draw.
    • setContents

      public Command setContents(Collection<GamePiece> c)
      Set the contents of this Deck to a Collection of GamePieces
    • getState

      public String getState()
      Description copied from class: Stack
      Encodes the game state information of the stack into a string
      Specified by:
      getState in interface GamePiece
      Overrides:
      getState in class Stack
      Returns:
      Current encoded "game state" string for the stack
    • setState

      public void setState(String state)
      Description copied from class: Stack
      Decodes the game state information of the stack from a string
      Specified by:
      setState in interface GamePiece
      Overrides:
      setState in class Stack
      Parameters:
      state - Game state information to be loaded into the stack
    • setContentsFaceDown

      public Command setContentsFaceDown(boolean value)
    • reverse

      public Command reverse()
      Reverse the order of the contents of the Deck
    • isDrawOutline

      public boolean isDrawOutline()
    • setOutlineColor

      public void setOutlineColor(Color outlineColor)
    • setDrawOutline

      public void setDrawOutline(boolean drawOutline)
    • getOutlineColor

      public Color getOutlineColor()
    • isFaceDown

      public boolean isFaceDown()
    • pieceAdded

      public Command pieceAdded(GamePiece p)
      Description copied from class: Stack
      Perform some action on a GamePiece that has just been added to this Stack
      Overrides:
      pieceAdded in class Stack
      Parameters:
      p - Game Piece
      Returns:
      a Command that performs the equivalent action when executed
    • pieceRemoved

      public Command pieceRemoved(GamePiece p)
      Description copied from class: Stack
      Perform some action on a GamePiece that has just been removed this Stack
      Overrides:
      pieceRemoved in class Stack
      Parameters:
      p - GamePiece
      Returns:
      a Command that performs the equivalent action when executed
    • setFaceDown

      public void setFaceDown(boolean faceDown)
    • draw

      public void draw(Graphics g, int x, int y, Component obs, double zoom)
      Description copied from class: Stack
      If the obs parameter is a Map, delegate drawing of this Stack to the StackMetrics of that Map. If obs is not a Map, use the default StackMetrics
      Specified by:
      draw in interface GamePiece
      Overrides:
      draw in class Stack
      Parameters:
      g - target Graphics object
      x - x-location of the center of the piece
      y - y-location of the center of the piece
      obs - the Component on which this piece is being drawn
      zoom - the scaling factor.
      See Also:
    • getBlankColor

      protected Color getBlankColor()
      The color used to draw boxes representing cards underneath the top one. If null, then draw each card normally for face-up decks, and duplicate the top card for face-down decks
    • getStackMetrics

      public StackMetrics getStackMetrics()
      Description copied from class: Stack
      StackMetrics encapsulate information on how to draw expanded/unexpanded views of stacks. This method retrieves the appropriate stack metrics to use the stack, based on its map
      Overrides:
      getStackMetrics in class Stack
      Returns:
      stack metrics for the map, if provided, or the default one for the module.
    • boundingBox

      public Rectangle boundingBox()
      Specified by:
      boundingBox in interface GamePiece
      Overrides:
      boundingBox in class Stack
      Returns:
      bounding box for the stack (minimum rectangle to contain the bounding boxes of all the pieces inside)
    • getShape

      public Shape getShape()
      Specified by:
      getShape in interface GamePiece
      Overrides:
      getShape in class Stack
      Returns:
      shape for the stack (shape to contain the shapes of all the pieces inside)
    • getProperty

      public Object getProperty(Object key)
      Description copied from class: Stack
      Stacks themselves do not have any properties, so always return null.
      Specified by:
      getProperty in interface GamePiece
      Specified by:
      getProperty in interface PropertySource
      Overrides:
      getProperty in class Stack
      Parameters:
      key - String key of property to be returned
      Returns:
      always null
    • doFaceDown

      protected void doFaceDown()
    • doFaceUp

      protected void doFaceUp()
    • doFaceFlip

      protected void doFaceFlip()
    • doSaveDeck

      protected void doSaveDeck()
    • doLoadDeck

      protected void doLoadDeck()
    • getKeyCommands

      protected KeyCommand[] getKeyCommands()
    • reportCommand

      protected Command reportCommand(String format, String commandName)
      Format command report as per module designers setup.
    • reportCommand

      protected Command reportCommand(FormattedString reportFormat, String commandName)
      Format command report as per module designers setup. Use a supplied FormattedString with preset properties
    • promptForDragCount

      public void promptForDragCount()
    • promptForNextDraw

      protected void promptForNextDraw()
    • sendToDeck

      public Command sendToDeck()
      Combine the contents of this Deck with the contents of the deck specified by reshuffleTarget
    • extendedSend

      public Command extendedSend(DeckSendKeyCommand dkc)
      Extended Send to Deck Command, based on the configuration of the supplied DeckSendKeyCommand - Deck target can be variable - Optional limit on number of cards to send - Optionally limit selection of cards to those that match an expression - Optionally stop sending cards when a specific card seen (match expression). If anything goes wrong, leave the source Deck untouched and gernate a Bad Data Report
      Parameters:
      dkc - DeckKeyCommand command containing the Send configuration
      Returns:
      Commands executing the send
    • isExpanded

      public boolean isExpanded()
      Overrides:
      isExpanded in class Stack
      Returns:
      true if stack has been visually expanded by the player
    • isAccessibleTo

      public boolean isAccessibleTo(String playerSide)
      Return true if the player playing the given side can access this deck
      See Also:
    • isAccessible

      public boolean isAccessible()
      Return if our current player side can access the deck
    • isPersistable

      public boolean isPersistable()
      Return true if this deck can be saved to and loaded from a file on disk
    • setPersistable

      public void setPersistable(boolean persistable)
    • saveDeck

      public void saveDeck(File f) throws IOException
      Throws:
      IOException
    • loadDeck

      public Command loadDeck(File f) throws IOException
      Throws:
      IOException
    • importDeck

      public Command importDeck()
    • importDeck

      public Command importDeck(File f) throws IOException
      Throws:
      IOException
    • getDragCount

      public int getDragCount()
      Return the number of cards to be returned by next call to drawCards().
    • setDragCount

      public void setDragCount(int dragCount)
      Set the number of cards to be returned by next call to drawCards().
      Parameters:
      dragCount - number of cards to be returned
    • setSelectDisplayProperty

      public void setSelectDisplayProperty(String promptDisplayProperty)
    • setSelectSortProperty

      public void setSelectSortProperty(String promptSortProperty)
    • getSelectDisplayProperty

      public String getSelectDisplayProperty()
    • getSelectSortProperty

      public String getSelectSortProperty()
    • repaintMap

      public void repaintMap()
    • sort

      public Command sort(List<SortParameter> sortParameters, FormattedString reportFormat, String menuCommand)
      Sort the Deck. Called from DeckSortKeyCommand
      Parameters:
      sortParameters - A list of parameters describing the sort
      reportFormat - A report format to generate when sort performed
      Returns:
      Command encapsulating sort