[messages] Edit: Re: [Module General Discussion] Why is my custom trait being listed as a "Marker" trait?

Joe12 j.sheppard88 at gmail.com
Tue Jun 7 18:02:22 CEST 2016


[This message has been edited.]

Hi,

After I've imported my trait into my piece its correctly listed as a
"Research Action Button" trait in the piece's list of current traits but
then when I save my module, close & then next open the module editor
this trait is listed as a "Marker" trait in the piece's list of traits.
And when I modify the simplest code I could give this trait (to test
this problem) to actually make it do something in game it fails to work.

I've tried used the example Magnifier trait from the programming
tutorial's ZapWars zip and it has the same problem.

My trait:

Code:

public class ResearchActionButton extends Decorator implements
EditablePiece
{
	public final static String ID = "RESEARCHED_ACTION_BUTTON";

	public ResearchActionButton(String type, GamePiece inner)
	{
		mySetType(type);
		setInner(inner);
	}

	public ResearchActionButton()
	{
		this(ID, null);
	}

	public String myGetType()
	{
		return ID;
	}

	public String getDescription()
	{
		return "Research Action Button";
	}

	public void draw(Graphics g, int x, int y, Component obs, double zoom)
	{
		piece.draw(g, x, y, obs, zoom);
	}

	public Rectangle boundingBox()
	{
		return piece.boundingBox();
	}

	public Shape getShape()
	{
		return piece.getShape();
	}

	public String getName()
	{
		return piece.getName();
	}

	@Override
	public void mySetState(String newState)
	{

	}

	@Override
	public String myGetState()
	{
		return "";
	}

	@Override
	protected KeyCommand[] myGetKeyCommands()
	{
		return new KeyCommand[0];
	}

	@Override
	public Command myKeyEvent(KeyStroke stroke)
	{
		return null;
	}

	public void mySetType(String type)
	{

	}

	public HelpFile getHelpFile()
	{
		return null;
	}

	public PieceEditor getEditor()
	{
		return new SimplePieceEditor(this);
	}
}




My counter factory:

Code:
public class MyCounterFactory extends BasicCommandEncoder
{
	public Decorator createDecorator(String type, GamePiece inner)
	{
		Decorator piece = null;

		if (type.startsWith(Magnifier.ID))
		{
			piece = new Magnifier(type, inner);
		}

		else if (type.startsWith(ResearchActionButton.ID))
		{
			piece = new ResearchActionButton(type, inner);
		}

		else
		{
			piece = super.createDecorator(type, inner);
		}

		return piece;
	}
}



_______________________________________________
Read this topic online here:
http://www.vassalengine.org/forum/viewtopic.php?p=51427#p51427


More information about the messages mailing list