From dd21669842f1fef5dfe08247edbffa705ac25b7c Mon Sep 17 00:00:00 2001 From: Kenneth VanderLinde Date: Fri, 31 May 2024 11:15:25 -0700 Subject: [PATCH] Set follower token position based on derived path 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. --- .../client/ui/zone/renderer/ZoneRenderer.java | 38 +++++-------------- 1 file changed, 9 insertions(+), 29 deletions(-) diff --git a/src/main/java/net/rptools/maptool/client/ui/zone/renderer/ZoneRenderer.java b/src/main/java/net/rptools/maptool/client/ui/zone/renderer/ZoneRenderer.java index 4af61b4cf7..99c7a02dce 100644 --- a/src/main/java/net/rptools/maptool/client/ui/zone/renderer/ZoneRenderer.java +++ b/src/main/java/net/rptools/maptool/client/ui/zone/renderer/ZoneRenderer.java @@ -429,8 +429,6 @@ public void commitMoveSelectionSet(GUID keyTokenId) { List filteredTokens = new ArrayList(); moveTimer.stop("setup"); - int offsetX, offsetY; - moveTimer.start("eachtoken"); for (GUID tokenGUID : selectionSet) { Token token = zone.getToken(tokenGUID); @@ -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()) {