Package VASSAL.counters
Class BasicPiece
java.lang.Object
VASSAL.search.AbstractImageFinder
VASSAL.counters.BasicPiece
- All Implemented Interfaces:
PropertyNameSource
,PropertySource
,EditablePiece
,GamePiece
,PropertyExporter
,StateMergeable
,TranslatablePiece
,PersistentPropertyContainer
,Auditable
,ImageSearchTarget
public class BasicPiece
extends AbstractImageFinder
implements TranslatablePiece, StateMergeable, PropertyNameSource, PersistentPropertyContainer, PropertyExporter
Basic class for representing a physical component of the game. Can be e.g. a counter, a card, or an overlay.
Note like traits, BasicPiece implements GamePiece (via TranslatablePiece), but UNLIKE traits it is NOT a
Decorator, and thus must be treated specially.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
protected Image
Deprecated, for removal: This API element is subject to removal in a future version.Replaced by #srcOp.protected Rectangle
protected String
protected ScaledImagePainter
static final String
static final String
static final String
Return information about the current location of the piece through getProperty(): LocationName - Current Location Name of piece as displayed in Chat Window CurrentX - Current X position CurrentY - Current Y position CurrentMap - Current Map name or "" if not on a map CurrentBoard - Current Board name or "" if not on a map CurrentZone - If the current map has a multi-zoned grid, then return the name of the Zone the piece is in, or "" if the piece is not in any zone, or not on a mapstatic final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
protected JPopupMenu
static Font
Deprecated, for removal: This API element is subject to removal in a future version.static final String
static final String
static final String
Fields inherited from interface VASSAL.counters.PropertyExporter
LOCALIZED_NAME
Fields inherited from interface VASSAL.i18n.TranslatablePiece
PREFIX
-
Constructor Summary
ConstructorDescriptionBasicPiece
(String type) creates a BasicPiece by passing complete type information -
Method Summary
Modifier and TypeMethodDescriptionvoid
SeeAbstractImageFinder
Adds our image (if any) to the list of imagesvoid
Draws the BasicPiece's image, if it has been setboolean
Support for a basic-name-only description introduced later, so this default retrofits it from the full description if an explicit one is not defined.A plain-English description of this type of trait/piece - includes data from fields where appropriategetGpId()
static Highlighter
Return a PieceI18nData object returning the I18n data about this GamePiece.getId()
Each GamePiece must have a unique String identifier.protected KeyCommand[]
And the translated name for this pieceReturns the localized text for a specified property if a translation is available, otherwise the non-localized version.Returns the localized text for a specified property if a translation is available, otherwise the non-localized version, but in both cases accounting for the unit's visibility (i.e.getMap()
getName()
The plain English name for this piecegetProperty
(Object key) Properties can be associated with a piece -- many may be game-specific, but others are standard, such as the LocationName property exposed by BasicPiece -- and can be read through this interface.getPublicProperty
(Object key) Properties (seegetProperty(java.lang.Object)
) visible in a masked (seeObscurable
) piece, even when the piece is masked.getShape()
getState()
getType()
The primary way for the piece or trait to receive events.void
mergeState
(String newState, String oldState) For BasicPiece, the "merge" of a new state simply involves copying in the new one in its entirety -- if any difference is detected.void
Sets the type information for this piece.protected Object
prefsValue
(String s) void
static void
void
Each GamePiece must have a unique String identifier.void
void
setPersistentProperty
(Object key, Object newValue) Setting a persistent property writes a property value into the piece (creating a new entry in the piece's persistent property table if the specified key does not yet exist in it).void
setPosition
(Point p) void
setProperty
(Object key, Object val) Properties can be associated with a piece -- many may be game-specific, but others are standard, such as the LocationName property exposed by BasicPiece -- and can be set through this interface.void
boolean
testEquals
(Object o) Test if this BasicPiece's Type and State are equal to another This method is intended to be used by Unit Tests to verify that a trait is unchanged after going through a process such as serialization/deserialization.toString()
Methods inherited from class VASSAL.search.AbstractImageFinder
addImageNamesRecursively, getAllImageNames, getLocalImageNames
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface VASSAL.script.expression.Auditable
getComponentName, getComponentTypeName
Methods inherited from interface VASSAL.counters.EditablePiece
checkTrueMoved, finishMove, finishMove, prepareMove
Methods inherited from interface VASSAL.counters.PropertyExporter
getProperties, getProperties
-
Field Details
-
ID
- See Also:
-
LOCATION_NAME
Return information about the current location of the piece through getProperty(): LocationName - Current Location Name of piece as displayed in Chat Window CurrentX - Current X position CurrentY - Current Y position CurrentMap - Current Map name or "" if not on a map CurrentBoard - Current Board name or "" if not on a map CurrentZone - If the current map has a multi-zoned grid, then return the name of the Zone the piece is in, or "" if the piece is not in any zone, or not on a map- See Also:
-
CURRENT_MAP
- See Also:
-
CURRENT_BOARD
- See Also:
-
CURRENT_ZONE
- See Also:
-
CURRENT_X
- See Also:
-
CURRENT_Y
- See Also:
-
OLD_LOCATION_NAME
- See Also:
-
OLD_MAP
- See Also:
-
OLD_BOARD
- See Also:
-
OLD_ZONE
- See Also:
-
OLD_X
- See Also:
-
OLD_Y
- See Also:
-
OLD_MAT
- See Also:
-
OLD_MAT_ID
- See Also:
-
OLD_MAT_PIECE_NAME
- See Also:
-
OLD_MAT_BASIC_NAME
- See Also:
-
OLD_MAT_OFFSET_X
- See Also:
-
OLD_MAT_OFFSET_Y
- See Also:
-
BASIC_NAME
- See Also:
-
PIECE_NAME
- See Also:
-
LOCALIZED_BASIC_NAME
- See Also:
-
LOCALIZED_PIECE_NAME
- See Also:
-
DECK_NAME
- See Also:
-
OLD_DECK_NAME
- See Also:
-
DECK_POSITION
- See Also:
-
CLICKED_X
- See Also:
-
CLICKED_Y
- See Also:
-
PIECE_UID
- See Also:
-
STACK_POS
- See Also:
-
STACK_SIZE
- See Also:
-
UNIQUE_ID
- See Also:
-
POPUP_MENU_FONT
Deprecated, for removal: This API element is subject to removal in a future version. -
popup
-
imageBounds
-
imagePainter
-
image
Deprecated, for removal: This API element is subject to removal in a future version.Replaced by #srcOp. -
imageName
-
-
Constructor Details
-
BasicPiece
public BasicPiece() -
BasicPiece
creates a BasicPiece by passing complete type information- Parameters:
type
- serialized type information (data about the piece which does not change during the course of a game) ready to be processed by aSequenceEncoder.Decoder
-
-
Method Details
-
mySetType
Sets the type information for this piece. SeeDecorator.myGetType()
- Specified by:
mySetType
in interfaceEditablePiece
- Parameters:
type
- a serialized configuration string to set the "type information" of this piece, which is information that doesn't change during the course of a single game (e.g. Image Files, Context Menu strings, etc). Typically ready to be processed e.g. by SequenceEncoder.decode()
-
getType
- Specified by:
getType
in interfaceGamePiece
- Returns:
- The "type information" of a piece or trait is information that does not change during the course of a game. Image file names, context menu strings, etc., all should be reflected in the type. The type information is returned serialized string form, ready to be decoded by a SequenceEncoder#decode.
- See Also:
-
setMap
-
getMap
-
getProperty
Properties can be associated with a piece -- many may be game-specific, but others are standard, such as the LocationName property exposed by BasicPiece -- and can be read through this interface. The properties may or may not need to be encoded in the piece'sgetState()
method. A request to getProperty() that reaches the BasicPiece will have already checked for such a property key being available from any outer Decorator/Trait in the stack. Upon reaching BasicPiece, the search hierarchy for a matching property now becomes: (1) Specific named properties supported by BasicPiece. These include BASIC_NAME, PIECE_NAME, LOCATION_NAME, CURRENT_MAP, CURRENT_BOARD, CURRENT_ZONE, CURRENT_X, CURRENT_Y. (2) "Scratchpad" properties - seesetProperty(java.lang.Object, java.lang.Object)
for full details, but these are highly temporary properties intended to remain valid only during the execution of a single key command. (3) Persistent properties - seesetPersistentProperty(java.lang.Object, java.lang.Object)
for full details, but they are stored in the piece and "game state robust" - saved during save/load, and propagated to other players' clients in a multiplayer game. (4) The values of any visible "Global Property" in a Vassal module, checking the Zone level first, then the map level, and finally the module level.
Thus, when using this interface a piece's own properties are preferred to those of "Global Properties", and those in turn are searched Zone-first then Map, then Module.- Specified by:
getProperty
in interfaceGamePiece
- Specified by:
getProperty
in interfacePropertySource
- Parameters:
key
- String key of property to be returned- Returns:
- Object containing new value of the specified property
-
getPublicProperty
Properties (seegetProperty(java.lang.Object)
) visible in a masked (seeObscurable
) piece, even when the piece is masked.- Parameters:
key
- String key of property to be returned.
-
getLocalizedProperty
Returns the localized text for a specified property if a translation is available, otherwise the non-localized version. Searches the same hierarchy of properties asgetProperty(java.lang.Object)
.- Specified by:
getLocalizedProperty
in interfacePropertySource
- Parameters:
key
- String key of property to be returned- Returns:
- localized text of property, if available, otherwise non-localized value
-
getLocalizedPublicProperty
Returns the localized text for a specified property if a translation is available, otherwise the non-localized version, but in both cases accounting for the unit's visibility (i.e. Mask/Obscurable
Traits). Searches the same hierarchy of properties asgetProperty(java.lang.Object)
.- Parameters:
key
- String key of property to be returned- Returns:
- Returns localized text of property, if available, otherwise non-localized value, accounting for Mask status.
-
setProperty
Properties can be associated with a piece -- many may be game-specific, but others are standard, such as the LocationName property exposed by BasicPiece -- and can be set through this interface. The properties may or may not need to be encoded in the piece'sgetState()
method. A setProperty() call which reaches BasicPiece will already have passed through all of the outer Decorator/Traits on the way in without finding one able to match the property.
NOTE: Properties outside the piece CANNOT be set by this method (e.g. Global Properties), even though they can be read bygetProperty(java.lang.Object)
-- in this the two methods are not perfect mirrors. This method ALSO does not set persistent properties (they can only be set by an explicit call tosetPersistentProperty(java.lang.Object, java.lang.Object)
).
BasicPiece does, however contain a "scratchpad" for temporary properties, and for any call to this method that does not match a known property (which is, currently, ANY call which reaches this method here in BasicPiece), a scratchpad property will be set. Scratchpad properties are NOT saved when the game is saved, and NO arrangement is made to pass their values to other players' machines. Thus they should only be used internally for highly temporary values during the execution of a single key command. Their one other use is to store the piece's Unique ID -- and although this value is obviously used over periods of time much longer than a single key command, this is possible because the value is immutable and is refreshed to the same value whenever the piece is re-created e.g. when loading a save.- Specified by:
setProperty
in interfaceGamePiece
- Parameters:
key
- String key of property to be changedval
- Object containing new value of the property
-
setPersistentProperty
Setting a persistent property writes a property value into the piece (creating a new entry in the piece's persistent property table if the specified key does not yet exist in it). Persistent properties are game-state-robust: they are saved/restored with saved games, and are passed viaCommand
to other players' clients in a multiplayer game. The persistent property value can then be read from the piece via e.g.getProperty(java.lang.Object)
. When reading back properties out of a piece, the piece's built-in properties are checked first, then scratchpad properties (seesetProperty(java.lang.Object, java.lang.Object)
), then external properties such as Global Properties. If only persistentProperties are to be searched, usegetPersistentProperty(java.lang.Object)
instead.
In practical terms, setPersistentProperty is used mainly to implement the "Old" properties of BasicPiece (e.g. "OldLocationName", "OldZone", "OldMap", "OldBoard", "OldX", "OldY"). A Persistent Property is indeed nearly identical withDynamicProperty
in storage/retrieval characteristics, and simply lacks the in-module interface for setting values, etc. Module Designers are thus recommended to stick with Dynamic Property traits for these functions.- Specified by:
setPersistentProperty
in interfacePersistentPropertyContainer
- Parameters:
key
- String key naming the persistent property to be set. If a corresponding persistent property does not exist it will be created.newValue
- New value for the persistent property- Returns:
- a
Command
object which, when passed to another player's client via logfile, server, or saved game, will allow the result of the "set" operation to be replicated.
-
getPersistentProperty
- Specified by:
getPersistentProperty
in interfacePersistentPropertyContainer
- Parameters:
key
- String key naming the persistent property whose value is to be returned.- Returns:
- the current value of a persistent property, or null if it doesn't exist.
-
prefsValue
-
draw
Draws the BasicPiece's image, if it has been set -
getKeyCommands
- Returns:
- the set of key commands that will populate the a BasicPiece's right-click menu.
This will normally be an empty array in the present age of the world, but the ability to contain a
clone and delete command is retained for compatibility with Modules Of Ancient Times.
In the case of BasicPiece, this method also keeps track of whether move up/down/to-top/to-bottom commands are enabled.
This method is chained from "outer" Decorator components of a larger logical game piece, in the process of generating
the complete list of key commands to build the right-click menu -- this process is originated by calling
getKeyCommands()
on the piece's outermost Decorator/Trait.
-
getPosition
- Specified by:
getPosition
in interfaceGamePiece
- Returns:
- piece's position on its map.
-
setPosition
- Specified by:
setPosition
in interfaceGamePiece
- Parameters:
p
- Sets the location of this piece on itsMap
-
getParent
-
setParent
-
boundingBox
- Specified by:
boundingBox
in interfaceGamePiece
- Returns:
- bounding box rectangle for BasicPiece's image, if an image has been specified.
-
getShape
- Specified by:
getShape
in interfaceGamePiece
- Returns:
- the Shape of this piece, for purposes of selecting it by clicking on it with the mouse. In the case
of BasicPiece, this is equivalent to the boundingBox of the BasicPiece image, if one exists. Note that the
shape should be defined in reference to the piece's location, which is ordinarily the center of the basic
image.
For pieces that need a non-rectangular click volume, add aNonRectangular
trait.
-
equals
- Parameters:
c
- GamePiece to check if equal to this one- Returns:
- Equality check with specified game piece
-
getRealName
- Returns:
- the name of this BasicPiece. This is the name typed by the module designer in the configuration box for the BasicPiece.
-
getName
Description copied from interface:GamePiece
The plain English name for this piece -
getRealLocalizedName
- Returns:
- the localized name of this BasicPiece. This is the translated version of the name typed by the module designer in the configuration box for the BasicPiece. It is used to fill the "BasicName" property if the search for it makes it all the way to this innermost piece.
-
getLocalizedName
Description copied from interface:GamePiece
And the translated name for this piece- Specified by:
getLocalizedName
in interfaceGamePiece
- Returns:
- the localized name of this GamePiece. It queries the BasicName property from the outermost piece inward, allowing a "Basic Name" trait to possibly override ours when the Piece Name is being queried.
-
keyEvent
The primary way for the piece or trait to receive events.KeyStroke
events are forward to this method if they are received while the piece is selected (or as the result of e.g. a Global Key Command being sent to the piece). The class implementing GamePiece can respond in any way it likes. Actual key presses by the player, selected items from the right-click Context Menu, keystrokes "applied on move" by a Map that the piece has just moved on, and Global Key Commands all send KeyStrokes (and NamedKeyStrokes) which are passed to pieces and traits through this interface.
In the case of BasicPiece, if a key command gets here, that means it has already been seen by any and all of its Traits (Decorator
s), as BasicPiece is the innermost member of the Decorator stack. The key events processed here by BasicPiece include the "move up"/"move down"/"move-to-top"/"move-to-bottom" stack-adjustment commands, along with legacy support for cloning and deleting.- Specified by:
keyEvent
in interfaceGamePiece
- Returns:
- a
Command
that, when executed, will make all changes to the game state (maps, pieces, other pieces, etc) to duplicate what the piece did in response to this event on another machine. Often aChangePiece
command, but for example if this keystroke caused the piece/trait to decide to fire off a Global Key Command, then the Command returned would include the entire results of that, appended as subcommands. - See Also:
-
getState
- Specified by:
getState
in interfaceGamePiece
- Returns:
- The "state information" is information that can change during
the course of a game. State information is saved when the game
is saved and is transferred between players on the server. For
example, the relative order of pieces in a stack is state
information, but whether the stack is expanded is not.
In the case of BasicPiece, the state information includes the current map, x/y position, the unique Game Piece ID, and the keys and values of any persistent properties (seesetPersistentProperty(java.lang.Object, java.lang.Object)
)
-
setState
- Specified by:
setState
in interfaceGamePiece
- Parameters:
s
- New state information serialized in string form, ready to be passed to a SequenceEncoder#decode. The "state information" is information that can change during the course of a game. State information is saved when the game is saved and is transferred between players on the server. For example, the relative order of pieces in a stack is state information, but whether the stack is expanded is not.
In the case of BasicPiece, the state information includes the current map, x/y position, the unique Game Piece ID, and the keys and values of any persistent properties (seesetPersistentProperty(java.lang.Object, java.lang.Object)
)
-
mergeState
For BasicPiece, the "merge" of a new state simply involves copying in the new one in its entirety -- if any difference is detected.- Specified by:
mergeState
in interfaceStateMergeable
- Parameters:
newState
- new serialized game state stringoldState
- old serialized game state string
-
getId
-
setId
-
getHighlighter
- Returns:
- the Highlighter instance for drawing selected pieces. Note that since this is a static method, all pieces in a module will always use the same Highlighter
-
setHighlighter
- Parameters:
h
- Set the Highlighter for all pieces
-
getDescription
Description copied from interface:EditablePiece
A plain-English description of this type of trait/piece - includes data from fields where appropriate- Specified by:
getDescription
in interfaceEditablePiece
- Returns:
- Description of what this kind of piece is. Appears in PieceDefiner list of traits.
-
getBaseDescription
Description copied from interface:EditablePiece
Support for a basic-name-only description introduced later, so this default retrofits it from the full description if an explicit one is not defined.- Specified by:
getBaseDescription
in interfaceEditablePiece
- Returns:
- Description of what this kind of piece is. Appears in PieceDefiner list of traits.
-
getGpId
- Returns:
- the unique gamepiece ID for this piece, as stored in the Property "scratchpad"
-
setGpId
- Parameters:
id
- stores the unique gamepiece ID for this piece into the Property "scratchpad"
-
getHelpFile
- Specified by:
getHelpFile
in interfaceEditablePiece
- Returns:
- the help file page for this type of piece.
-
getEditor
- Specified by:
getEditor
in interfaceEditablePiece
- Returns:
- The configurer (
PieceEditor
for the BasicPiece, which generates the dialog for editing the BasicPiece's type information in the Editor window.
-
testEquals
Test if this BasicPiece's Type and State are equal to another This method is intended to be used by Unit Tests to verify that a trait is unchanged after going through a process such as serialization/deserialization.- Parameters:
o
- Object to compare this Decorator to- Returns:
- true if the Class, type and state all match
-
toString
-
getI18nData
Description copied from interface:TranslatablePiece
Return a PieceI18nData object returning the I18n data about this GamePiece.- Specified by:
getI18nData
in interfaceTranslatablePiece
- Returns:
- Object encapsulating the internationalization data for the BasicPiece
-
getPropertyNames
- Specified by:
getPropertyNames
in interfacePropertyNameSource
- Returns:
- Property names exposed by the Trait or Piece. In the case of BasicPiece, there are quite a few, mainly dealing with past and present location.
-
addLocalImageNames
SeeAbstractImageFinder
Adds our image (if any) to the list of images- Specified by:
addLocalImageNames
in interfaceImageSearchTarget
- Overrides:
addLocalImageNames
in classAbstractImageFinder
- Parameters:
s
- Collection to add image names to
-