Skip to content

Commit

Permalink
Fix setTokenVBL() not updating clients
Browse files Browse the repository at this point in the history
- Fix so that setTokenVBL updates all clients.
- Add javadocs comments to vision and light methods
- Remove redundent updateTokenTree calls (already triggered by TOKEN_CHANGED event)
- Remove redundant tokenTopologyChanged: (already triggered by TOKEN_CHANGED if the token has VBL)
- Close RPTools#932
  • Loading branch information
Merudo committed Nov 24, 2019
1 parent c4ee522 commit b6e043c
Show file tree
Hide file tree
Showing 23 changed files with 468 additions and 155 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ public Object childEvaluate(Parser parser, String functionName, List<Object> par

Token token = FunctionUtil.getTokenFromParam(resolver, functionName, parameters, 0, 1);
MapTool.serverCommand().updateTokenProperty(token, "clearLightSources");
MapTool.getFrame().updateTokenTree();
return "";
}
if (functionName.equalsIgnoreCase("setLight")) {
Expand Down Expand Up @@ -158,9 +157,6 @@ private static BigDecimal setLight(Token token, String category, String name, Bi
throw new ParserException(
I18N.getText("macro.function.tokenLight.unknownLightType", "setLights", category));
}
MapTool.getFrame().updateTokenTree();
token.getZoneRenderer().flushLight();

return found ? BigDecimal.ONE : BigDecimal.ZERO;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,8 @@ public Object childEvaluate(Parser parser, String functionName, List<Object> par
1,
parameters.get(0).toString()));
}
MapTool.serverCommand()
.updateTokenProperty(token, "setZOrder", ((BigDecimal) parameters.get(0)).intValue());
ZoneRenderer renderer = MapTool.getFrame().getCurrentZoneRenderer();
renderer.flushLight();
int newZOrder = ((BigDecimal) parameters.get(0)).intValue();
MapTool.serverCommand().updateTokenProperty(token, "setZOrder", newZOrder);
return BigDecimal.valueOf(token.getZOrder());
}
if (functionName.equals("getDistance")) {
Expand Down Expand Up @@ -595,7 +593,6 @@ private static String moveToken(MapToolVariableResolver res, List<Object> args)

ZonePoint zp = getZonePoint(x, y, useDistance);
MapTool.serverCommand().updateTokenProperty(token, "setXY", zp.x, zp.y);
token.getZoneRenderer().flushLight();
return "";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,6 @@ public Object childEvaluate(Parser parser, String functionName, List<Object> par
FunctionUtil.checkNumberParam(functionName, parameters, 0, 2);
Token token = FunctionUtil.getTokenFromParam(resolver, functionName, parameters, 0, 1);
MapTool.serverCommand().updateTokenProperty(token, functionName);
token.getZoneRenderer().flushLight();
MapTool.getFrame().updateTokenTree();
return "";
}

Expand All @@ -214,8 +212,6 @@ public Object childEvaluate(Parser parser, String functionName, List<Object> par
FunctionUtil.checkNumberParam(functionName, parameters, 0, 2);
Token token = FunctionUtil.getTokenFromParam(resolver, functionName, parameters, 0, 1);
MapTool.serverCommand().updateTokenProperty(token, functionName);
token.getZoneRenderer().flushLight();
MapTool.getFrame().updateTokenTree();
return "";
}

Expand All @@ -239,8 +235,6 @@ public Object childEvaluate(Parser parser, String functionName, List<Object> par
}
Token token = FunctionUtil.getTokenFromParam(resolver, functionName, parameters, 1, 3);
String layer = setLayer(token, parameters.get(0).toString(), forceShape);
token.getZoneRenderer().flushLight();
MapTool.getFrame().updateTokenTree();
return layer;
}

Expand Down Expand Up @@ -605,10 +599,6 @@ public Object childEvaluate(Parser parser, String functionName, List<Object> par
BigDecimal facing = getBigDecimalFromParam(functionName, parameters, 0);
Token token = FunctionUtil.getTokenFromParam(resolver, functionName, parameters, 1, 2);
MapTool.serverCommand().updateTokenProperty(token, "setFacing", facing.intValue());
token
.getZoneRenderer()
.flushLight(); // FJE This isn't needed unless the token had a light source, right? Should
// we check for that?
return "";
}

Expand All @@ -619,7 +609,6 @@ public Object childEvaluate(Parser parser, String functionName, List<Object> par
FunctionUtil.checkNumberParam(functionName, parameters, 0, 2);
Token token = FunctionUtil.getTokenFromParam(resolver, functionName, parameters, 0, 1);
MapTool.serverCommand().updateTokenProperty(token, "setFacing", (Integer) null);
token.getZoneRenderer().flushLight();
return "";
}

Expand Down Expand Up @@ -776,10 +765,9 @@ public Object childEvaluate(Parser parser, String functionName, List<Object> par

double magnitude = getBigDecimalFromParam(functionName, parameters, 0).doubleValue();
Rectangle tokenBounds = token.getBounds(zone);

double oldWidth = tokenBounds.width;
double oldHeight = tokenBounds.height;
MapTool.serverCommand().updateTokenProperty(token, "setSnapToScale", false);

double newScaleX;
double newScaleY;
if (functionName.equals("setTokenWidth")) {
Expand Down Expand Up @@ -839,16 +827,10 @@ private String setSize(Token token, String size) throws ParserException {
MapTool.serverCommand().updateTokenProperty(token, "setSnapToScale", false);
return getSize(token);
}
MapTool.serverCommand().updateTokenProperty(token, "setSnapToScale", true);
ZoneRenderer renderer = token.getZoneRenderer();
Zone zone = renderer.getZone();
Grid grid = zone.getGrid();
Grid grid = token.getZoneRenderer().getZone().getGrid();
for (TokenFootprint footprint : grid.getFootprints()) {
if (footprint.getName().equalsIgnoreCase(size)) {
MapTool.serverCommand().updateTokenProperty(token, "setFootprint", grid, footprint);
renderer.flush(token);
renderer.repaint();
MapTool.getFrame().updateTokenTree();
return getSize(token);
}
}
Expand All @@ -862,12 +844,9 @@ private String setSize(Token token, String size) throws ParserException {
* @param token The token to reset the size of.
*/
private void resetSize(Token token) {
MapTool.serverCommand().updateTokenProperty(token, "setSnapToScale", true);
ZoneRenderer renderer = token.getZoneRenderer();
Zone zone = renderer.getZone();
Grid grid = zone.getGrid();
MapTool.serverCommand()
.updateTokenProperty(token, "setFootprint", grid, grid.getDefaultFootprint());
Grid grid = token.getZoneRenderer().getZone().getGrid();
TokenFootprint footprint = grid.getDefaultFootprint();
MapTool.serverCommand().updateTokenProperty(token, "setFootprint", grid, footprint);
}

/**
Expand Down Expand Up @@ -896,8 +875,8 @@ public static Zone.Layer getLayer(String layerName) throws ParserException {
}

/**
* Get the token shape corresponding to the token & layer. Returns null if can't find match, or if
* forceShape is set to false.
* Get the token shape corresponding to the token and layer. Returns null if can't find match, or
* if forceShape is set to false.
*
* @param token the token to get the new shape of.
* @param layer the layer of the token.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,14 @@ public Object childEvaluate(Parser parser, String functionName, List<Object> par
token = FunctionUtil.getTokenFromParam(resolver, functionName, parameters, 1, 2);

if (functionName.equals("setHasSight")) {
MapTool.serverCommand()
.updateTokenProperty(token, "setHasSight", !parameters.get(0).equals(BigDecimal.ZERO));
token.getZoneRenderer().flushLight();
boolean hasSight = !parameters.get(0).equals(BigDecimal.ZERO);
MapTool.serverCommand().updateTokenProperty(token, "setHasSight", hasSight);
return token.getHasSight() ? BigDecimal.ONE : BigDecimal.ZERO;
}

if (functionName.equals("setSightType")) {
MapTool.serverCommand()
.updateTokenProperty(token, "setSightType", parameters.get(0).toString());
token.getZoneRenderer().flushLight();
String sightType = parameters.get(0).toString();
MapTool.serverCommand().updateTokenProperty(token, "setSightType", sightType);
return token.getSightType();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,8 @@ public Object childEvaluate(Parser parser, String functionName, List<Object> par
break;
}
}

// Replace with new VBL
MapTool.serverCommand().updateTokenProperty(token, "setVBL", tokenVBL);

// Force a TOPOLOGY_CHANGED event. This made the client performing the
// VBL change actually show the change but not the other clients.
renderer.getZone().tokenTopologyChanged();
renderer.repaint();
}

if (functionName.equals("transferVBL")) {
Expand Down Expand Up @@ -363,19 +357,18 @@ public Object childEvaluate(Parser parser, String functionName, List<Object> par
/**
* Get the required parameters needed from the JSON to draw a rectangle and render as VBL.
*
* @param renderer Reference to the ZoneRenderer
* @param renderer Reference to the ZoneRenderer. Can be null.
* @param vblObject The JSONObject containing all the coordinates and values to needed to draw a
* rectangle.
* @param erase Set to true to erase the rectangle in VBL, otherwise draw it
* @return
* @throws ParserException If the minimum required parameters are not present in the JSON, throw
* ParserException
* @param erase Set to true to erase the rectangle in VBL, otherwise draw it.
* @return the VBL area if the renderer is null, and null otherwise.
* @throws ParserException If the minimum required parameters are not present in the JSON.
*/
private Area drawRectangleVBL(ZoneRenderer renderer, JSONObject vblObject, boolean erase)
throws ParserException {
String funcname = "drawVBL[Rectangle]";
// Required Parameters
String requiredParms[] = {"x", "y", "w", "h"};
String[] requiredParms = {"x", "y", "w", "h"};
if (!jsonKeysExist(vblObject, requiredParms, funcname))
throw new ParserException(
I18N.getText("macro.function.general.argumentKeyTypeI", funcname, "{x,y,w,h}"));
Expand Down Expand Up @@ -491,9 +484,8 @@ private void applyScale(
* @param vblObject The JSONObject containing all the coordinates and values to needed to draw a
* rectangle.
* @param erase Set to true to erase the rectangle in VBL, otherwise draw it
* @return
* @throws ParserException If the minimum required parameters are not present in the JSON, throw
* ParserException
* @return the VBL area if the renderer is null, and null otherwise.
* @throws ParserException If the minimum required parameters are not present in the JSON.
*/
private Area drawPolygonVBL(ZoneRenderer renderer, JSONObject vblObject, boolean erase)
throws ParserException {
Expand Down Expand Up @@ -611,9 +603,8 @@ private Area drawPolygonVBL(ZoneRenderer renderer, JSONObject vblObject, boolean
* @param vblObject The JSONObject containing all the coordinates and values to needed to draw a
* rectangle.
* @param erase Set to true to erase the rectangle in VBL, otherwise draw it
* @return the token.
* @throws ParserException If the minimum required parameters are not present in the JSON, throw
* ParserException
* @return the VBL area if the renderer is null, and null otherwise.
* @throws ParserException If the minimum required parameters are not present in the JSON.
*/
private Area drawCrossVBL(ZoneRenderer renderer, JSONObject vblObject, boolean erase)
throws ParserException {
Expand Down Expand Up @@ -694,9 +685,8 @@ private Area drawCrossVBL(ZoneRenderer renderer, JSONObject vblObject, boolean e
* @param vblObject The JSONObject containing all the coordinates and values to needed to draw a
* rectangle.
* @param erase Set to true to erase the rectangle in VBL, otherwise draw it
* @return
* @throws ParserException If the minimum required parameters are not present in the JSON, throw
* ParserException
* @return the VBL area if the renderer is null, and null otherwise.
* @throws ParserException If the minimum required parameters are not present in the JSON.
*/
private Area drawCircleVBL(ZoneRenderer renderer, JSONObject vblObject, boolean erase)
throws ParserException {
Expand Down Expand Up @@ -781,10 +771,10 @@ private Area drawCircleVBL(ZoneRenderer renderer, JSONObject vblObject, boolean
* Get the required parameters needed from the JSON to get/set VBL within a defined rectangle.
*
* @param renderer Reference to the ZoneRenderer
* @param vblObject The JSONObject containing all the coordinates and values to needed to draw a
* @param vblObject JSONObject containing all the coordinates and values needed to draw a
* rectangle.
* @throws ParserException If the minimum required parameters are not present in the JSON, throw
* ParserException
* @return the VBL area.
* @throws ParserException If the minimum required parameters are not present in the JSON.
*/
private Area getVBL(ZoneRenderer renderer, JSONObject vblObject) throws ParserException {
String funcname = "getVBL[Rectangle]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ public void stopTokenDrag() {
exposeFoW(null);
}

/**
* Expose the FoW at a ZonePoint, or at the visible area, for the selected token
*
* @param p the ZonePoint to expose, or a null if exposing visible area and last path
*/
public void exposeFoW(ZonePoint p) {
// if has fog(required)
// and ((isGM with pref set) OR serverPolicy allows auto reveal by players)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ public class MapToolFrame extends DefaultDockableHolder
// Components
private final AssetPanel assetPanel;
private final ClientConnectionPanel connectionPanel;
/** The panel showing the initiative order. */
private final InitiativePanel initiativePanel;

private final PointerOverlay pointerOverlay;
private final CommandPanel commandPanel;
private final AboutDialog aboutDialog;
Expand Down Expand Up @@ -212,7 +214,9 @@ public class MapToolFrame extends DefaultDockableHolder
private final ChatTyperObserver chatTyperObserver;

private final GlassPane glassPane;
/** Model for the token tree panel of the map explorer. */
private TokenPanelTreeModel tokenPanelTreeModel;

private DrawPanelTreeModel drawPanelTreeModel;
private DrawablesPanel drawablesPanel;
private final TextureChooserPanel textureChooserPanel;
Expand All @@ -225,7 +229,7 @@ public class MapToolFrame extends DefaultDockableHolder
private JFileChooser savePropsFileChooser;
private JFileChooser saveFileChooser;

// Remember the last layer selected
/** Remember the last layer selected */
private Layer lastSelectedLayer = Zone.Layer.TOKEN;

private final FileFilter campaignFilter =
Expand Down Expand Up @@ -788,6 +792,7 @@ public EditTokenDialog getTokenPropertiesDialog() {
return tokenPropertiesDialog;
}

/** Repaints the current ZoneRenderer, if it is not null. */
public void refresh() {
if (getCurrentZoneRenderer() != null) {
getCurrentZoneRenderer().repaint();
Expand Down Expand Up @@ -1214,6 +1219,7 @@ public void updateDrawTree() {
}
}

/** Create the token tree panel for the map explorer */
private JComponent createTokenTreePanel() {
final JTree tree = new JTree();
tokenPanelTreeModel = new TokenPanelTreeModel(tree);
Expand Down Expand Up @@ -1311,6 +1317,7 @@ public void clearTokenTree() {
}
}

/** Update tokenPanelTreeModel and the initiativePanel. */
public void updateTokenTree() {
if (tokenPanelTreeModel != null) {
tokenPanelTreeModel.update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public void clearTokens() {
list.clearModel();
}

/** Make sure that the token references match the zone */
/** Update list containing tokens in initiative. Make sure the token references match the zone. */
public void update() {
list.update();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public enum View {
Zone.Layer layer;
boolean isAdmin;

private View(String key, Zone.Layer layer, boolean required, boolean isAdmin) {
View(String key, Zone.Layer layer, boolean required, boolean isAdmin) {
this.displayName = I18N.getText(key);
this.description = null; // I18N.getDescription(key); // TODO Tooltip -- not currently used
this.required = required;
Expand All @@ -97,10 +97,13 @@ public boolean isRequired() {
}
}

/** The list of token filters. */
private final List<TokenFilter> filterList = new ArrayList<TokenFilter>();

private final String root = "Views";
private Zone zone;
private final JTree tree;
/** Is an updateInternal pending? */
private volatile boolean updatePending = false;

public TokenPanelTreeModel(JTree tree) {
Expand All @@ -126,6 +129,11 @@ public Object getRoot() {
return root;
}

/**
* Set the zone, updating the listeners and the internals.
*
* @param zone the Zone to set.
*/
public void setZone(Zone zone) {
if (zone != null) {
zone.removeModelChangeListener(this);
Expand Down Expand Up @@ -192,6 +200,10 @@ public void removeTreeModelListener(TreeModelListener l) {
listenerList.remove(l);
}

/**
* Run updateInternal on the EventQueue. This clears currentViewList and viewMap, and adds views
* in the filterList to currentViewList.
*/
public void update() {
// better solution would be to use a timeout to invoke the internal update to give more
// token events the chance to arrive, but in this case EventQueue overload will
Expand All @@ -208,6 +220,7 @@ public void run() {
}
}

/** Clear currentViewList and viewMap, and add views in the filterList to currentViewList */
private void updateInternal() {
currentViewList.clear();
viewMap.clear();
Expand Down Expand Up @@ -308,6 +321,7 @@ private void filter(Token token) {
* useStrictTokenManagement() into account).
*/
private class PlayerTokenFilter extends TokenFilter {
/** Accepts only PCs tokens owned by the current player. */
public PlayerTokenFilter() {
super(View.PLAYERS);
}
Expand Down Expand Up @@ -392,6 +406,7 @@ protected boolean accept(Token token) {
* </ol>
*/
private class TokenTokenFilter extends TokenFilter {
/** Accepts only NPC tokens (GM) or tokens owned by current player. */
public TokenTokenFilter() {
super(View.TOKENS);
}
Expand Down
Loading

0 comments on commit b6e043c

Please sign in to comment.