Skip to content

Commit

Permalink
Merge branch 'develop' into cover-vbl
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdAnkles committed Oct 20, 2023
2 parents 0b9e1b9 + 3cdf0dc commit 06d8705
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 48 deletions.
9 changes: 4 additions & 5 deletions src/main/java/net/rptools/maptool/client/AppUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,18 +213,17 @@ public static Path getInstallDirectory() {
var path = Path.of(getAppInstallLocation());
if (MapTool.isDevelopment()) {
// remove build/classes/java
path = path.getParent().getParent().getParent().getParent();
} else {
path = path.getParent().getParent().getParent();
} else { // First try to find MapTool* directory in path
while (path != null) {
if (path.getFileName().toString().matches("(?i).*maptool.*")) {
path = path.getParent();
break;
}
path = path.getParent();
}
}
if (path == null) {
return Path.of(getAppInstallLocation());
if (path == null) { // if not found then just return the parent of the app subdir
return Path.of(getAppInstallLocation()).resolve("..").toAbsolutePath();
} else {
return path;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@
import java.util.List;
import java.util.prefs.Preferences;
import net.rptools.maptool.language.I18N;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class DeveloperOptions {
private static final Logger log = LogManager.getLogger(DeveloperOptions.class);
private static final Preferences prefs =
Preferences.userRoot().node(AppConstants.APP_NAME + "/prefs");
Preferences.userRoot().node(AppConstants.APP_NAME + "/dev");

public enum Toggle {
/**
Expand Down Expand Up @@ -57,7 +54,7 @@ public String getKey() {
}

public boolean isEnabled() {
return prefs.getBoolean(key, true);
return prefs.getBoolean(key, false);
}

public void setEnabled(boolean enabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,12 @@ private JsonElement shallowCopy(JsonElement jsonElement) {
* @return The resulting json data.
*/
private JsonElement jsonPathDelete(JsonElement json, String path) {
return JsonPath.using(jaywayConfig).parse(shallowCopy(json)).delete(path).json();
try {
return JsonPath.using(jaywayConfig).parse(shallowCopy(json)).delete(path).json();
} catch (PathNotFoundException ex) {
// Return original json, this is to preserve backwards compatability pre library update
return json;
}
}

/**
Expand Down Expand Up @@ -906,7 +911,12 @@ private JsonElement jsonPathPut(JsonElement json, String path, String key, Objec
private JsonElement jsonPathSet(JsonElement json, String path, Object info) {
Object value = asJsonElement(info);

return JsonPath.using(jaywayConfig).parse(shallowCopy(json)).set(path, value).json();
try {
return JsonPath.using(jaywayConfig).parse(shallowCopy(json)).set(path, value).json();
} catch (PathNotFoundException ex) {
// Return original json, this is to preserve backwards compatability pre library update
return json;
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package net.rptools.maptool.client.script.javascript.api;

import java.util.Iterator;
import java.util.List;
import java.util.Set;
import net.rptools.maptool.client.MapTool;
import net.rptools.maptool.client.script.javascript.*;
Expand Down Expand Up @@ -199,4 +200,70 @@ public void setMap(Zone m) {
public String getMapName() {
return this.map.getDisplayName();
}

@HostAccess.Export
public boolean getState(String stateName) {
Object currentState = this.token.getState(stateName);
return (currentState instanceof Boolean && (Boolean) currentState);
}

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

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

@HostAccess.Export
public List<String> getActiveStates() {
return this.token.getSetStates();
}

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

@HostAccess.Export
public void setPC() {
boolean trusted = JSScriptEngine.inTrustedContext();
String playerId = MapTool.getPlayer().getName();
if (trusted || token.isOwner(playerId)) {
this.token.setType(Token.Type.PC);
MapTool.serverCommand().updateTokenProperty(token, Token.Update.setPC);
}
}

@HostAccess.Export
public boolean isNPC() {
return this.token.getType() == Token.Type.NPC;
}

@HostAccess.Export
public void setNPC() {
boolean trusted = JSScriptEngine.inTrustedContext();
String playerId = MapTool.getPlayer().getName();
if (trusted || token.isOwner(playerId)) {
this.token.setType(Token.Type.NPC);
MapTool.serverCommand().updateTokenProperty(token, Token.Update.setNPC);
}
}

@HostAccess.Export
public String getType() {
return this.token.getType().name();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ public PreferencesDialog() {
fileSyncPath = panel.getTextField("fileSyncPath");
fileSyncPathButton = (JButton) panel.getButton("fileSyncPathButton");

final var installDirTextField = (JTextField) panel.getComponent("InstallDirTextField");
installDirTextField.setText(AppUtil.getInstallDirectory().toString());

publicKeyTextArea = (JTextArea) panel.getTextComponent("publicKeyTextArea");
regeneratePublicKey = (JButton) panel.getButton("regeneratePublicKey");
copyPublicKey = (JButton) panel.getButton("copyKey");
Expand Down
Loading

0 comments on commit 06d8705

Please sign in to comment.