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.-
Field Summary
Fields inherited from class CompoundPieceCollection
bottomLayer, enabled, layersModifier and TypeFieldDescriptionprotected intprotected boolean[]protected SimplePieceCollection[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleancanPiecesMerge(GamePiece p1, GamePiece p2) Two pieces can merge in the default case as long as neither is presently invisible and neither has a Does Not Stack (Hideable) trait.intgetLayerForName(String layer) 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.intGets the appropriate layer for the given piece (or Stack or Deck).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.String[]voidsetLayerOrder(String[] layerOrder) voidsetPropertyName(String propertyName) Decks are always displayed in the highest possible layerOrdinary pieces are queried for their value of the designated layer property, and this value is then checked against the list of layer names.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 theHideable("Invisible") trait, we fall back on the Stack's own memory of what layer it has been in.Methods inherited from class CompoundPieceCollection
add, canMerge, canStackAndPieceMerge, canStacksMerge, clear, getAllPieces, getBottomLayer, getCollectionForPiece, getLayerCount, getPieces, getPieces, getTopLayer, indexOf, initLayers, moveToBack, moveToFront, remove, reset, rotate, rotate, setBottomLayer, setLayerEnabled, setLayerEnabled, toggleLayerEnabled, toggleLayerEnabledModifier and TypeMethodDescriptionvoidAdds a piece to the overall collection, by adding it to the simple collection for the layer it belongs in.booleanUsed when moving a piece on top of another piece to determine whether they can be merged together (e.g. can this Piece be added to that Stack, can this Stack be added to that Deck, can these two Stacks be combined together into one).protected booleanA piece can be merged into a stack if it is merge-compatible with the first piece in the stack.protected booleancanStacksMerge(Stack s1, Stack s2) Stacks can merge if their component pieces can mergevoidclear()Clears the whole collection.Return all pieces in the collection, regardless of visibilityintprotected PieceCollectionGiven a game piece, returns the simple piece collection for the layer that it belongs inintReturn all currently-visible pieces in the collection as a read-only arrayprotected GamePiece[]getPieces(boolean includeDisabled) intintReturns the index of a piece.protected voidinitLayers(int layerCount) voidReposition a piece to the back of all others in the same visual layervoidReposition a piece to the front of all others in the same visual layervoidRemoves the piecevoidreset()voidrotate(boolean rotateUp) voidrotate(boolean rotateUp, boolean skipNullLayers) voidsetBottomLayer(int layer) voidsetLayerEnabled(int layer, boolean b) Enable/Disable layersvoidsetLayerEnabled(String layer, boolean b) Enable/Disable layersvoidtoggleLayerEnabled(int layer) Toggle for Enable/Disable of layersvoidtoggleLayerEnabled(String layer) Toggle for Enable/Disable of layers
-
Constructor Details
-
Collection
-
-
Method Details
-
getLayerOrder
-
setLayerOrder
-
getPropertyName
-
setPropertyName
-
getLayerForPiece
Gets the appropriate layer for the given piece (or Stack or Deck). Will call one of the dispatcher methods below, as appropriate:visitDeck(Deck),visitStack(Stack), orvisitDefault(GamePiece).- Overrides:
getLayerForPiecein classCompoundPieceCollection- Parameters:
p- Piece (possibly a Deck or Stack) to obtain layer for- Returns:
- visual layer
-
getLayerForName
Description copied from class:CompoundPieceCollectionDefault 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:
getLayerForNamein classCompoundPieceCollection- Parameters:
layer- the name of a layer- Returns:
- the index for the layer
-
getLayerNameForPiece
Description copied from class:CompoundPieceCollectionDefault 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:
getLayerNameForPiecein classCompoundPieceCollection- Parameters:
p- A game piece- Returns:
- the layer name it belongs in.
-
canPiecesMerge
Description copied from class:CompoundPieceCollectionTwo pieces can merge in the default case as long as neither is presently invisible and neither has a Does Not Stack (Hideable) trait.- Overrides:
canPiecesMergein classCompoundPieceCollection- Parameters:
p1- a piecep2- another piece- Returns:
- WonderTwin powers activate?
-
visitDeck
Decks are always displayed in the highest possible layer- Specified by:
visitDeckin interfaceDeckVisitor- Parameters:
d- Deck- Returns:
- layer - the highest possible one
-
visitDefault
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:
visitDefaultin interfacePieceVisitor- Parameters:
p- ordinary piece- Returns:
- layer index for this piece
-
visitStack
Stacks are first checked for the "topPiece()", but since this method actually hides from us pieces hidden from the currently active player by theHideable("Invisible") trait, we fall back on the Stack's own memory of what layer it has been in.- Specified by:
visitStackin interfacePieceVisitor- Parameters:
s- Stack to check layer- Returns:
- layer index
-