custom imported traits

It seems easy enough to import custom class files as attributes, but it doesn’t seem possible to import custom piece traits. If you set the ID to something unique, VASSAL doesn’t seem to be able to find the class that’s associated with it. Nowhere in the buildFile is there a reference to the imported trait class.

Am I missing something? Have custom traits been used in the past?

The editor imports the trait class without problem and I can even use the custom trait editor, but the buildFile knows nothing about the imported class.

  • M.

Hi Michael,

You need to create a custom CommandEncoder class like this:

[code]
package script;
import VASSAL.build.module.BasicCommandEncoder;
import VASSAL.counters.Decorator;
import VASSAL.counters.GamePiece;

public class BshCommandEncoder extends BasicCommandEncoder {

public Decorator createDecorator(String type, GamePiece inner) {
if (type.startsWith(CalculatedProperty.ID)) {
return new CalculatedProperty(type, inner);
}
return super.createDecorator(type, inner);
}
}[/code]

and import it into your module also. In this case, I import script.BshCommandEncoder and it adds support for my custom trait CalculatedProperty.

Regards,
Brent.

Hi Michael,

Yes, your right, you can’t import it, I usually edit it directly into the buildfile like so:

<?xml version="1.0" encoding="UTF-8"?>

<VASSAL.launch.BasicModule VassalVersion=“3.1.0-beta1” description="" name=“Unnamed module” nextPieceSlotId=“5” version=“0.0”>
<VASSAL.build.module.BasicCommandEncoder/>
<bsh.BshCommandEncoder/>
etc.

You should also be able to do something like

GameModule.getGameModule.addCommandEncoder(new BshCommandEncoder()));

in the initialisation of another Configurable custom component if you have one, but I usually just edit the buildFile.

Regards,
Brent.


Brent Easton
Analyst/Programmer
University of Western Sydney
Email: b.easton@uws.edu.au


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)

Hi Michael,

I’m not sure what the problem is. I have used this technique to add custom traits to 5+ modules without problem.

Hmm, I do have a vague memory that after a certain vassal version, I had to do something different. Try removing the reference in the buildfile to <Vassal.build.module.BasicCommandEncoder> and replace it with your custom Command encoder. Since you custom command encoder extends BasicCommandEncoder, you only need the one.

The sequence should come through GameModule.getGameModule().decode() . This happens only when a piece is created, which in general will not happen when a module is loaded (only when loading a saved game, pulling a piece of a palette etc.). Have a look at the saved gamed loader in GameState which does

GameModule.[i]getGameModule/i.decode(new String(b, “UTF-8”).trim());
Regards,
Brent.

*********** REPLY SEPARATOR ***********

On 9/07/2008 at 10:51 PM Michael Kiefte wrote:

Post generated using Mail2Forum (mail2forum.com)

Michael,

I think it has to do with changes Rodney made at my request to ensure that every single Decorator that gets created does so through a single central point. Previously, traits like Replace used to go off and create their own BasicPiece’s by calling low-level stuff directly. I had over-written BasicPiece with my own version that exposed some additional properties and I needed every BasicPiece created to happen in one central over-rideable place.

We could probably do some sort of Registration component that allows you to enter the class name of a new BasicCommandEncoder. Also the class names of new Decorator’s that you want to appear in the PieceDefiner list.

By the way, the one big lessson I learned about custom Decorators is don’t create them by subclassing an existing decorator. Instead, take a copy of the source of the existing decoraror, rename it and modify it to do what you want. I have been burned time and gain by innocuous source changes in Decorators that have blown my custom code out of the water.

Regards,
Brent.


Messages mailing list
Messages@forums.vassalengine.org
forums.vassalengine.org/mailman/ … engine.org

Post generated using Mail2Forum (mail2forum.com)