Skip to content

Commit

Permalink
Set follower token position based on derived path
Browse files Browse the repository at this point in the history
This is not visibly different from before, though it ensures that STG followers have their position snapped to the
grid, just as they would be had they been the leader.
  • Loading branch information
kwvanderlinde committed May 31, 2024
1 parent abc9f60 commit dd21669
Showing 1 changed file with 9 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -429,8 +429,6 @@ public void commitMoveSelectionSet(GUID keyTokenId) {
List<GUID> filteredTokens = new ArrayList<GUID>();
moveTimer.stop("setup");

int offsetX, offsetY;

moveTimer.start("eachtoken");
for (GUID tokenGUID : selectionSet) {
Token token = zone.getToken(tokenGUID);
Expand All @@ -440,39 +438,21 @@ public void commitMoveSelectionSet(GUID keyTokenId) {
continue;
}

if (token.isSnapToGrid()
&& (!AppPreferences.getTokensSnapWhileDragging() || !keyToken.isSnapToGrid())) {
// convert to Cellpoint and back to ensure token ends up at correct X and Y
CellPoint cellEnd =
zone.getGrid()
.convert(
new ZonePoint(
token.getX() + set.getOffsetX(), token.getY() + set.getOffsetY()));
ZonePoint pointEnd = cellEnd.convertToZonePoint(zone.getGrid());
offsetX = pointEnd.x - token.getX();
offsetY = pointEnd.y - token.getY();
} else {
offsetX = set.getOffsetX();
offsetY = set.getOffsetY();
}

/*
* Lee: the problem now is to keep the precise coordinate computations for unsnapped tokens following a snapped key token. The derived path in the following section contains rounded
* down values because the integer cell values were passed. If these were double in nature, the precision would be kept, but that would be too difficult to change at this stage...
*/
var tokenPath = path.derive(zone.getGrid(), keyToken, token);

token.setX(token.getX() + offsetX);
token.setY(token.getY() + offsetY);
token.setLastPath(tokenPath);

var lastPoint = tokenPath.getWayPointList().getLast();
var endPoint =
switch (lastPoint) {
case CellPoint cp -> zone.getGrid().convert(cp);
case ZonePoint zp -> zp;
};
token.setX(endPoint.x);
token.setY(endPoint.y);

flush(token);
MapTool.serverCommand().putToken(zone.getId(), token);

// No longer need this version
// Lee: redundant flush() already did this above
// replacementImageMap.remove(token);

// Only add certain tokens to the list to process in the move
// Macro function(s).
if (token.getLayer().supportsWalker() && token.isVisible()) {
Expand Down

0 comments on commit dd21669

Please sign in to comment.