[messages] [Module Design] Custom java class that deals with GamePieces

Brent Easton b.easton at exemail.com.au
Wed Feb 1 01:37:31 CET 2017


Yes, you do have access to the same methods. I'm just saying there isn't
one simple method that does it everything you need in a simple easy
call. To find out what those methods are and how to call them, I am
suggesting you look at a piece of code that already does it.

The class that does the drag and drop from the Game Palette to the board
is PieceMover, but it is hideously complex and I would not suggest
starting there.

The two classes I suggested more or less do everything you need to do.
GpIDChecker shows you how to locate all of the pieces in the GamePiece
palette, how to find their GpId's and how to create a new piece from a
definition with all of the prototypes expanded.

Since you are only concerned about GamePiece palette entries (PieceSlot)
and not piece definitions in Markers, you can simplify things. Once you
have found the PieceSlot you need with the GpID you are after, you will
need to do something like this:

 PieceSlot slot = findSlot (gpid);
 GamePiece piece = slot.getExpandedPiece();
 Point pos = new Point (100, 100);
 Command place = map.placeOrMerge(newPiece, pos);

then execute the command.

To find all PieceSlots in the module, use something like this:

PieceSlot findSlot (String myGpId) {
      PieceSlot mySlot = null;
      for (PieceSlot slot :
GameModule.getGameModule().getAllDescendantComponentsOf(PieceSlot.class))
{
        if (slot.getGpId().equals(myGpId)) {
            mySlot = slot;
            break;
        }
      }
     return slot;
}


Hope this helps.
Rgds.

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


More information about the messages mailing list