Class LayeredPieceCollection.Collection

java.lang.Object
VASSAL.build.module.map.CompoundPieceCollection
VASSAL.build.module.map.LayeredPieceCollection.Collection
All Implemented Interfaces:
PieceCollection, DeckVisitor, PieceVisitor
Enclosing class:
LayeredPieceCollection

public static class LayeredPieceCollection.Collection extends CompoundPieceCollection implements DeckVisitor
The PieceCollection class used by the Map to which a LayeredPieceCollection has been added. This replaces the simpler DefaultPieceCollection that the map would ordinarily use. Here we extend CompoundPieceCollection which maintains a list of pieces currently on each layer as well as a set of flags for whether each layer is presently enabled/visible. We simply provide the methods needed to determine which relative layer (i.e. internally-maintained drawing order) a particular piece (or stack) should be grouped with, by querying the designated property of the piece. In the case of a Stack we use its memory of the most recent layer it was in, if a piece is not available.
  • Constructor Details

    • Collection

      public Collection(String propertyName, String[] layerOrder)
  • Method Details

    • getLayerOrder

      public String[] getLayerOrder()
    • setLayerOrder

      public void setLayerOrder(String[] layerOrder)
    • getPropertyName

      public String getPropertyName()
    • setPropertyName

      public void setPropertyName(String propertyName)
    • getLayerForPiece

      public int getLayerForPiece(GamePiece p)
      Gets the appropriate layer for the given piece (or Stack or Deck). Will call one of the dispatcher methods below, as appropriate: visitDeck(VASSAL.counters.Deck), visitStack(VASSAL.counters.Stack), or visitDefault(VASSAL.counters.GamePiece).
      Overrides:
      getLayerForPiece in class CompoundPieceCollection
      Parameters:
      p - Piece (possibly a Deck or Stack) to obtain layer for
      Returns:
      visual layer
    • getLayerForName

      public int getLayerForName(String layer)
      Description copied from class: CompoundPieceCollection
      Default implementation is "degenerate", having only a single layer -- when extending this class, this method takes layer name and returns the index for that layer, or -1 if the string does not name a valid layer.
      Overrides:
      getLayerForName in class CompoundPieceCollection
      Parameters:
      layer - the name of a layer
      Returns:
      the index for the layer
    • getLayerNameForPiece

      public String getLayerNameForPiece(GamePiece p)
      Description copied from class: CompoundPieceCollection
      Default implementation is "degenerate", having only a single layer -- when extending this class, this method takes a piece and determines which of several layers it belongs in, returning the layer name.
      Overrides:
      getLayerNameForPiece in class CompoundPieceCollection
      Parameters:
      p - A game piece
      Returns:
      the layer name it belongs in.
    • canPiecesMerge

      protected boolean canPiecesMerge(GamePiece p1, GamePiece p2)
      Description copied from class: CompoundPieceCollection
      Two pieces can merge in the default case as long as neither is presently invisible and neither has a Does Not Stack (Hideable) trait.
      Overrides:
      canPiecesMerge in class CompoundPieceCollection
      Parameters:
      p1 - a piece
      p2 - another piece
      Returns:
      WonderTwin powers activate?
    • visitDeck

      public Object visitDeck(Deck d)
      Decks are always displayed in the highest possible layer
      Specified by:
      visitDeck in interface DeckVisitor
      Parameters:
      d - Deck
      Returns:
      layer - the highest possible one
    • visitDefault

      public Object visitDefault(GamePiece p)
      Ordinary pieces are queried for their value of the designated layer property, and this value is then checked against the list of layer names. If there is no match, the "highest possible layer" is used as the default.
      Specified by:
      visitDefault in interface PieceVisitor
      Parameters:
      p - ordinary piece
      Returns:
      layer index for this piece
    • visitStack

      public Object visitStack(Stack s)
      Stacks are first checked for the "topPiece()", but since this method actually hides from us pieces hidden from the currently active player by the Hideable ("Invisible") trait, we fall back on the Stack's own memory of what layer it has been in.
      Specified by:
      visitStack in interface PieceVisitor
      Parameters:
      s - Stack to check layer
      Returns:
      layer index