Skip to content

Commit

Permalink
Merge pull request #4301 from ColdAnkles/JS_setPropertyFix
Browse files Browse the repository at this point in the history
JS API setProperty() fix.
  • Loading branch information
cwisniew authored Sep 27, 2023
2 parents 6bcba32 + 37f72c4 commit e479bb1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -33,6 +34,7 @@ public String serializeToString() {
private final Token token;
private Set<String> names;
private Iterator<String> names_iter;
private Zone map;

public JSAPIToken(Token token) {
this.token = token;
Expand All @@ -58,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);
}
}

Expand All @@ -77,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);
}
}

Expand Down Expand Up @@ -130,6 +134,8 @@ public void setProperty(String name, Object value) {
String playerId = MapTool.getPlayer().getName();
if (trusted || token.isOwner(playerId)) {
this.token.setProperty(name, value.toString());
MapTool.serverCommand()
.updateTokenProperty(token, Token.Update.setProperty, name, value.toString());
}
}

Expand Down Expand Up @@ -184,4 +190,13 @@ public boolean isOnCurrentMap() {
MapTool.getFrame().getCurrentZoneRenderer().getZone().getToken(new GUID(this.getId()));
return this.token == findToken;
}

public void setMap(Zone m) {
this.map = m;
}

@HostAccess.Export
public String getMapName() {
return this.map.getDisplayName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ZoneRenderer> 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;
}
}
Expand All @@ -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;
}
Expand Down

0 comments on commit e479bb1

Please sign in to comment.