Skip to content

Commit

Permalink
Merge pull request #5019 from kwvanderlinde/bugfix/5018-transfer-vbl-…
Browse files Browse the repository at this point in the history
…desync

Fix various issues with transfering map topology to and from token topology
  • Loading branch information
cwisniew authored Oct 24, 2024
2 parents c5c1f62 + b96eb6f commit 3163585
Show file tree
Hide file tree
Showing 21 changed files with 157 additions and 382 deletions.
30 changes: 7 additions & 23 deletions src/main/java/net/rptools/maptool/client/ClientMessageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void handleMessage(String id, byte[] message) {
log.debug("{} got: {}", id, msgType);

switch (msgType) {
case ADD_TOPOLOGY_MSG -> handle(msg.getAddTopologyMsg());
case UPDATE_TOPOLOGY_MSG -> handle(msg.getUpdateTopologyMsg());
case BOOT_PLAYER_MSG -> handle(msg.getBootPlayerMsg());
case CHANGE_ZONE_DISPLAY_NAME_MSG -> handle(msg.getChangeZoneDisplayNameMsg());
case CLEAR_ALL_DRAWINGS_MSG -> handle(msg.getClearAllDrawingsMsg());
Expand All @@ -128,7 +128,6 @@ public void handleMessage(String id, byte[] message) {
case REMOVE_LABEL_MSG -> handle(msg.getRemoveLabelMsg());
case REMOVE_TOKEN_MSG -> handle(msg.getRemoveTokenMsg());
case REMOVE_TOKENS_MSG -> handle(msg.getRemoveTokensMsg());
case REMOVE_TOPOLOGY_MSG -> handle(msg.getRemoveTopologyMsg());
case REMOVE_ZONE_MSG -> handle(msg.getRemoveZoneMsg());
case RENAME_ZONE_MSG -> handle(msg.getRenameZoneMsg());
case RESTORE_ZONE_VIEW_MSG -> handle(msg.getRestoreZoneViewMsg());
Expand Down Expand Up @@ -701,20 +700,6 @@ private void handle(RemoveZoneMsg msg) {
});
}

private void handle(RemoveTopologyMsg msg) {
EventQueue.invokeLater(
() -> {
var zoneGUID = GUID.valueOf(msg.getZoneGuid());
var area = Mapper.map(msg.getArea());
var topologyType = Zone.TopologyType.valueOf(msg.getType().name());

var zone = client.getCampaign().getZone(zoneGUID);
zone.removeTopology(area, topologyType);

MapTool.getFrame().getZoneRenderer(zoneGUID).repaint();
});
}

private void handle(RemoveTokensMsg msg) {
EventQueue.invokeLater(
() -> {
Expand Down Expand Up @@ -1018,17 +1003,16 @@ private void handle(ChangeZoneDisplayNameMsg changeZoneDisplayNameMsg) {
});
}

private void handle(AddTopologyMsg addTopologyMsg) {
private void handle(UpdateTopologyMsg updateTopologyMsg) {
EventQueue.invokeLater(
() -> {
var zoneGUID = GUID.valueOf(addTopologyMsg.getZoneGuid());
var area = Mapper.map(addTopologyMsg.getArea());
var topologyType = Zone.TopologyType.valueOf(addTopologyMsg.getType().name());
var zoneGUID = GUID.valueOf(updateTopologyMsg.getZoneGuid());
var area = Mapper.map(updateTopologyMsg.getArea());
var erase = updateTopologyMsg.getErase();
var topologyType = Zone.TopologyType.valueOf(updateTopologyMsg.getType().name());

var zone = client.getCampaign().getZone(zoneGUID);
zone.addTopology(area, topologyType);

MapTool.getFrame().getZoneRenderer(zoneGUID).repaint();
zone.updateTopology(area, erase, topologyType);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import net.rptools.lib.MD5Key;
import net.rptools.maptool.client.functions.ExecFunction;
import net.rptools.maptool.client.functions.MacroLinkFunction;
Expand Down Expand Up @@ -392,23 +393,18 @@ public void toggleTokenMoveWaypoint(GUID zoneGUID, GUID tokenGUID, ZonePoint cp)
makeServerCall(Message.newBuilder().setToggleTokenMoveWaypointMsg(msg).build());
}

public void addTopology(GUID zoneGUID, Area area, Zone.TopologyType topologyType) {
var msg =
AddTopologyMsg.newBuilder()
.setZoneGuid(zoneGUID.toString())
.setType(TopologyTypeDto.valueOf(topologyType.name()))
.setArea(Mapper.map(area));

makeServerCall(Message.newBuilder().setAddTopologyMsg(msg).build());
}

public void removeTopology(GUID zoneGUID, Area area, Zone.TopologyType topologyType) {
@Override
public void updateTopology(Zone zone, Area area, boolean erase, Zone.TopologyType topologyType) {
var msg =
RemoveTopologyMsg.newBuilder()
.setZoneGuid(zoneGUID.toString())
UpdateTopologyMsg.newBuilder()
.setZoneGuid(zone.getId().toString())
.setArea(Mapper.map(area))
.setErase(erase)
.setType(TopologyTypeDto.valueOf(topologyType.name()));
makeServerCall(Message.newBuilder().setRemoveTopologyMsg(msg).build());

// Update locally as well.
zone.updateTopology(area, erase, topologyType);
makeServerCall(Message.newBuilder().setUpdateTopologyMsg(msg).build());
}

public void exposePCArea(GUID zoneGUID) {
Expand Down Expand Up @@ -623,6 +619,20 @@ public void removeData(String type, String namespace, String name) {
makeServerCall(Message.newBuilder().setRemoveDataMsg(msg).build());
}

@Override
public void setTokenTopology(Token token, @Nullable Area area, Zone.TopologyType topologyType) {
if (area == null) {
// Will be converted back to null on the other end.
area = new Area();
}

updateTokenProperty(
token,
Token.Update.setTopology,
TokenPropertyValueDto.newBuilder().setTopologyType(topologyType.name()).build(),
TokenPropertyValueDto.newBuilder().setArea(Mapper.map(area)).build());
}

@Override
public void updateTokenProperty(Token token, Token.Update update, int value) {
updateTokenProperty(
Expand Down Expand Up @@ -757,16 +767,6 @@ public void updateTokenProperty(
TokenPropertyValueDto.newBuilder().setIntValue(value3).build());
}

@Override
public void updateTokenProperty(
Token token, Token.Update update, Zone.TopologyType topologyType, Area area) {
updateTokenProperty(
token,
update,
TokenPropertyValueDto.newBuilder().setTopologyType(topologyType.name()).build(),
TokenPropertyValueDto.newBuilder().setArea(Mapper.map(area)).build());
}

@Override
public void updateTokenProperty(Token token, Token.Update update, String value1, boolean value2) {
updateTokenProperty(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private void childEvaluateDrawEraseTopology(String functionName, List<Object> pa
default -> null;
};
if (newArea != null) {
TokenVBL.renderTopology(renderer, newArea, erase, topologyType);
MapTool.serverCommand().updateTopology(renderer.getZone(), newArea, erase, topologyType);
}
}
}
Expand Down Expand Up @@ -515,16 +515,14 @@ private int childEvaluateSetTokenTopology(
}
}
// Replace with new topology
MapTool.serverCommand()
.updateTokenProperty(token, Token.Update.setTopology, topologyType, tokenTopology);
MapTool.serverCommand().setTokenTopology(token, tokenTopology, topologyType);

return results;
}

private void childEvaluateTransferTopology(
VariableResolver resolver, String functionName, List<Object> parameters)
throws ParserException {
ZoneRenderer renderer = MapTool.getFrame().getCurrentZoneRenderer();
Token token = null;

Zone.TopologyType topologyType;
Expand Down Expand Up @@ -594,18 +592,23 @@ private void childEvaluateTransferTopology(
}
}

Zone zone = MapTool.getFrame().getCurrentZoneRenderer().getZone();
if (topologyFromToken) {
TokenVBL.renderTopology(
renderer, token.getTransformedTopology(topologyType), false, topologyType);
var newMapTopology = token.getTransformedTopology(topologyType);
if (newMapTopology != null) {
MapTool.serverCommand().updateTopology(zone, newMapTopology, false, topologyType);
}
if (delete) {
token.setTopology(topologyType, null);
MapTool.serverCommand().setTokenTopology(token, null, topologyType);
}
} else {
Area topology = TokenVBL.getTopology_underToken(renderer, token, topologyType);
token.setTopology(
topologyType, TokenVBL.getMapTopology_transformed(renderer, token, topologyType));
Area topology = TokenVBL.getTopology_underToken(zone, token, topologyType);

MapTool.serverCommand()
.setTokenTopology(
token, TokenVBL.transformTopology_toToken(zone, token, topology), topologyType);
if (delete) {
TokenVBL.renderTopology(renderer, topology, true, topologyType);
MapTool.serverCommand().updateTopology(zone, topology, true, topologyType);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,9 @@ public void mousePressed(MouseEvent e) {
GraphicsUtil.createLine(1, new Point2D.Double(x1, y1), new Point2D.Double(x2, y2));
area.add(
GraphicsUtil.createLine(1, new Point2D.Double(x1, y2), new Point2D.Double(x2, y1)));
MapTool.serverCommand()
.updateTopology(getZone(), area, isEraser(e), getZone().getTopologyTypes());

if (isEraser(e)) {
getZone().removeTopology(area);
MapTool.serverCommand()
.removeTopology(getZone().getId(), area, getZone().getTopologyTypes());
} else {
getZone().addTopology(area);
MapTool.serverCommand()
.addTopology(getZone().getId(), area, getZone().getTopologyTypes());
}
renderer.repaint();
// TODO: send this to the server
cross = null;
}
setIsEraser(isEraser(e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,8 @@ public void mousePressed(MouseEvent e) {
return;
}
Area area = new ShapeDrawable(diamond, false).getArea(getZone());
if (isEraser(e)) {
getZone().removeTopology(area);
MapTool.serverCommand()
.removeTopology(getZone().getId(), area, getZone().getTopologyTypes());
} else {
getZone().addTopology(area);
MapTool.serverCommand()
.addTopology(getZone().getId(), area, getZone().getTopologyTypes());
}
renderer.repaint();
// TODO: send this to the server

MapTool.serverCommand()
.updateTopology(getZone(), area, isEraser(e), getZone().getTopologyTypes());
diamond = null;
}
setIsEraser(isEraser(e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,8 @@ public void mousePressed(MouseEvent e) {
return;
}
Area area = new Area(diamond);
if (isEraser(e)) {
getZone().removeTopology(area);
MapTool.serverCommand()
.removeTopology(getZone().getId(), area, getZone().getTopologyTypes());
} else {
getZone().addTopology(area);
MapTool.serverCommand()
.addTopology(getZone().getId(), area, getZone().getTopologyTypes());
}
renderer.repaint();
// TODO: send this to the server

MapTool.serverCommand()
.updateTopology(getZone(), area, isEraser(e), getZone().getTopologyTypes());
diamond = null;
}
setIsEraser(isEraser(e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,8 @@ public void mousePressed(MouseEvent e) {
area.subtract(innerArea);
}

if (isEraser(e)) {
getZone().removeTopology(area);
MapTool.serverCommand()
.removeTopology(getZone().getId(), area, getZone().getTopologyTypes());
} else {
getZone().addTopology(area);
MapTool.serverCommand()
.addTopology(getZone().getId(), area, getZone().getTopologyTypes());
}
renderer.repaint();

MapTool.serverCommand()
.updateTopology(getZone(), area, isEraser(e), getZone().getTopologyTypes());
oval = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,8 @@ public void mousePressed(MouseEvent e) {
new Area(new java.awt.Rectangle(x1 + 1, y1 + 1, x2 - x1 - 2, y2 - y1 - 2));
area.subtract(innerArea);
}
if (isEraser(e)) {
getZone().removeTopology(area);
MapTool.serverCommand()
.removeTopology(getZone().getId(), area, getZone().getTopologyTypes());
} else {
getZone().addTopology(area);
MapTool.serverCommand()
.addTopology(getZone().getId(), area, getZone().getTopologyTypes());
}
renderer.repaint();
// TODO: send this to the server
MapTool.serverCommand()
.updateTopology(getZone(), area, isEraser(e), getZone().getTopologyTypes());
rectangle = null;
}
setIsEraser(isEraser(e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,8 @@ public void mousePressed(MouseEvent e) {
oval.getEndPoint().y,
10);

if (isEraser(e)) {
getZone().removeTopology(area);
MapTool.serverCommand()
.removeTopology(getZone().getId(), area, getZone().getTopologyTypes());
} else {
getZone().addTopology(area);
MapTool.serverCommand()
.addTopology(getZone().getId(), area, getZone().getTopologyTypes());
}
renderer.repaint();
MapTool.serverCommand()
.updateTopology(getZone(), area, isEraser(e), getZone().getTopologyTypes());
oval = null;
}
setIsEraser(isEraser(e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,8 @@ protected void completeDrawable(Pen pen, Drawable drawable) {
} else {
area = new Area(((ShapeDrawable) drawable).getShape());
}
if (pen.isEraser()) {
getZone().removeTopology(area);
MapTool.serverCommand().removeTopology(getZone().getId(), area, getZone().getTopologyTypes());
} else {
getZone().addTopology(area);
MapTool.serverCommand().addTopology(getZone().getId(), area, getZone().getTopologyTypes());
}
renderer.repaint();
MapTool.serverCommand()
.updateTopology(getZone(), area, pen.isEraser(), getZone().getTopologyTypes());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,8 @@ public void mousePressed(MouseEvent e) {
int y2 = Math.max(rectangle.getStartPoint().y, rectangle.getEndPoint().y);

Area area = new Area(new java.awt.Rectangle(x1, y1, x2 - x1, y2 - y1));
if (isEraser(e)) {
getZone().removeTopology(area);
MapTool.serverCommand()
.removeTopology(getZone().getId(), area, getZone().getTopologyTypes());
} else {
getZone().addTopology(area);
MapTool.serverCommand()
.addTopology(getZone().getId(), area, getZone().getTopologyTypes());
}
renderer.repaint();
// TODO: send this to the server

MapTool.serverCommand()
.updateTopology(getZone(), area, isEraser(e), getZone().getTopologyTypes());
rectangle = null;
}
setIsEraser(isEraser(e));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,16 +584,9 @@ private void VblTool(Drawable drawable, boolean pathOnly, boolean isEraser) {
area = new Area(((ShapeDrawable) drawable).getShape());
}
}
if (isEraser) {
renderer.getZone().removeTopology(area);
MapTool.serverCommand()
.removeTopology(renderer.getZone().getId(), area, renderer.getZone().getTopologyTypes());
} else {
renderer.getZone().addTopology(area);
MapTool.serverCommand()
.addTopology(renderer.getZone().getId(), area, renderer.getZone().getTopologyTypes());
}
renderer.repaint();

MapTool.serverCommand()
.updateTopology(renderer.getZone(), area, isEraser, renderer.getZone().getTopologyTypes());
}

private Path2D getPath(Drawable drawable) {
Expand Down
Loading

0 comments on commit 3163585

Please sign in to comment.