Package VASSAL.build.module.map
Class CompoundPieceCollection
java.lang.Object
VASSAL.build.module.map.CompoundPieceCollection
- All Implemented Interfaces:
PieceCollection
- Direct Known Subclasses:
DefaultPieceCollection,LayeredPieceCollection.Collection
Base class for PieceCollection implementation that organizes
Maintains, usually on behalf of a Map, lists of all the pieces in each of several layers, along with a set of "enabled" flags marking which layers are disabled/hidden and which are enabled/visible. When a piece is added to the overall collection, its appropriate layer is determined and it is added to the list of pieces on that layer.
GamePieces -- a category which in this case
also includes Decks and Stacks, in addition to ordinary pieces -- into distinct visual layers. The layers are drawn
in order of their index, i.e. layer 0 is drawn first and thus appears "on the bottom", as higher layers are drawn
over top of it.
Maintains, usually on behalf of a Map, lists of all the pieces in each of several layers, along with a set of "enabled" flags marking which layers are disabled/hidden and which are enabled/visible. When a piece is added to the overall collection, its appropriate layer is determined and it is added to the list of pieces on that layer.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected boolean[]protected SimplePieceCollection[] -
Constructor Summary
Constructors -
Method Summary
Modifier 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.protected 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.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 inintintgetLayerForName(String layerName) 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.intDefault 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 an index.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.Return 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
-
Field Details
-
layers
-
bottomLayer
protected int bottomLayer -
enabled
protected boolean[] enabled
-
-
Constructor Details
-
CompoundPieceCollection
protected CompoundPieceCollection(int layerCount)
-
-
Method Details
-
initLayers
protected void initLayers(int layerCount) -
getLayerForPiece
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 an index.- Parameters:
p- A game piece- Returns:
- Index for the visual layer the piece should be drawn with.
-
getLayerNameForPiece
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.- Parameters:
p- A game piece- Returns:
- the layer name it belongs in.
-
getLayerForName
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.- Parameters:
layerName- the name of a layer- Returns:
- the index for the layer
-
getCollectionForPiece
Given a game piece, returns the simple piece collection for the layer that it belongs in- Parameters:
p- A game piece- Returns:
- the piece collection for the layer that it belongs in
-
add
Adds a piece to the overall collection, by adding it to the simple collection for the layer it belongs in.- Specified by:
addin interfacePieceCollection- Parameters:
p- Game piece to add
-
clear
-
getPieces
Description copied from interface:PieceCollectionReturn all currently-visible pieces in the collection as a read-only array- Specified by:
getPiecesin interfacePieceCollection
-
getPieces
- Parameters:
includeDisabled- true if pieces in disabled layers should be included- Returns:
- A list of all pieces in this overall collection, or all that are in "enabled" layers, depending on the parameter
-
getAllPieces
Description copied from interface:PieceCollectionReturn all pieces in the collection, regardless of visibility- Specified by:
getAllPiecesin interfacePieceCollection- Returns:
- a list of all pieces in any layer of this collection.
-
indexOf
Description copied from interface:PieceCollectionReturns the index of a piece. When painting the map, pieces are drawn in order of index -- lowest index drawn first and therefore appearing "below" later pieces which are drawn on top of it.- Specified by:
indexOfin interfacePieceCollection- Parameters:
p- A game piece- Returns:
- A unique index for the game piece within the overall collection.
-
remove
Description copied from interface:PieceCollectionRemoves the piece- Specified by:
removein interfacePieceCollection- Parameters:
p- piece to remove from the collection
-
moveToBack
Description copied from interface:PieceCollectionReposition a piece to the back of all others in the same visual layer- Specified by:
moveToBackin interfacePieceCollection- Parameters:
p- piece to move to the visual back of its layer
-
moveToFront
Description copied from interface:PieceCollectionReposition a piece to the front of all others in the same visual layer- Specified by:
moveToFrontin interfacePieceCollection- Parameters:
p- piece to move to visual front of its layer
-
canMerge
Used 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). Default preconditions for merging into a Stack include not being Invisible due to aHideabletrait, and not having a "Does Not Stack" trait (Immobilized). When extending the class additional requirements can be added (e.g.LayeredPieceCollectionrequires pieces to be in the same visual layer in order to form a stack).- Specified by:
canMergein interfacePieceCollection- Parameters:
p1- one piece/stack/deckp2- another piece/stack/deck- Returns:
- Whether the two pieces are legal to merge
-
canStacksMerge
-
canStackAndPieceMerge
-
canPiecesMerge
-
getLayerCount
public int getLayerCount()- Returns:
- the number of visual layers in this collection
-
setBottomLayer
public void setBottomLayer(int layer) -
getBottomLayer
public int getBottomLayer()- Returns:
- current bottom layer
-
getTopLayer
public int getTopLayer()- Returns:
- the current top layer
-
rotate
public void rotate(boolean rotateUp, boolean skipNullLayers) -
rotate
public void rotate(boolean rotateUp) -
setLayerEnabled
public void setLayerEnabled(int layer, boolean b) Enable/Disable layers- Parameters:
layer- layer indexb- true to enable the layer, false to disable
-
toggleLayerEnabled
public void toggleLayerEnabled(int layer) Toggle for Enable/Disable of layers- Parameters:
layer- layer index
-
setLayerEnabled
Enable/Disable layers- Parameters:
layer- layer nameb- true to enable the layer, false to disable
-
toggleLayerEnabled
Toggle for Enable/Disable of layers- Parameters:
layer- layer name
-
reset
public void reset()
-