From 15ebc6caf2abfe7e3e2ac9b82f699e1300769e92 Mon Sep 17 00:00:00 2001 From: jmr3366 Date: Tue, 3 Oct 2023 07:06:17 -0400 Subject: [PATCH 1/4] onChangeMap updated to new event type --- .../maptool/events/ZoneLoadedListener.java | 36 +++++++++++++++---- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/rptools/maptool/events/ZoneLoadedListener.java b/src/main/java/net/rptools/maptool/events/ZoneLoadedListener.java index 1f9ee6681a..ab94b818de 100644 --- a/src/main/java/net/rptools/maptool/events/ZoneLoadedListener.java +++ b/src/main/java/net/rptools/maptool/events/ZoneLoadedListener.java @@ -18,11 +18,19 @@ import com.google.common.eventbus.Subscribe; import java.util.Collections; +import java.util.concurrent.ExecutionException; +import net.rptools.maptool.client.MapTool; import net.rptools.maptool.client.events.ZoneLoaded; -import net.rptools.maptool.model.Token; +import net.rptools.maptool.client.ui.zone.ZoneRenderer; +import net.rptools.maptool.language.I18N; +import net.rptools.maptool.model.library.Library; +import net.rptools.maptool.model.library.LibraryManager; import net.rptools.maptool.util.EventMacroUtil; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; public class ZoneLoadedListener { + private static final Logger LOGGER = LogManager.getLogger(EventMacroUtil.class); public ZoneLoadedListener() { new MapToolEventBus().getMainEventBus().register(this); @@ -30,12 +38,26 @@ public ZoneLoadedListener() { @Subscribe public void OnChangedMap(ZoneLoaded event) { - var libTokens = EventMacroUtil.getEventMacroTokens(ON_CHANGE_MAP_CALLBACK); - String prefix = ON_CHANGE_MAP_CALLBACK + "@"; - - for (Token handler : libTokens) { - EventMacroUtil.callEventHandlerOld( - prefix + handler.getName(), "", handler, Collections.emptyMap(), true); + ZoneRenderer currentZR = MapTool.getFrame().getCurrentZoneRenderer(); + try { + var libs = new LibraryManager().getLegacyEventTargets(ON_CHANGE_MAP_CALLBACK).get(); + if (!libs.isEmpty()) { + for (Library handler : libs) { + try { + String libraryNamespace = handler.getNamespace().get(); + EventMacroUtil.callEventHandler( + ON_CHANGE_MAP_CALLBACK, + libraryNamespace, + currentZR.getZone().getId().toString() + "," + currentZR.getZone().toString(), + null, + Collections.emptyMap()); + } catch (InterruptedException | ExecutionException e) { + throw new AssertionError("Error retrieving library namespace"); + } + } + } + } catch (InterruptedException | ExecutionException e) { + LOGGER.error(I18N.getText("library.error.retrievingEventHandler"), e); } } } From 8c3b7ed05ac3e79b104100ef0cdbac2c2be664e1 Mon Sep 17 00:00:00 2001 From: jmr3366 Date: Tue, 3 Oct 2023 10:59:12 -0400 Subject: [PATCH 2/4] onChangeMap updated to new event type --- .../net/rptools/maptool/client/functions/MapFunctions.java | 1 - .../rptools/maptool/client/ui/syntax/MapToolScriptSyntax.java | 3 ++- .../java/net/rptools/maptool/events/ZoneLoadedListener.java | 3 +-- 3 files changed, 3 insertions(+), 4 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 749c62bd67..df0190f68a 100644 --- a/src/main/java/net/rptools/maptool/client/functions/MapFunctions.java +++ b/src/main/java/net/rptools/maptool/client/functions/MapFunctions.java @@ -39,7 +39,6 @@ import net.rptools.parser.function.AbstractFunction; public class MapFunctions extends AbstractFunction { - public static final String ON_CHANGE_MAP_CALLBACK = "onChangeMap"; private static final MapFunctions instance = new MapFunctions(); private MapFunctions() { diff --git a/src/main/java/net/rptools/maptool/client/ui/syntax/MapToolScriptSyntax.java b/src/main/java/net/rptools/maptool/client/ui/syntax/MapToolScriptSyntax.java index 20ef6a676a..a04ab91ab0 100644 --- a/src/main/java/net/rptools/maptool/client/ui/syntax/MapToolScriptSyntax.java +++ b/src/main/java/net/rptools/maptool/client/ui/syntax/MapToolScriptSyntax.java @@ -22,6 +22,7 @@ import net.rptools.maptool.client.functions.DefinesSpecialVariables; import net.rptools.maptool.client.functions.TokenMoveFunctions; import net.rptools.maptool.client.functions.UserDefinedMacroFunctions; +import net.rptools.maptool.events.ZoneLoadedListener; import net.rptools.maptool.model.InitiativeList; import net.rptools.maptool.model.TokenProperty; import net.rptools.parser.function.Function; @@ -97,9 +98,9 @@ public class MapToolScriptSyntax extends MapToolScriptTokenMaker { static String[] RESERVED_WORDS_2 = { "onCampaignLoad", - "onChangeMap", "onChangeSelection", "onMouseOverEvent", + ZoneLoadedListener.ON_CHANGE_MAP_CALLBACK, TokenMoveFunctions.ON_MULTIPLE_TOKENS_MOVED_COMPLETE_CALLBACK, TokenMoveFunctions.ON_TOKEN_MOVE_COMPLETE_CALLBACK, InitiativeList.ON_INITIATIVE_CHANGE_VETOABLE_MACRO_CALLBACK, diff --git a/src/main/java/net/rptools/maptool/events/ZoneLoadedListener.java b/src/main/java/net/rptools/maptool/events/ZoneLoadedListener.java index ab94b818de..4cda2a6d19 100644 --- a/src/main/java/net/rptools/maptool/events/ZoneLoadedListener.java +++ b/src/main/java/net/rptools/maptool/events/ZoneLoadedListener.java @@ -14,8 +14,6 @@ */ package net.rptools.maptool.events; -import static net.rptools.maptool.client.functions.MapFunctions.ON_CHANGE_MAP_CALLBACK; - import com.google.common.eventbus.Subscribe; import java.util.Collections; import java.util.concurrent.ExecutionException; @@ -31,6 +29,7 @@ public class ZoneLoadedListener { private static final Logger LOGGER = LogManager.getLogger(EventMacroUtil.class); + public static final String ON_CHANGE_MAP_CALLBACK = "onChangeMap"; public ZoneLoadedListener() { new MapToolEventBus().getMainEventBus().register(this); From 910b633df25a5c46ed9220babce0325f99ac7af6 Mon Sep 17 00:00:00 2001 From: jmr3366 Date: Sat, 14 Oct 2023 18:47:00 -0400 Subject: [PATCH 3/4] onChangeMap add-on compliance, output added --- .../maptool/events/ZoneLoadedListener.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/net/rptools/maptool/events/ZoneLoadedListener.java b/src/main/java/net/rptools/maptool/events/ZoneLoadedListener.java index 4cda2a6d19..d12afb2e39 100644 --- a/src/main/java/net/rptools/maptool/events/ZoneLoadedListener.java +++ b/src/main/java/net/rptools/maptool/events/ZoneLoadedListener.java @@ -40,19 +40,19 @@ public void OnChangedMap(ZoneLoaded event) { ZoneRenderer currentZR = MapTool.getFrame().getCurrentZoneRenderer(); try { var libs = new LibraryManager().getLegacyEventTargets(ON_CHANGE_MAP_CALLBACK).get(); - if (!libs.isEmpty()) { - for (Library handler : libs) { - try { - String libraryNamespace = handler.getNamespace().get(); - EventMacroUtil.callEventHandler( - ON_CHANGE_MAP_CALLBACK, - libraryNamespace, - currentZR.getZone().getId().toString() + "," + currentZR.getZone().toString(), - null, - Collections.emptyMap()); - } catch (InterruptedException | ExecutionException e) { - throw new AssertionError("Error retrieving library namespace"); - } + if (libs.isEmpty()) return; + for (Library handler : libs) { + try { + String libraryNamespace = handler.getNamespace().get(); + EventMacroUtil.callEventHandler( + ON_CHANGE_MAP_CALLBACK, + libraryNamespace, + currentZR.getZone().getId().toString() + "," + currentZR.getZone().toString(), + null, + Collections.emptyMap()); + } catch (InterruptedException | ExecutionException e) { + LOGGER.error(I18N.getText("library.error.notFound"), e); + throw new AssertionError("Error retrieving library namespace"); } } } catch (InterruptedException | ExecutionException e) { From 98648fe7e7c968433ef30e18e5313b4d46c4b04a Mon Sep 17 00:00:00 2001 From: jmr3366 Date: Wed, 18 Oct 2023 22:14:38 -0400 Subject: [PATCH 4/4] Completed requested changes --- .../java/net/rptools/maptool/events/ZoneLoadedListener.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/rptools/maptool/events/ZoneLoadedListener.java b/src/main/java/net/rptools/maptool/events/ZoneLoadedListener.java index d12afb2e39..95e8220080 100644 --- a/src/main/java/net/rptools/maptool/events/ZoneLoadedListener.java +++ b/src/main/java/net/rptools/maptool/events/ZoneLoadedListener.java @@ -40,14 +40,16 @@ public void OnChangedMap(ZoneLoaded event) { ZoneRenderer currentZR = MapTool.getFrame().getCurrentZoneRenderer(); try { var libs = new LibraryManager().getLegacyEventTargets(ON_CHANGE_MAP_CALLBACK).get(); - if (libs.isEmpty()) return; + if (libs.isEmpty()) { + return; + } for (Library handler : libs) { try { String libraryNamespace = handler.getNamespace().get(); EventMacroUtil.callEventHandler( ON_CHANGE_MAP_CALLBACK, libraryNamespace, - currentZR.getZone().getId().toString() + "," + currentZR.getZone().toString(), + currentZR.getZone().getId().toString(), null, Collections.emptyMap()); } catch (InterruptedException | ExecutionException e) {