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 Link icon

  • Constructor Details Link icon

    • Deck Link icon

      @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 Link icon

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

      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 Link icon

      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 Link icon

    • sendEmptyKey Link icon

      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 Link icon

      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 Link icon

      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 Link icon

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

      public String[] getOwners()
    • setOwners Link icon

      public void setOwners(String[] o)
    • isRestrictAccess Link icon

      public boolean isRestrictAccess()
    • setRestrictAccess Link icon

      public void setRestrictAccess(boolean b)
    • sideChanged Link icon

      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 Link icon

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

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

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

      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 Link icon

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

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

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

      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 Link icon

      public void addListeners()
    • removeListeners Link icon

      public void removeListeners()
    • myRefreshType Link icon

      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 Link icon

      protected void mySetType(String type)
    • getFaceDownOption Link icon

      public String getFaceDownOption()
    • isDrawFaceUp Link icon

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

      public void setDrawFaceUp(boolean drawFaceUp)
    • setFaceDownOption Link icon

      public void setFaceDownOption(String faceDownOption)
    • getSize Link icon

      public Dimension getSize()
    • setSize Link icon

      public void setSize(Dimension size)
    • getShuffleOption Link icon

      public String getShuffleOption()
    • setShuffleOption Link icon

      public void setShuffleOption(String shuffleOption)
    • isShuffle Link icon

      public boolean isShuffle()
    • getMaxStack Link icon

      public int getMaxStack()
    • getMaximumVisiblePieceCount Link icon

      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 Link icon

      public String[] getCountExpressions()
    • doesExpressionCounting Link icon

      public boolean doesExpressionCounting()
    • getFaceDownMsgFormat Link icon

      public String getFaceDownMsgFormat()
    • setFaceDownMsgFormat Link icon

      public void setFaceDownMsgFormat(String faceDownMsgFormat)
    • getReverseMsgFormat Link icon

      public String getReverseMsgFormat()
    • setReverseMsgFormat Link icon

      public void setReverseMsgFormat(String reverseMsgFormat)
    • getReverseCommand Link icon

      public String getReverseCommand()
    • setReverseCommand Link icon

      public void setReverseCommand(String s)
    • getReverseKey Link icon

      public NamedKeyStroke getReverseKey()
    • setReverseKey Link icon

      public void setReverseKey(NamedKeyStroke reverseKey)
    • getShuffleMsgFormat Link icon

      public String getShuffleMsgFormat()
    • setShuffleMsgFormat Link icon

      public void setShuffleMsgFormat(String shuffleMsgFormat)
    • getShuffleKey Link icon

      public NamedKeyStroke getShuffleKey()
    • setShuffleKey Link icon

      public void setShuffleKey(NamedKeyStroke shuffleKey)
    • getShuffleCommand Link icon

      public String getShuffleCommand()
    • setShuffleCommand Link icon

      public void setShuffleCommand(String s)
    • setShuffle Link icon

      public void setShuffle(boolean shuffle)
    • isAllowMultipleDraw Link icon

      public boolean isAllowMultipleDraw()
    • setAllowMultipleDraw Link icon

      public void setAllowMultipleDraw(boolean allowMultipleDraw)
    • isAllowSelectDraw Link icon

      public boolean isAllowSelectDraw()
    • setMaxStack Link icon

      public void setMaxStack(int maxStack)
    • setCountExpressions Link icon

      public void setCountExpressions(String[] countExpressionsString)
    • setExpressionCounting Link icon

      public void setExpressionCounting(boolean expressionCounting)
    • setAllowSelectDraw Link icon

      public void setAllowSelectDraw(boolean allowSelectDraw)
    • isReversible Link icon

      public boolean isReversible()
    • setReversible Link icon

      public void setReversible(boolean reversible)
    • setDeckName Link icon

      public void setDeckName(String n)
    • getDeckName Link icon

      public String getDeckName()
    • getLocalizedDeckName Link icon

      public String getLocalizedDeckName()
    • getReshuffleCommand Link icon

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

      public void setReshuffleCommand(String reshuffleCommand)
    • getReshuffleKey Link icon

      public NamedKeyStroke getReshuffleKey()
    • setReshuffleKey Link icon

      public void setReshuffleKey(NamedKeyStroke reshuffleKey)
    • getReshuffleTarget Link icon

      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 Link icon

      public void setReshuffleTarget(String reshuffleTarget)
    • getReshuffleMsgFormat Link icon

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

      public void setReshuffleMsgFormat(String reshuffleMsgFormat)
    • getDrawMultipleMessage Link icon

      public String getDrawMultipleMessage()
    • setDrawMultipleMessage Link icon

      public void setDrawMultipleMessage(String m)
    • getDrawSpecificMessage Link icon

      public String getDrawSpecificMessage()
    • setDrawSpecificMessage Link icon

      public void setDrawSpecificMessage(String m)
    • getFaceUpMessage Link icon

      public String getFaceUpMessage()
    • setFaceUpMessage Link icon

      public void setFaceUpMessage(String m)
    • getFaceDownMessage Link icon

      public String getFaceDownMessage()
    • setFaceDownMessage Link icon

      public void setFaceDownMessage(String m)
    • getFaceUpMsgFormat Link icon

      public String getFaceUpMsgFormat()
    • setFaceUpMsgFormat Link icon

      public void setFaceUpMsgFormat(String m)
    • getFaceUpKey Link icon

      public NamedKeyStroke getFaceUpKey()
    • setFaceUpKey Link icon

      public void setFaceUpKey(NamedKeyStroke k)
    • getFaceDownKey Link icon

      public NamedKeyStroke getFaceDownKey()
    • setFaceDownKey Link icon

      public void setFaceDownKey(NamedKeyStroke k)
    • getFaceFlipKey Link icon

      public NamedKeyStroke getFaceFlipKey()
    • setFaceFlipKey Link icon

      public void setFaceFlipKey(NamedKeyStroke k)
    • getSaveMessage Link icon

      public String getSaveMessage()
    • setSaveMessage Link icon

      public void setSaveMessage(String s)
    • getLoadMessage Link icon

      public String getLoadMessage()
    • setLoadMessage Link icon

      public void setLoadMessage(String s)
    • getSaveKey Link icon

      public NamedKeyStroke getSaveKey()
    • setSaveKey Link icon

      public void setSaveKey(NamedKeyStroke k)
    • getLoadKey Link icon

      public NamedKeyStroke getLoadKey()
    • setLoadKey Link icon

      public void setLoadKey(NamedKeyStroke k)
    • getSaveReport Link icon

      public String getSaveReport()
    • setSaveReport Link icon

      public void setSaveReport(String s)
    • getLoadReport Link icon

      public String getLoadReport()
    • setLoadReport Link icon

      public void setLoadReport(String s)
    • isHotkeyOnEmpty Link icon

      public boolean isHotkeyOnEmpty()
    • setHotkeyOnEmpty Link icon

      public void setHotkeyOnEmpty(boolean b)
    • getNamedEmptyKey Link icon

      public NamedKeyStroke getNamedEmptyKey()
    • setEmptyKey Link icon

      public void setEmptyKey(NamedKeyStroke k)
    • setRestrictOption Link icon

      public void setRestrictOption(boolean restrictOption)
    • isRestrictOption Link icon

      public boolean isRestrictOption()
    • setRestrictExpression Link icon

      public void setRestrictExpression(PropertyExpression restrictExpression)
    • getRestrictExpression Link icon

      public PropertyExpression getRestrictExpression()
    • mayContain Link icon

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

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

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

      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 Link icon

      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 Link icon

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

      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 Link icon

      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 Link icon

      public Command setContentsFaceDown(boolean value)
    • reverse Link icon

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

      public boolean isDrawOutline()
    • setOutlineColor Link icon

      public void setOutlineColor(Color outlineColor)
    • setDrawOutline Link icon

      public void setDrawOutline(boolean drawOutline)
    • getOutlineColor Link icon

      public Color getOutlineColor()
    • isFaceDown Link icon

      public boolean isFaceDown()
    • pieceAdded Link icon

      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 Link icon

      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 Link icon

      public void setFaceDown(boolean faceDown)
    • draw Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      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 Link icon

      protected void doFaceDown()
    • doFaceUp Link icon

      protected void doFaceUp()
    • doFaceFlip Link icon

      protected void doFaceFlip()
    • doSaveDeck Link icon

      protected void doSaveDeck()
    • doLoadDeck Link icon

      protected void doLoadDeck()
    • getKeyCommands Link icon

      protected KeyCommand[] getKeyCommands()
    • reportCommand Link icon

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

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

      public void promptForDragCount()
    • promptForNextDraw Link icon

      protected void promptForNextDraw()
    • sendToDeck Link icon

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

      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 Link icon

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

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

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

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

      public void setPersistable(boolean persistable)
    • saveDeck Link icon

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

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

      public Command importDeck()
    • importDeck Link icon

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

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

      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 Link icon

      public void setSelectDisplayProperty(String promptDisplayProperty)
    • setSelectSortProperty Link icon

      public void setSelectSortProperty(String promptSortProperty)
    • getSelectDisplayProperty Link icon

      public String getSelectDisplayProperty()
    • getSelectSortProperty Link icon

      public String getSelectSortProperty()
    • repaintMap Link icon

      public void repaintMap()
    • sort Link icon

      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