Class Deck

All Implemented Interfaces:
PlayerRoster.SideChangeListener, PropertySource, GamePiece, StateMergeable, 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

    • ID

      public static final String ID
      See Also:
      Constant Field Values
    • ALWAYS

      public static final String ALWAYS
      See Also:
      Constant Field Values
    • NEVER

      public static final String NEVER
      See Also:
      Constant Field Values
    • USE_MENU

      public static final String USE_MENU
      See Also:
      Constant Field Values
    • NO_USER

      public static final String NO_USER
      See Also:
      Constant Field Values
    • deckStackMetrics

      protected static final StackMetrics deckStackMetrics
    • drawOutline

      protected boolean drawOutline
    • outlineColor

      protected Color outlineColor
    • size

      protected Dimension size
    • shuffle

      protected boolean shuffle
    • faceDownOption

      protected String faceDownOption
    • shuffleOption

      protected String shuffleOption
    • shuffleCommand

      protected String shuffleCommand
    • allowMultipleDraw

      protected boolean allowMultipleDraw
    • allowSelectDraw

      protected boolean allowSelectDraw
    • reversible

      protected boolean reversible
    • reshuffleCommand

      protected String reshuffleCommand
    • reshuffleTarget

      protected String reshuffleTarget
    • reshuffleMsgFormat

      protected String reshuffleMsgFormat
    • reshuffleListener

      protected NamedKeyStrokeListener reshuffleListener
    • reshuffleKey

      protected NamedKeyStroke reshuffleKey
    • reverseMsgFormat

      protected String reverseMsgFormat
    • reverseCommand

      protected String reverseCommand
    • reverseKey

      protected NamedKeyStroke reverseKey
    • reverseListener

      protected NamedKeyStrokeListener reverseListener
    • shuffleMsgFormat

      protected String shuffleMsgFormat
    • shuffleListener

      protected NamedKeyStrokeListener shuffleListener
    • shuffleKey

      protected NamedKeyStroke shuffleKey
    • faceDownMsgFormat

      protected String faceDownMsgFormat
    • drawFaceUp

      protected boolean drawFaceUp
    • persistable

      protected boolean persistable
    • selectDisplayProperty

      protected FormattedString selectDisplayProperty
    • selectSortProperty

      protected String selectSortProperty
    • countProperty

      protected MutableProperty.Impl countProperty
    • expressionProperties

      protected List<MutableProperty.Impl> expressionProperties
    • deckName

      protected String deckName
    • localizedDeckName

      protected String localizedDeckName
    • faceDown

      protected boolean faceDown
    • dragCount

      protected int dragCount
    • maxStack

      protected int maxStack
    • countExpressions

      protected Deck.CountExpression[] countExpressions
    • expressionCounting

      protected boolean expressionCounting
    • nextDraw

      protected List<GamePiece> nextDraw
    • commands

      protected KeyCommand[] commands
    • globalCommands

      protected List<DeckGlobalKeyCommand> globalCommands
    • hotkeyOnEmpty

      protected boolean hotkeyOnEmpty
    • emptyKey

      protected NamedKeyStroke emptyKey
    • restrictOption

      protected boolean restrictOption
    • restrictExpression

      protected PropertyExpression restrictExpression
    • propertySource

      protected PropertySource propertySource
    • commandEncoder

      protected CommandEncoder commandEncoder
      Special CommandEncoder to handle loading/saving Decks from files.
  • Constructor Details

    • Deck

      @Deprecated public Deck()
      Deprecated.
      Not for internal use, but required for initial build of module
    • Deck

      @Deprecated(since="2020-08-06", forRemoval=true) public Deck​(String type)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • Deck

      @Deprecated(since="2020-08-06", forRemoval=true) public Deck​(String type, PropertySource source)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • 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

    • setPropertySource

      public void setPropertySource​(PropertySource source)
      Sets the Deck's property source
      Parameters:
      source - PropertySource
    • 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.
    • 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
    • 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
    • mySetType

      protected void mySetType​(String type)
      Sets 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).
    • 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)
    • isHotkeyOnEmpty

      public boolean isHotkeyOnEmpty()
    • setHotkeyOnEmpty

      public void setHotkeyOnEmpty​(boolean b)
    • getEmptyKey

      @Deprecated(since="2020-08-06", forRemoval=true) public KeyStroke getEmptyKey()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getNamedEmptyKey

      public NamedKeyStroke getNamedEmptyKey()
    • setEmptyKey

      @Deprecated(since="2020-08-06", forRemoval=true) public void setEmptyKey​(KeyStroke k)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • 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:
      BasicCommandEncoder
    • shuffle

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

      public Command maybeShuffle()
      Shuffle the contents of the Deck, IF it is an always-shuffle, and we're about to ask for a random list from it
    • 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

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

      @Deprecated(since="2020-08-06", forRemoval=true) protected Command setContents​(Iterator<GamePiece> it)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Set the contents of this Deck to an Iterator 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:
      StackMetrics.draw(VASSAL.counters.Stack, java.awt.Graphics, int, int, java.awt.Component, double), Stack.getDefaultMetrics()
    • 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
    • getKeyCommands

      protected KeyCommand[] getKeyCommands()
    • reportCommand

      protected Command reportCommand​(String format, String commandName)
    • 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
    • isExpanded

      public boolean isExpanded()
      Overrides:
      isExpanded in class Stack
      Returns:
      true if stack has been visually expanded by the player
    • 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
    • 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

      protected void repaintMap()