Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NPEs in protobuf conversion #3288

Merged
merged 5 commits into from
Jan 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import net.rptools.lib.MD5Key;
import net.rptools.maptool.model.Asset;
import net.rptools.maptool.model.AssetManager;
import net.rptools.maptool.transfer.ConsumerListener;
Expand All @@ -28,7 +28,7 @@
* @author trevor
*/
public class AssetTransferHandler implements ConsumerListener {
public void assetComplete(Serializable id, String name, File data) {
public void assetComplete(MD5Key id, String name, File data) {
byte[] assetData = null;
try {
assetData = FileUtils.readFileToByteArray(data);
Expand All @@ -50,11 +50,11 @@ public void assetComplete(Serializable id, String name, File data) {
MapTool.getFrame().refresh();
}

public void assetUpdated(Serializable id) {
public void assetUpdated(MD5Key id) {
// Nothing to do
}

public void assetAdded(Serializable id) {
public void assetAdded(MD5Key id) {
// Nothing to do
}
}
17 changes: 15 additions & 2 deletions src/main/java/net/rptools/maptool/client/ClientMessageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ public void handleMessage(String id, byte[] message) {
case UPDATE_CAMPAIGN_MACROS_MSG -> handle(msg.getUpdateCampaignMacrosMsg());
case UPDATE_GM_MACROS_MSG -> handle(msg.getUpdateGmMacrosMsg());
case UPDATE_EXPOSED_AREA_META_MSG -> handle(msg.getUpdateExposedAreaMetaMsg());
case UPDATE_TOKEN_MOVE_MSG -> handle(msg.getUpdateTokenMoveMsg());
default -> log.warn(msgType + "not handled.");
}

Expand All @@ -160,11 +161,23 @@ public void handleMessage(String id, byte[] message) {
}
}

private void handle(UpdateTokenMoveMsg msg) {
EventQueue.invokeLater(
() -> {
var zoneGUID = GUID.valueOf(msg.getZoneGuid());
var keyToken = GUID.valueOf(msg.getKeyTokenId());

var renderer = MapTool.getFrame().getZoneRenderer(zoneGUID);
renderer.updateMoveSelectionSet(
keyToken, new ZonePoint(msg.getPoint().getX(), msg.getPoint().getY()));
});
}

private void handle(UpdateExposedAreaMetaMsg msg) {
EventQueue.invokeLater(
() -> {
var zoneGUID = GUID.valueOf(msg.getZoneGuid());
var tokenGUID = GUID.valueOf(msg.getTokenGuid());
var tokenGUID = msg.hasTokenGuid() ? GUID.valueOf(msg.getTokenGuid().getValue()) : null;
ExposedAreaMetaData meta = new ExposedAreaMetaData(Mapper.map(msg.getArea()));
var zone = MapTool.getCampaign().getZone(zoneGUID);
zone.setExposedAreaMetaData(tokenGUID, meta);
Expand Down Expand Up @@ -212,7 +225,7 @@ private void handle(UpdateTokenInitiativeMsg msg) {
if (tokenIndex.size() != 1) return;
ti = list.getTokenInitiative(tokenIndex.get(0));
} // endif
ti.update(msg.getIsHolding(), msg.getState());
ti.update(msg.getIsHolding(), msg.hasState() ? msg.getState().getValue() : null);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/rptools/maptool/client/MapTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ private static void initialize() {
ChatAutoSave.changeTimeout(AppPreferences.getChatAutosaveTime());

// TODO: make this more formal when we switch to mina
new ServerHeartBeatThread().start();
// new ServerHeartBeatThread().start();
}

public static NoteFrame getProfilingNoteFrame() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package net.rptools.maptool.client;

import com.google.protobuf.BoolValue;
import com.google.protobuf.StringValue;
import java.awt.geom.Area;
import java.math.BigDecimal;
import java.util.Arrays;
Expand Down Expand Up @@ -442,8 +443,7 @@ public void setZoneHasFoW(GUID zoneGUID, boolean hasFog) {

public void bringTokensToFront(GUID zoneGUID, Set<GUID> tokenList) {
var msg = BringTokensToFrontMsg.newBuilder().setZoneGuid(zoneGUID.toString());
tokenList.stream().forEach(guid -> msg.addTokenGuids(guid.toString()));

msg.addAllTokenGuids(tokenList.stream().map(g -> g.toString()).collect(Collectors.toList()));
makeServerCall(Message.newBuilder().setBringTokensToFrontMsg(msg).build());
}

Expand Down Expand Up @@ -477,8 +477,10 @@ public void updateTokenInitiative(
.setZoneGuid(zone.toString())
.setTokenGuid(token.toString())
.setIsHolding(holding)
.setState(state)
.setIndex(index);
if (state != null) {
msg.setState(StringValue.of(state));
}
makeServerCall(Message.newBuilder().setUpdateTokenInitiativeMsg(msg).build());
}

Expand Down Expand Up @@ -543,8 +545,10 @@ public void updateExposedAreaMeta(
var msg =
UpdateExposedAreaMetaMsg.newBuilder()
.setZoneGuid(zoneGUID.toString())
.setTokenGuid(tokenExposedAreaGUID.toString())
.setArea(Mapper.map(meta.getExposedAreaHistory()));
if (tokenExposedAreaGUID != null) {
msg.setTokenGuid(StringValue.of(tokenExposedAreaGUID.toString()));
}
makeServerCall(Message.newBuilder().setUpdateExposedAreaMetaMsg(msg).build());
}

Expand Down Expand Up @@ -796,6 +800,7 @@ public synchronized void flush() {

if (msg != null) {
makeServerCall(msg);
msg = null;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package net.rptools.maptool.client.ui.token;

import com.google.protobuf.StringValue;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.util.Comparator;
Expand Down Expand Up @@ -218,7 +219,7 @@ public boolean showPlayer(Token token, Player player) {
protected void fillFrom(TokenOverlayDto dto) {
name = dto.getName();
order = dto.getOrder();
group = dto.getGroup();
group = dto.hasGroup() ? dto.getGroup().getValue() : null;
mouseover = dto.getMouseOver();
opacity = dto.getOpacity();
showGM = dto.getShowGm();
Expand All @@ -230,7 +231,7 @@ protected TokenOverlayDto getCommonDto() {
var dto = TokenOverlayDto.newBuilder();
dto.setName(name);
dto.setOrder(order);
dto.setGroup(group);
if (group != null) dto.setGroup(StringValue.of(group));
dto.setMouseOver(mouseover);
dto.setOpacity(opacity);
dto.setShowGm(showGM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
import java.awt.Color;
import java.awt.EventQueue;
import java.io.File;
import java.io.Serializable;
import java.text.NumberFormat;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableColumnModel;
import net.rptools.lib.MD5Key;
import net.rptools.maptool.client.MapTool;
import net.rptools.maptool.client.swing.AbeillePanel;
import net.rptools.maptool.client.swing.GenericDialog;
Expand Down Expand Up @@ -151,15 +151,15 @@ public String getColumnName(int column) {

////
// CONSUMER LISTENER
public void assetComplete(Serializable id, String name, File data) {
public void assetComplete(MD5Key id, String name, File data) {
updateTransferTable();
}

public void assetUpdated(Serializable id) {
public void assetUpdated(MD5Key id) {
getTransferTable().repaint();
}

public void assetAdded(Serializable id) {
public void assetAdded(MD5Key id) {
updateTransferTable();
}
}
21 changes: 14 additions & 7 deletions src/main/java/net/rptools/maptool/model/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package net.rptools.maptool.model;

import com.google.protobuf.BoolValue;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -74,8 +75,8 @@ public class Campaign {
// location and type, and the
// settings of all JToggleButton objects (JRadioButtons and JCheckBoxes).
private Location exportLocation; // FJE 2011-01-14
private Map<String, Boolean>
exportSettings; // the state of each checkbox/radiobutton for the Export>ScreenshotAs dialog
private Map<String, Boolean> exportSettings =
new HashMap<>(); // the state of each checkbox/radiobutton for the Export>ScreenshotAs dialog

private CampaignProperties campaignProperties = new CampaignProperties();
private transient boolean isBeingSerialized;
Expand Down Expand Up @@ -720,10 +721,12 @@ public static Campaign fromDto(CampaignDto dto) {
var campaign = new Campaign();
campaign.id = GUID.valueOf(dto.getId());
campaign.name = dto.getName();
campaign.hasUsedFogToolbar = dto.getHasUsedFogToolbar();
campaign.hasUsedFogToolbar =
dto.hasHasUsedFogToolbar() ? dto.getHasUsedFogToolbar().getValue() : null;
campaign.campaignProperties = CampaignProperties.fromDto(dto.getProperties());
campaign.exportLocation = Location.fromDto(dto.getExportLocation());
campaign.exportSettings = dto.getExportSettingsMap();
campaign.exportLocation =
dto.hasExportLocation() ? Location.fromDto(dto.getExportLocation()) : null;
campaign.exportSettings.putAll(dto.getExportSettingsMap());
campaign.macroButtonLastIndex = dto.getMacroButtonLastIndex();
campaign.gmMacroButtonLastIndex = dto.getGmMacroButtonLastIndex();
campaign.macroButtonProperties =
Expand All @@ -740,9 +743,13 @@ public CampaignDto toDto() {
var dto = CampaignDto.newBuilder();
dto.setId(id.toString());
dto.setName(name);
dto.setHasUsedFogToolbar(hasUsedFogToolbar);
if (hasUsedFogToolbar != null) {
dto.setHasUsedFogToolbar(BoolValue.of(hasUsedFogToolbar));
}
dto.setProperties(campaignProperties.toDto());
dto.setExportLocation(exportLocation.toDto());
if (exportLocation != null) {
dto.setExportLocation(exportLocation.toDto());
}
dto.putAllExportSettings(exportSettings);
dto.setMacroButtonLastIndex(macroButtonLastIndex);
dto.setGmMacroButtonLastIndex(gmMacroButtonLastIndex);
Expand Down
Loading