Skip to content

Commit

Permalink
Merge pull request #4899 from fishface60/develop
Browse files Browse the repository at this point in the history
Bind getBar, setBar isBarVisible and setBarVisible to javascript
  • Loading branch information
cwisniew authored Sep 12, 2024
2 parents aed33aa + 143086d commit da4bea5
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package net.rptools.maptool.client.script.javascript.api;

import java.math.BigDecimal;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -282,6 +283,39 @@ public List<String> getActiveStates() {
return this.token.getSetStates();
}

@HostAccess.Export
public BigDecimal getBar(String barName) {
Object currentBar = this.token.getState(barName);
return currentBar == null ? BigDecimal.ZERO : (BigDecimal) currentBar;
}

@HostAccess.Export
public void setBar(String barName, double aValue) {
BigDecimal value = BigDecimal.valueOf(aValue);
boolean trusted = JSScriptEngine.inTrustedContext();
String playerId = MapTool.getPlayer().getName();
if (trusted || token.isOwner(playerId)) {
this.token.setState(barName, value);
MapTool.serverCommand().updateTokenProperty(token, Token.Update.setState, barName, value);
}
}

@HostAccess.Export
public boolean isBarVisible(String barName) {
Object currentBar = this.token.getState(barName);
return currentBar != null;
}

@HostAccess.Export
public void setBarVisible(String barName, boolean show) {
boolean trusted = JSScriptEngine.inTrustedContext();
String playerId = MapTool.getPlayer().getName();
if (trusted || token.isOwner(playerId)) {
this.token.setState(barName, show);
MapTool.serverCommand().updateTokenProperty(token, Token.Update.setState, barName, show);
}
}

@HostAccess.Export
public boolean isPC() {
return this.token.getType() == Token.Type.PC;
Expand Down

0 comments on commit da4bea5

Please sign in to comment.