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.
GamePiece
s -- 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
Modifier and TypeFieldDescriptionprotected int
protected boolean[]
protected SimplePieceCollection[]
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a piece to the overall collection, by adding it to the simple collection for the layer it belongs in.boolean
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).protected boolean
canPiecesMerge
(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 boolean
A piece can be merged into a stack if it is merge-compatible with the first piece in the stack.protected boolean
canStacksMerge
(Stack s1, Stack s2) Stacks can merge if their component pieces can mergevoid
clear()
Clears the whole collection.Return all pieces in the collection, regardless of visibilityint
protected PieceCollection
Given a game piece, returns the simple piece collection for the layer that it belongs inint
int
getLayerForName
(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.int
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.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) int
int
Returns the index of a piece.protected void
initLayers
(int layerCount) void
Reposition a piece to the back of all others in the same visual layervoid
Reposition a piece to the front of all others in the same visual layervoid
Removes the piecevoid
reset()
void
rotate
(boolean rotateUp) void
rotate
(boolean rotateUp, boolean skipNullLayers) void
setBottomLayer
(int layer) void
setLayerEnabled
(int layer, boolean b) Enable/Disable layersvoid
setLayerEnabled
(String layer, boolean b) Enable/Disable layersvoid
toggleLayerEnabled
(int layer) Toggle for Enable/Disable of layersvoid
toggleLayerEnabled
(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:
add
in interfacePieceCollection
- Parameters:
p
- Game piece to add
-
clear
-
getPieces
Description copied from interface:PieceCollection
Return all currently-visible pieces in the collection as a read-only array- Specified by:
getPieces
in 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:PieceCollection
Return all pieces in the collection, regardless of visibility- Specified by:
getAllPieces
in interfacePieceCollection
- Returns:
- a list of all pieces in any layer of this collection.
-
indexOf
Description copied from interface:PieceCollection
Returns 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:
indexOf
in interfacePieceCollection
- Parameters:
p
- A game piece- Returns:
- A unique index for the game piece within the overall collection.
-
remove
Description copied from interface:PieceCollection
Removes the piece- Specified by:
remove
in interfacePieceCollection
- Parameters:
p
- piece to remove from the collection
-
moveToBack
Description copied from interface:PieceCollection
Reposition a piece to the back of all others in the same visual layer- Specified by:
moveToBack
in interfacePieceCollection
- Parameters:
p
- piece to move to the visual back of its layer
-
moveToFront
Description copied from interface:PieceCollection
Reposition a piece to the front of all others in the same visual layer- Specified by:
moveToFront
in 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 aHideable
trait, and not having a "Does Not Stack" trait (Immobilized
). When extending the class additional requirements can be added (e.g.LayeredPieceCollection
requires pieces to be in the same visual layer in order to form a stack).- Specified by:
canMerge
in 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()
-