I'm making a custom trait as a java class (using these instructions here: http://www.vassalengine.org/wiki/Programming_Tutorial). I want to be able to access a property on the trait - it looks like the methods I would override are:
public List<String> getPropertyNames()
public Object getProperty(Object key)
I'm just not sure how to interpret the key. For example - I would like a Property named "FromLocation" - to access that I would be like this: $FromLocation$
So here's the code I tried to use for that:
@Override
public List<String> getPropertyNames() {
List<String> myProps = new ArrayList<String>();
myProps.add("FromLocation");
return myProps;
}
@Override
public Object getProperty(Object key) {
Object myValue = null;
if (key.equals("FromLocation")) {
myValue = this.getState();
}
else {
myValue = super.getProperty(key);
}
return myValue;
}
But it's not working. I suspect it is the "key.equals" condition in "getProperty". Does anyone have an example of an Imported Class where they have exposed properties?