Making sure a custom Command class makes it into a log

Module in development: Star Wars X-Wing the Miniatures Game

I have a Game Piece (a movement dial for those familiar with the game) which behaves great while a game is being played out between the players, both for its owner who manipulates it and for its opponent (or any observers watching the game). What’s not working at the moment is that I can’t seem to grasp how to properly send that command to a logfile if anyone attempts to record the game.

Help me sort out this procedure- are any steps redundant? Are there missing steps?

  1. The dial Game Piece has a custom Decorator/trait class that extends Decorator and implements EditablePiece, Serializable which listens to keyEvents (my point of entry that starts up this whole thing

  2. I construct a ChangeTracker object to get the current state of the dial Game Piece before anything happens

  3. A specific keystroke triggers the construction of a custom Command. I have an inner static class for CommandEncoder that itself has the encoder and decoder methods to pass through sufficient information in order to change a few (3 total) properties of the dial Game Piece.

  4. I execute() the Command right away

  5. I get a new Command from my ChangeTracker via .getChangeCommand(), since I’ve altered 3 properties inside my GamePiece (a Dynamic Property’s value + which layer level is shown in a Layer decorator + which image is used within another Layer decorator).

  6. I create a Command chain with my dial Game Piece’s original keyEvent(stroke) Command which triggered everything + my custom Command + the getChangeCommand() I fished out. I use GameModule.getGameModule().sendAndLog(commandChain).

  7. finally, the keyEvent method ends and I return the commandChain

The behavior that happens:

While playing, both players see everything happen.

If I’m the owner of the dial Game Piece and I’m recording a game: the playback of the logfile will only show 1 of the 3 properties change (the layer # that becomes the current visible one). I haven’t tested the dynamic property value yet but the other layer decorator does not change the image of its visible layer.

I’m slowly possibly coming to the conclusion that I can’t record a command which makes use of setType() for a layer decorator (ie change the image it uses for a specific layer, layer #1 in my case). I can only log property changes, or change which layer is displayed.

I can do it fine during runtime, but the log recorder will simply refuse to record it.

Things you can safely pass to everyone with an encoded Command:

keyEvent
placeAndMerge (a Game Piece)
(a Change Tracker).getChangeCommand
(a decorator).setValue()
(a decorator).setType()

Thing that will be recorded in a logfile:

keyEvent
placeAndMerge (a Game Piece)
(a Change Tracker).getChangeCommand
(a decorator).setValue()

You are correct. Vassal will not interpret a change to the internal type of a unit (via setType()) as a command that needs to be sent to a log file or other players.

The ‘type’ of a unit is configured in the module editor and cannot generally be changed by players during play, so no standard process in Vassal will include a change to ‘type’ in a log file.

The ‘state’ of a unit changes continuously during play and it is changes to ‘state’ that are communicated.

You could potentially copy the code of the Embellishment class to create your own custom Layer command that logs ‘type’ changes. But I would strongly advise that you modify your design to just use the standard Layer traits. There should be no need to replace the image a Layer displays.