From 729dbb93960d871322e1e5380ef46c6cc6bc4ac9 Mon Sep 17 00:00:00 2001 From: jmr3366 Date: Tue, 5 Sep 2023 19:12:10 -0400 Subject: [PATCH 1/2] new functions - getMapVision(), setMapVision("off/day/night") Requested feature --- .../client/functions/MapFunctions.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/rptools/maptool/client/functions/MapFunctions.java b/src/main/java/net/rptools/maptool/client/functions/MapFunctions.java index e9b4de8b1f..8002f8c5e3 100644 --- a/src/main/java/net/rptools/maptool/client/functions/MapFunctions.java +++ b/src/main/java/net/rptools/maptool/client/functions/MapFunctions.java @@ -63,7 +63,9 @@ private MapFunctions() { "copyMap", "createMap", "getMapName", - "setMapSelectButton"); + "setMapSelectButton", + "getMapVision", + "setMapVision"); } public static MapFunctions getInstance() { @@ -397,6 +399,29 @@ public Object childEvaluate( return (MapTool.getFrame().getToolbarPanel().getMapselect().isVisible() ? BigDecimal.ONE : BigDecimal.ZERO); + } else if ("setMapVision".equalsIgnoreCase(functionName)) { + FunctionUtil.blockUntrustedMacro(functionName); + FunctionUtil.checkNumberParam(functionName, parameters, 1, 1); + Zone currentZR = MapTool.getFrame().getCurrentZoneRenderer().getZone(); + if (parameters.get(0).toString().equalsIgnoreCase("off")) { + MapTool.serverCommand().setVisionType(currentZR.getId(), Zone.VisionType.OFF); + } else if (parameters.get(0).toString().equalsIgnoreCase("day")) { + MapTool.serverCommand().setVisionType(currentZR.getId(), Zone.VisionType.DAY); + } else if (parameters.get(0).toString().equalsIgnoreCase("night")) { + MapTool.serverCommand().setVisionType(currentZR.getId(), Zone.VisionType.NIGHT); + } + /* else if (!parameters.get(0).toString().isBlank()) { + throw new ParameterException( + I18N.getText("macro.function.general.argumentTypeInvalid", functionName)); + } */ + if (currentZR == null) { + throw new ParserException(I18N.getText("macro.function.map.none", functionName)); + } + return ""; + } else if ("getMapVision".equalsIgnoreCase(functionName)) { + FunctionUtil.checkNumberParam(functionName, parameters, 0, 0); + ZoneRenderer currentZR = MapTool.getFrame().getCurrentZoneRenderer(); + return currentZR.getZone().getVisionType().toString(); } throw new ParserException(I18N.getText("macro.function.general.unknownFunction", functionName)); From 2bf217fd39234872bdea37156485dcd35eba7abc Mon Sep 17 00:00:00 2001 From: jmr3366 Date: Wed, 6 Sep 2023 07:39:00 -0400 Subject: [PATCH 2/2] new functions - getMapVision(), setMapVision("off/day/night") Requested feature - updated from comments --- .../client/functions/MapFunctions.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/rptools/maptool/client/functions/MapFunctions.java b/src/main/java/net/rptools/maptool/client/functions/MapFunctions.java index 8002f8c5e3..df0190f68a 100644 --- a/src/main/java/net/rptools/maptool/client/functions/MapFunctions.java +++ b/src/main/java/net/rptools/maptool/client/functions/MapFunctions.java @@ -403,20 +403,17 @@ public Object childEvaluate( FunctionUtil.blockUntrustedMacro(functionName); FunctionUtil.checkNumberParam(functionName, parameters, 1, 1); Zone currentZR = MapTool.getFrame().getCurrentZoneRenderer().getZone(); - if (parameters.get(0).toString().equalsIgnoreCase("off")) { - MapTool.serverCommand().setVisionType(currentZR.getId(), Zone.VisionType.OFF); - } else if (parameters.get(0).toString().equalsIgnoreCase("day")) { - MapTool.serverCommand().setVisionType(currentZR.getId(), Zone.VisionType.DAY); - } else if (parameters.get(0).toString().equalsIgnoreCase("night")) { - MapTool.serverCommand().setVisionType(currentZR.getId(), Zone.VisionType.NIGHT); - } - /* else if (!parameters.get(0).toString().isBlank()) { - throw new ParameterException( - I18N.getText("macro.function.general.argumentTypeInvalid", functionName)); - } */ if (currentZR == null) { throw new ParserException(I18N.getText("macro.function.map.none", functionName)); } + switch (parameters.get(0).toString().toLowerCase()) { + case "off" -> MapTool.serverCommand().setVisionType(currentZR.getId(), Zone.VisionType.OFF); + case "day" -> MapTool.serverCommand().setVisionType(currentZR.getId(), Zone.VisionType.DAY); + case "night" -> MapTool.serverCommand() + .setVisionType(currentZR.getId(), Zone.VisionType.NIGHT); + default -> throw new ParserException( + I18N.getText("macro.function.general.argumentTypeInvalid", functionName)); + } return ""; } else if ("getMapVision".equalsIgnoreCase(functionName)) { FunctionUtil.checkNumberParam(functionName, parameters, 0, 0);