From e3ecddd22fe981186e26762e25acdef08d1616c3 Mon Sep 17 00:00:00 2001 From: bubblobill <45483160+bubblobill@users.noreply.github.com> Date: Sun, 10 Dec 2023 19:21:57 +0800 Subject: [PATCH 1/2] Added info type "functions" --- .../client/functions/getInfoFunction.java | 57 ++++++++++++------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/src/main/java/net/rptools/maptool/client/functions/getInfoFunction.java b/src/main/java/net/rptools/maptool/client/functions/getInfoFunction.java index dc4283ddf9..b9420a9123 100644 --- a/src/main/java/net/rptools/maptool/client/functions/getInfoFunction.java +++ b/src/main/java/net/rptools/maptool/client/functions/getInfoFunction.java @@ -28,6 +28,7 @@ import javax.swing.*; import net.rptools.maptool.client.AppPreferences; import net.rptools.maptool.client.MapTool; +import net.rptools.maptool.client.MapToolExpressionParser; import net.rptools.maptool.client.ui.htmlframe.HTMLDialog; import net.rptools.maptool.client.ui.htmlframe.HTMLFrame; import net.rptools.maptool.client.ui.htmlframe.HTMLOverlayManager; @@ -89,8 +90,8 @@ public static getInfoFunction getInstance() { @Override public Object childEvaluate( - Parser parser, VariableResolver resolver, String functionName, List param) - throws ParserException { + Parser parser, VariableResolver resolver, String functionName, List param) + throws ParserException { String infoType = param.get(0).toString(); if (infoType.equalsIgnoreCase("map") || infoType.equalsIgnoreCase("zone")) { @@ -105,12 +106,30 @@ public Object childEvaluate( return getThemeInfo(); } else if (infoType.equalsIgnoreCase("debug")) { return getDebugInfo(); + } else if (infoType.equalsIgnoreCase("functions")) { + return getFunctionLists(); } else { throw new ParserException( - I18N.getText("macro.function.getInfo.invalidArg", param.get(0).toString())); + I18N.getText("macro.function.getInfo.invalidArg", param.get(0).toString())); } } + private JsonObject getFunctionLists() { + UserDefinedMacroFunctions UDF = UserDefinedMacroFunctions.getInstance(); + JsonObject udfList = new JsonObject(); + for (String name : UDF.getAliases()) { + udfList.addProperty(name, UDF.getFunctionLocation(name)); + } + JsonArray fList = new JsonArray(); + MapToolExpressionParser.getMacroFunctions() + .forEach(function -> Arrays.stream(function.getAliases()).forEach(fList::add)); + + JsonObject fInfo = new JsonObject(); + fInfo.add("functions", fList); + fInfo.add("user defined functions", udfList); + return fInfo; + } + /** * Retrieves the information about the current zone/map and returns it as a JSON Object. * @@ -199,18 +218,18 @@ private JsonObject getClientInfo() { cinfo.addProperty("face edge", FunctionUtil.getDecimalForBoolean(AppPreferences.getFaceEdge())); cinfo.addProperty( - "face vertex", FunctionUtil.getDecimalForBoolean(AppPreferences.getFaceVertex())); + "face vertex", FunctionUtil.getDecimalForBoolean(AppPreferences.getFaceVertex())); cinfo.addProperty("portrait size", AppPreferences.getPortraitSize()); cinfo.addProperty("show portrait", AppPreferences.getShowPortrait()); cinfo.addProperty("show stat sheet", AppPreferences.getShowStatSheet()); cinfo.addProperty("file sync directory", AppPreferences.getFileSyncPath()); cinfo.addProperty("show avatar in chat", AppPreferences.getShowAvatarInChat()); cinfo.addProperty( - "suppress tooltips for macroLinks", AppPreferences.getSuppressToolTipsForMacroLinks()); + "suppress tooltips for macroLinks", AppPreferences.getSuppressToolTipsForMacroLinks()); cinfo.addProperty("use tooltips for inline rolls", AppPreferences.getUseToolTipForInlineRoll()); cinfo.addProperty("version", MapTool.getVersion()); cinfo.addProperty( - "isFullScreen", FunctionUtil.getDecimalForBoolean(MapTool.getFrame().isFullScreen())); + "isFullScreen", FunctionUtil.getDecimalForBoolean(MapTool.getFrame().isFullScreen())); cinfo.addProperty("timeInMs", System.currentTimeMillis()); cinfo.addProperty("timeDate", getTimeDate()); cinfo.addProperty("isoTimeDate", getIsoTimeDate()); @@ -236,7 +255,7 @@ private JsonObject getClientInfo() { JsonObject overlays = new JsonObject(); ConcurrentSkipListSet registeredOverlays = - MapTool.getFrame().getOverlayPanel().getOverlays(); + MapTool.getFrame().getOverlayPanel().getOverlays(); for (HTMLOverlayManager o : registeredOverlays) { overlays.add(o.getName(), o.getProperties()); } @@ -266,11 +285,11 @@ private JsonObject getClientInfo() { * @param unknownVersionText text to show if version is unknown */ private void getInfoOnTokensOfType( - JsonObject cinfo, - String token_type, - String prefix, - String versionProperty, - String unknownVersionText) { + JsonObject cinfo, + String token_type, + String prefix, + String versionProperty, + String unknownVersionText) { JsonObject libInfo = new JsonObject(); for (ZoneRenderer zr : MapTool.getFrame().getZoneRenderers()) { Zone zone = zr.getZone(); @@ -322,7 +341,7 @@ private JsonObject getCampaignInfo() throws ParserException { if (!MapTool.getParser().isMacroTrusted()) { throw new ParserException( - I18N.getText("macro.function.general.noPerm", "getInfo('campaign')")); + I18N.getText("macro.function.general.noPerm", "getInfo('campaign')")); } JsonObject cinfo = new JsonObject(); Campaign c = MapTool.getCampaign(); @@ -330,11 +349,11 @@ private JsonObject getCampaignInfo() throws ParserException { cinfo.addProperty("id", c.getId().toString()); cinfo.addProperty( - "initiative movement locked", - FunctionUtil.getDecimalForBoolean(cp.isInitiativeMovementLock())); + "initiative movement locked", + FunctionUtil.getDecimalForBoolean(cp.isInitiativeMovementLock())); cinfo.addProperty( - "initiative owner permissions", - FunctionUtil.getDecimalForBoolean(cp.isInitiativeOwnerPermissions())); + "initiative owner permissions", + FunctionUtil.getDecimalForBoolean(cp.isInitiativeOwnerPermissions())); JsonArray zoneIds = new JsonArray(); JsonObject zinfo = new JsonObject(); @@ -395,7 +414,7 @@ private JsonObject getCampaignInfo() throws ParserException { state.addProperty("isShowOwner", bto.isShowOwner() ? BigDecimal.ONE : BigDecimal.ZERO); state.addProperty("isShowOthers", bto.isShowOthers() ? BigDecimal.ONE : BigDecimal.ZERO); state.addProperty( - "isImageOverlay", (bto instanceof ImageTokenOverlay) ? BigDecimal.ONE : BigDecimal.ZERO); + "isImageOverlay", (bto instanceof ImageTokenOverlay) ? BigDecimal.ONE : BigDecimal.ZERO); state.addProperty("mouseOver", bto.isMouseover() ? BigDecimal.ONE : BigDecimal.ZERO); state.addProperty("opacity", bto.getOpacity()); state.addProperty("order", bto.getOrder()); @@ -486,4 +505,4 @@ private JsonObject getThemeInfo() { private JsonObject getDebugInfo() { return sysInfoProvider.getSysInfoJSON(); } -} +} \ No newline at end of file From 066df4c5e2708a2c7c25682682e9a8e0071346d6 Mon Sep 17 00:00:00 2001 From: bubblobill <45483160+bubblobill@users.noreply.github.com> Date: Sun, 10 Dec 2023 19:23:39 +0800 Subject: [PATCH 2/2] Spotlessed --- .../client/functions/getInfoFunction.java | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/main/java/net/rptools/maptool/client/functions/getInfoFunction.java b/src/main/java/net/rptools/maptool/client/functions/getInfoFunction.java index b9420a9123..46231fee59 100644 --- a/src/main/java/net/rptools/maptool/client/functions/getInfoFunction.java +++ b/src/main/java/net/rptools/maptool/client/functions/getInfoFunction.java @@ -90,8 +90,8 @@ public static getInfoFunction getInstance() { @Override public Object childEvaluate( - Parser parser, VariableResolver resolver, String functionName, List param) - throws ParserException { + Parser parser, VariableResolver resolver, String functionName, List param) + throws ParserException { String infoType = param.get(0).toString(); if (infoType.equalsIgnoreCase("map") || infoType.equalsIgnoreCase("zone")) { @@ -110,7 +110,7 @@ public Object childEvaluate( return getFunctionLists(); } else { throw new ParserException( - I18N.getText("macro.function.getInfo.invalidArg", param.get(0).toString())); + I18N.getText("macro.function.getInfo.invalidArg", param.get(0).toString())); } } @@ -122,7 +122,7 @@ private JsonObject getFunctionLists() { } JsonArray fList = new JsonArray(); MapToolExpressionParser.getMacroFunctions() - .forEach(function -> Arrays.stream(function.getAliases()).forEach(fList::add)); + .forEach(function -> Arrays.stream(function.getAliases()).forEach(fList::add)); JsonObject fInfo = new JsonObject(); fInfo.add("functions", fList); @@ -218,18 +218,18 @@ private JsonObject getClientInfo() { cinfo.addProperty("face edge", FunctionUtil.getDecimalForBoolean(AppPreferences.getFaceEdge())); cinfo.addProperty( - "face vertex", FunctionUtil.getDecimalForBoolean(AppPreferences.getFaceVertex())); + "face vertex", FunctionUtil.getDecimalForBoolean(AppPreferences.getFaceVertex())); cinfo.addProperty("portrait size", AppPreferences.getPortraitSize()); cinfo.addProperty("show portrait", AppPreferences.getShowPortrait()); cinfo.addProperty("show stat sheet", AppPreferences.getShowStatSheet()); cinfo.addProperty("file sync directory", AppPreferences.getFileSyncPath()); cinfo.addProperty("show avatar in chat", AppPreferences.getShowAvatarInChat()); cinfo.addProperty( - "suppress tooltips for macroLinks", AppPreferences.getSuppressToolTipsForMacroLinks()); + "suppress tooltips for macroLinks", AppPreferences.getSuppressToolTipsForMacroLinks()); cinfo.addProperty("use tooltips for inline rolls", AppPreferences.getUseToolTipForInlineRoll()); cinfo.addProperty("version", MapTool.getVersion()); cinfo.addProperty( - "isFullScreen", FunctionUtil.getDecimalForBoolean(MapTool.getFrame().isFullScreen())); + "isFullScreen", FunctionUtil.getDecimalForBoolean(MapTool.getFrame().isFullScreen())); cinfo.addProperty("timeInMs", System.currentTimeMillis()); cinfo.addProperty("timeDate", getTimeDate()); cinfo.addProperty("isoTimeDate", getIsoTimeDate()); @@ -255,7 +255,7 @@ private JsonObject getClientInfo() { JsonObject overlays = new JsonObject(); ConcurrentSkipListSet registeredOverlays = - MapTool.getFrame().getOverlayPanel().getOverlays(); + MapTool.getFrame().getOverlayPanel().getOverlays(); for (HTMLOverlayManager o : registeredOverlays) { overlays.add(o.getName(), o.getProperties()); } @@ -285,11 +285,11 @@ private JsonObject getClientInfo() { * @param unknownVersionText text to show if version is unknown */ private void getInfoOnTokensOfType( - JsonObject cinfo, - String token_type, - String prefix, - String versionProperty, - String unknownVersionText) { + JsonObject cinfo, + String token_type, + String prefix, + String versionProperty, + String unknownVersionText) { JsonObject libInfo = new JsonObject(); for (ZoneRenderer zr : MapTool.getFrame().getZoneRenderers()) { Zone zone = zr.getZone(); @@ -341,7 +341,7 @@ private JsonObject getCampaignInfo() throws ParserException { if (!MapTool.getParser().isMacroTrusted()) { throw new ParserException( - I18N.getText("macro.function.general.noPerm", "getInfo('campaign')")); + I18N.getText("macro.function.general.noPerm", "getInfo('campaign')")); } JsonObject cinfo = new JsonObject(); Campaign c = MapTool.getCampaign(); @@ -349,11 +349,11 @@ private JsonObject getCampaignInfo() throws ParserException { cinfo.addProperty("id", c.getId().toString()); cinfo.addProperty( - "initiative movement locked", - FunctionUtil.getDecimalForBoolean(cp.isInitiativeMovementLock())); + "initiative movement locked", + FunctionUtil.getDecimalForBoolean(cp.isInitiativeMovementLock())); cinfo.addProperty( - "initiative owner permissions", - FunctionUtil.getDecimalForBoolean(cp.isInitiativeOwnerPermissions())); + "initiative owner permissions", + FunctionUtil.getDecimalForBoolean(cp.isInitiativeOwnerPermissions())); JsonArray zoneIds = new JsonArray(); JsonObject zinfo = new JsonObject(); @@ -414,7 +414,7 @@ private JsonObject getCampaignInfo() throws ParserException { state.addProperty("isShowOwner", bto.isShowOwner() ? BigDecimal.ONE : BigDecimal.ZERO); state.addProperty("isShowOthers", bto.isShowOthers() ? BigDecimal.ONE : BigDecimal.ZERO); state.addProperty( - "isImageOverlay", (bto instanceof ImageTokenOverlay) ? BigDecimal.ONE : BigDecimal.ZERO); + "isImageOverlay", (bto instanceof ImageTokenOverlay) ? BigDecimal.ONE : BigDecimal.ZERO); state.addProperty("mouseOver", bto.isMouseover() ? BigDecimal.ONE : BigDecimal.ZERO); state.addProperty("opacity", bto.getOpacity()); state.addProperty("order", bto.getOrder()); @@ -505,4 +505,4 @@ private JsonObject getThemeInfo() { private JsonObject getDebugInfo() { return sysInfoProvider.getSysInfoJSON(); } -} \ No newline at end of file +}