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; }