Package VASSAL.build.module
Class BasicCommandEncoder
java.lang.Object
VASSAL.build.module.BasicCommandEncoder
- All Implemented Interfaces:
Buildable
,CommandEncoder
- Direct Known Subclasses:
BshCommandEncoder
Although it is the
CommandEncoder
which handles the basic commands: AddPiece
,
RemovePiece
, ChangePiece
, MovePiece
, this class is most commonly needed by
module designers who want to make custom "Traits" for game pieces because it contains createDecorator(java.lang.String, VASSAL.counters.GamePiece)
,
the BasicCommandEncoder.DecoratorFactory
for Traits, which are usually internally referred to as Decorators because they
are implemented using the Decorator Pattern.
If a module is to add its own custom game pieces, it will need to override the createDecorator(java.lang.String, VASSAL.counters.GamePiece)
method, and
use this pattern to create any custom Traits:
package MyCustomClasses; // Your package name here public class MyCustomCommandEncoder extends BasicCommandEncoder { public Decorator createDecorator(String type, GamePiece inner) { if (type.startsWith(MyCustomClass.ID)) { return new MyCustomClass(type, inner); } //... more custom traits, possibly // Now allow BasicCommandEncoder to run so that "normal" Traits process return super.createDecorator(type, inner); } }Then in the buildFile (XML) for the module, the VASSAL.build.module.BasicCommandEncoder entry is replaced with an entry for (in the example above):
MyCustomClasses.MyCustomCommandEncoder
The class files are placed in a MyCustomClasses
(package name) folder in the Zip structure of the VMOD file, and
At that point the new trait can be imported into a piece as MyCustomClasses.MyCustomClass
(package name followed by
class name).
Less often, the createBasic(java.lang.String)
or createPiece(java.lang.String)
methods could be overridden to allow instantiation of
custom GamePiece
classes.-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Factory interface for BasicPieces.static interface
Factory interface for Decorators See: Decorator Pattern, Factory Pattern -
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a buildable subcomponent.void
Adds this BasicCommandEncoder to its parent, which should be theGameModule
.void
Build a BasicCommandEncoder from the XML buildFile.protected GamePiece
createBasic
(String type) Create aGamePiece
instance that is not a Decorator ("Trait").createDecorator
(String type, GamePiece inner) createPiece
(String type) Creates a GamePiece instance from the given type information.Deserializes a string into a Basic Piece command (Add, Remove, Change, Move, and...Serializes a Basic Piece command (Add, Remove, Change, Move, and ...getBuildElement
(Document doc) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface VASSAL.build.Buildable
isMandatory, isMovable, isUnique
-
Field Details
-
ADD
- See Also:
-
REMOVE
- See Also:
-
CHANGE
- See Also:
-
MOVE
- See Also:
-
-
Constructor Details
-
BasicCommandEncoder
public BasicCommandEncoder()
-
-
Method Details
-
createDecorator
Creates aDecorator
instance - aGamePiece
"Trait". Modules which wish to provide their own custom classes should subclass BasicCommandEncoder and override this class. The override should check for and parse any definitions that match desired custom Traits(Decorators), and then use super to call this method for any unmatched definitions. Further documentation on creating custom traits appears in BasicCommandEncoder's own javadoc entry, or alternatively at the top of BasicCommandEncoder.java.- Parameters:
type
- the type of the Decorator ("Trait") to be created. Once created, the Decorator should return this value from itsDecorator.myGetType()
method.inner
- the inner trait/piece of the Decorator (the "innermost" member of a game piece will be aBasicPiece
; each successive Trait in the trait list presented in a piece'sPieceDefiner
dialog represents a sep "outward").
-
createBasic
Create aGamePiece
instance that is not a Decorator ("Trait"). In other words aBasicPiece
, aStack
, or aDeck
.- Parameters:
type
- the type of the GamePiece. The created piece should return this value from itsGamePiece.getType()
method.
-
createPiece
Creates a GamePiece instance from the given type information. Determines from the type whether the represented piece is aDecorator
("Trait") or not and forwards tocreateDecorator(java.lang.String, VASSAL.counters.GamePiece)
orcreateBasic(java.lang.String)
. This method should generally not need to be overridden. Instead, overridecreateDecorator(java.lang.String, VASSAL.counters.GamePiece)
orcreateBasic(java.lang.String)
- Parameters:
type
- definition string of the piece or trait to be created.
-
build
-
addTo
Adds this BasicCommandEncoder to its parent, which should be theGameModule
.- Specified by:
addTo
in interfaceBuildable
- Parameters:
parent
- theGameModule
-
add
-
getBuildElement
- Specified by:
getBuildElement
in interfaceBuildable
- Parameters:
doc
- An XML document- Returns:
- an XML element from which this component can be built
-
decode
Deserializes a string into a Basic Piece command (Add, Remove, Change, Move, and... Play Audio Clip!), readying it for execution.- Specified by:
decode
in interfaceCommandEncoder
- Parameters:
command
- string form of the command- Returns:
- Command object for command.
- See Also:
-
encode
Serializes a Basic Piece command (Add, Remove, Change, Move, and ... Play Audio Clip!) into a String, readying it for transmission to other clients.- Specified by:
encode
in interfaceCommandEncoder
- Parameters:
c
- Command to be serialized- Returns:
- String form of the command
- See Also:
-