From 581a103d104571e0bec93ed32a24b0ae033f2c4d Mon Sep 17 00:00:00 2001 From: ColdAnkles <13864745+ColdAnkles@users.noreply.github.com> Date: Thu, 19 Dec 2024 17:28:39 +1030 Subject: [PATCH] Completed Cleanup and JS Token Functions --- .../client/functions/Topology_Functions.java | 8 --- .../script/javascript/api/JSAPIToken.java | 60 +++++++++++++++++++ 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/rptools/maptool/client/functions/Topology_Functions.java b/src/main/java/net/rptools/maptool/client/functions/Topology_Functions.java index 2f405dca4e..0e818e78ce 100644 --- a/src/main/java/net/rptools/maptool/client/functions/Topology_Functions.java +++ b/src/main/java/net/rptools/maptool/client/functions/Topology_Functions.java @@ -668,23 +668,18 @@ public void childEvaluateSetTopologyImmunity( for (JsonElement entry : setList) { newSet.add(entry.getAsString()); } - // token.setTokenVBLImmunity(newSet); MapTool.serverCommand() .updateTokenProperty( token, Token.Update.setTokenVBLImmunity, newSet.toString().replaceAll("^\\[|]$", "")); } else if (functionName.equalsIgnoreCase("addTokenVBLImmunity")) { - // token.addTokenVBLImmunity(parameters.get(1).toString()); MapTool.serverCommand() .updateTokenProperty( token, Token.Update.addTokenVBLImmunity, parameters.get(1).toString()); } else if (functionName.equalsIgnoreCase("removeTokenVBLImmunity")) { - // token.removeTokenVBLImmunity(parameters.get(1).toString()); MapTool.serverCommand() .updateTokenProperty( token, Token.Update.removeTokenVBLImmunity, parameters.get(1).toString()); } else if (functionName.equalsIgnoreCase("setGlobalVBLImmunity")) { - // token.setGlobalVBLImmunity(parameters.get(1).toString(), - // BigDecimal.ONE.equals(parameters.get(2))); MapTool.serverCommand() .updateTokenProperty( token, @@ -692,15 +687,12 @@ public void childEvaluateSetTopologyImmunity( parameters.get(1).toString(), BigDecimal.ONE.equals(parameters.get(2))); } else if (functionName.equalsIgnoreCase("toggleGlobalVBLImmunity")) { - // token.toggleGlobalVBLImmunity(parameters.get(1).toString()); MapTool.serverCommand() .updateTokenProperty( token, Token.Update.toggleGlobalVBLImmunity, parameters.get(1).toString()); } else if (functionName.equalsIgnoreCase("clearTokenVBLImmunity")) { - // token.clearTokenVBLImmunity(); MapTool.serverCommand().updateTokenProperty(token, Token.Update.clearTokenVBLImmunity); } else if (functionName.equalsIgnoreCase("clearGlobalVBLImmunity")) { - // token.clearGlobalVBLImmunity(); MapTool.serverCommand().updateTokenProperty(token, Token.Update.clearGlobalVBLImmunity); } } diff --git a/src/main/java/net/rptools/maptool/client/script/javascript/api/JSAPIToken.java b/src/main/java/net/rptools/maptool/client/script/javascript/api/JSAPIToken.java index 0dffe95d9f..3036217d91 100644 --- a/src/main/java/net/rptools/maptool/client/script/javascript/api/JSAPIToken.java +++ b/src/main/java/net/rptools/maptool/client/script/javascript/api/JSAPIToken.java @@ -14,6 +14,7 @@ */ package net.rptools.maptool.client.script.javascript.api; +import com.google.gson.JsonArray; import java.math.BigDecimal; import java.util.Iterator; import java.util.List; @@ -350,4 +351,63 @@ public void setNPC() { public String getType() { return this.token.getType().name(); } + + @HostAccess.Export + public String getGlobalVBLImmunity() { + JsonArray returnValue = new JsonArray(); + token + .getGlobalVBLImmunity() + .forEach( + (key, value) -> { + if (value) { + returnValue.add(key); + } + }); + return returnValue.toString(); + } + + @HostAccess.Export + public String getTokenVBLImmunity() { + JsonArray returnValue = new JsonArray(); + token + .getTokenVBLImmunity() + .forEach( + (value) -> { + returnValue.add(value); + }); + return returnValue.toString(); + } + + @HostAccess.Export + public void setGlobalVBLImmunity(String vblSelector, boolean setTo) { + MapTool.serverCommand() + .updateTokenProperty(token, Token.Update.setGlobalVBLImmunity, vblSelector, setTo); + } + + @HostAccess.Export + public void toggleGlobalVBLImmunity(String vblSelector) { + MapTool.serverCommand() + .updateTokenProperty(token, Token.Update.toggleGlobalVBLImmunity, vblSelector); + } + + @HostAccess.Export + public void addTokenVBLImmunity(String tokenID) { + MapTool.serverCommand().updateTokenProperty(token, Token.Update.addTokenVBLImmunity, tokenID); + } + + @HostAccess.Export + public void removeTokenVBLImmunity(String tokenID) { + MapTool.serverCommand() + .updateTokenProperty(token, Token.Update.removeTokenVBLImmunity, tokenID); + } + + @HostAccess.Export + public void clearTokenVBLImmunity() { + MapTool.serverCommand().updateTokenProperty(token, Token.Update.clearTokenVBLImmunity); + } + + @HostAccess.Export + public void clearGlobalVBLImmunity() { + MapTool.serverCommand().updateTokenProperty(token, Token.Update.clearGlobalVBLImmunity); + } }