Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onChangeMap event #4284

Merged
merged 4 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/net/rptools/maptool/client/AppActions.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
package net.rptools.maptool.client;

import static net.rptools.maptool.client.functions.MapFunctions.ON_CHANGE_MAP_CALLBACK;

import com.jidesoft.docking.DockableFrame;
import java.awt.*;
import java.awt.event.ActionEvent;
Expand Down Expand Up @@ -498,6 +500,12 @@ protected void executeAction() {
}

MapTool.serverCommand().enforceZone(renderer.getZone().getId());
List<Token> libTokens = EventMacroUtil.getEventMacroTokens(ON_CHANGE_MAP_CALLBACK);
cwisniew marked this conversation as resolved.
Show resolved Hide resolved
String prefix = ON_CHANGE_MAP_CALLBACK + "@";
for (Token handler : libTokens) {
EventMacroUtil.callEventHandlerOld(
prefix + handler.getName(), "", handler, Collections.emptyMap(), true);
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public class MapToolScriptSyntax extends MapToolScriptTokenMaker {

static String[] RESERVED_WORDS_2 = {
"onCampaignLoad",
"onChangeMap",
"onChangeSelection",
"onMouseOverEvent",
TokenMoveFunctions.ON_MULTIPLE_TOKENS_MOVED_COMPLETE_CALLBACK,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void convert() {
macroScriptNameMap.put(macroName, macroName + ".mts");
legacyEventNameMap.put(macroName, macroName);
}
case "onCampaignLoad" -> {
case "onCampaignLoad", "onChangeMap" -> {
macroScriptNameMap.put(macroName, macroName + ".mts");
eventNameMap.put(macroName, macroName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@
*/
package net.rptools.maptool.model.player;

import static net.rptools.maptool.client.functions.MapFunctions.ON_CHANGE_MAP_CALLBACK;

import com.google.common.eventbus.Subscribe;
import java.util.Collections;
import net.rptools.maptool.client.MapTool;
import net.rptools.maptool.client.events.PlayerStatusChanged;
import net.rptools.maptool.client.events.ZoneLoaded;
import net.rptools.maptool.client.events.ZoneLoading;
import net.rptools.maptool.events.MapToolEventBus;
import net.rptools.maptool.model.Token;
import net.rptools.maptool.util.EventMacroUtil;

public class PlayerZoneListener {
public PlayerZoneListener() {
Expand Down Expand Up @@ -54,6 +59,8 @@ public void OnZoneLoading(ZoneLoading event) {

@Subscribe
public void OnZoneLoaded(ZoneLoaded event) {
cwisniew marked this conversation as resolved.
Show resolved Hide resolved
var libTokens = EventMacroUtil.getEventMacroTokens(ON_CHANGE_MAP_CALLBACK);
String prefix = ON_CHANGE_MAP_CALLBACK + "@";
var player = MapTool.getPlayer();
player.setLoaded(true);
player.setZoneId(event.zone().getId());
Expand All @@ -76,5 +83,9 @@ public void OnZoneLoaded(ZoneLoaded event) {
eventBus.post(new PlayerStatusChanged(player));

MapTool.serverCommand().updatePlayerStatus(player);
for (Token handler : libTokens) {
EventMacroUtil.callEventHandlerOld(
prefix + handler.getName(), "", handler, Collections.emptyMap(), true);
}
}
}
Loading