From 4950c8526ea13cd3182f0e584fe0441136f2db3b Mon Sep 17 00:00:00 2001 From: ColdAnkles <13864745+ColdAnkles@users.noreply.github.com> Date: Mon, 25 Sep 2023 16:24:06 +0930 Subject: [PATCH 1/3] Attempted to resolve #4237 --- .../client/script/javascript/api/JSAPIToken.java | 13 +++++++++++++ .../client/script/javascript/api/JSAPITokens.java | 3 +++ 2 files changed, 16 insertions(+) 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 4430318346..a92b63c7f2 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 @@ -21,6 +21,7 @@ import net.rptools.maptool.language.I18N; import net.rptools.maptool.model.GUID; import net.rptools.maptool.model.Token; +import net.rptools.maptool.model.Zone; import net.rptools.parser.ParserException; import org.graalvm.polyglot.HostAccess; @@ -33,6 +34,7 @@ public String serializeToString() { private final Token token; private Set names; private Iterator names_iter; + private Zone map; public JSAPIToken(Token token) { this.token = token; @@ -130,6 +132,7 @@ public void setProperty(String name, Object value) { String playerId = MapTool.getPlayer().getName(); if (trusted || token.isOwner(playerId)) { this.token.setProperty(name, value.toString()); + this.map.putToken(this.token); } } @@ -184,4 +187,14 @@ public boolean isOnCurrentMap() { MapTool.getFrame().getCurrentZoneRenderer().getZone().getToken(new GUID(this.getId())); return this.token == findToken; } + + @HostAccess.Export + public void setMap(Zone m) { + this.map = m; + } + + @HostAccess.Export + public String getMapName() { + return this.map.getDisplayName(); + } } diff --git a/src/main/java/net/rptools/maptool/client/script/javascript/api/JSAPITokens.java b/src/main/java/net/rptools/maptool/client/script/javascript/api/JSAPITokens.java index 2e07322468..8842a92390 100644 --- a/src/main/java/net/rptools/maptool/client/script/javascript/api/JSAPITokens.java +++ b/src/main/java/net/rptools/maptool/client/script/javascript/api/JSAPITokens.java @@ -97,12 +97,14 @@ public JSAPIToken getTokenByID(String uuid) { MapTool.getFrame().getCurrentZoneRenderer().getZone().getToken(new GUID(uuid)); if (findToken != null) { token = new JSAPIToken(findToken); + token.setMap(MapTool.getFrame().getCurrentZoneRenderer().getZone()); } else { List zrenderers = MapTool.getFrame().getZoneRenderers(); for (ZoneRenderer zr : zrenderers) { findToken = zr.getZone().resolveToken(uuid); if (findToken != null) { token = new JSAPIToken(findToken); + token.setMap(zr.getZone()); break; } } @@ -122,6 +124,7 @@ public JSAPIToken getMapTokenByID(String uuid) { if (findToken != null && (JSScriptEngine.inTrustedContext() || token.isOwner(MapTool.getPlayer().getName()))) { token = new JSAPIToken(findToken); + token.setMap(MapTool.getFrame().getCurrentZoneRenderer().getZone()); } return token; } From 722ab47e15a70871bd230054f09810c36d1544f6 Mon Sep 17 00:00:00 2001 From: ColdAnkles <13864745+ColdAnkles@users.noreply.github.com> Date: Mon, 25 Sep 2023 16:52:47 +0930 Subject: [PATCH 2/3] Potential resolution, mimicking existing setX() and setY() calls to serverCommand(), but unsure whether this is wise... --- .../maptool/client/script/javascript/api/JSAPIToken.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 a92b63c7f2..6cc54be912 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 @@ -60,6 +60,7 @@ public void setNotes(String notes) { String playerId = MapTool.getPlayer().getName(); if (trusted || token.isOwner(playerId)) { token.setNotes(notes); + MapTool.serverCommand().updateTokenProperty(token, Token.Update.setNotes, notes); } } @@ -79,6 +80,7 @@ public void setName(String name) { String playerId = MapTool.getPlayer().getName(); if (trusted || token.isOwner(playerId)) { token.setName(name); + MapTool.serverCommand().updateTokenProperty(token, Token.Update.setName, name); } } @@ -132,7 +134,9 @@ public void setProperty(String name, Object value) { String playerId = MapTool.getPlayer().getName(); if (trusted || token.isOwner(playerId)) { this.token.setProperty(name, value.toString()); - this.map.putToken(this.token); + // this.map.putToken(this.token); + MapTool.serverCommand() + .updateTokenProperty(token, Token.Update.setProperty, name, value.toString()); } } From 37f72c400b334d04aaa085125c6f306195a04bd3 Mon Sep 17 00:00:00 2001 From: ColdAnkles <13864745+ColdAnkles@users.noreply.github.com> Date: Tue, 26 Sep 2023 18:44:19 +0930 Subject: [PATCH 3/3] Remove Unwanted Export and comment. --- .../maptool/client/script/javascript/api/JSAPIToken.java | 2 -- 1 file changed, 2 deletions(-) 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 6cc54be912..e328d89e69 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 @@ -134,7 +134,6 @@ public void setProperty(String name, Object value) { String playerId = MapTool.getPlayer().getName(); if (trusted || token.isOwner(playerId)) { this.token.setProperty(name, value.toString()); - // this.map.putToken(this.token); MapTool.serverCommand() .updateTokenProperty(token, Token.Update.setProperty, name, value.toString()); } @@ -192,7 +191,6 @@ public boolean isOnCurrentMap() { return this.token == findToken; } - @HostAccess.Export public void setMap(Zone m) { this.map = m; }