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 all commits
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
3 changes: 3 additions & 0 deletions src/main/java/net/rptools/maptool/client/MapTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import net.rptools.maptool.client.ui.zone.ZoneRenderer;
import net.rptools.maptool.client.ui.zone.ZoneRendererFactory;
import net.rptools.maptool.events.MapToolEventBus;
import net.rptools.maptool.events.ZoneLoadedListener;
import net.rptools.maptool.language.I18N;
import net.rptools.maptool.model.AssetManager;
import net.rptools.maptool.model.Campaign;
Expand Down Expand Up @@ -158,6 +159,7 @@ public class MapTool {
private static List<Player> playerList;
private static LocalPlayer player;
private static PlayerZoneListener playerZoneListener;
private static ZoneLoadedListener zoneLoadedListener;

private static MapToolConnection conn;
private static ClientMessageHandler handler;
Expand Down Expand Up @@ -679,6 +681,7 @@ private static void initialize() {
try {
player = new LocalPlayer("", Player.Role.GM, ServerConfig.getPersonalServerGMPassword());
playerZoneListener = new PlayerZoneListener();
zoneLoadedListener = new ZoneLoadedListener();
Campaign cmpgn = CampaignFactory.createBasicCampaign();
// This was previously being done in the server thread and didn't always get done
// before the campaign was accessed by the postInitialize() method below.
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
41 changes: 41 additions & 0 deletions src/main/java/net/rptools/maptool/events/ZoneLoadedListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* This software Copyright by the RPTools.net development team, and
* licensed under the Affero GPL Version 3 or, at your option, any later
* version.
*
* MapTool Source Code is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public
* License * along with this source Code. If not, please visit
* <http://www.gnu.org/licenses/> and specifically the Affero license
* text at <http://www.gnu.org/licenses/agpl.html>.
*/
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 net.rptools.maptool.client.events.ZoneLoaded;
import net.rptools.maptool.model.Token;
import net.rptools.maptool.util.EventMacroUtil;

public class ZoneLoadedListener {

public ZoneLoadedListener() {
new MapToolEventBus().getMainEventBus().register(this);
}

@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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public void convert() {
case "onInitiativeChangeRequest",
"onInitiativeChange",
"onTokenMove",
"onMultipleTokensMove" -> {
"onMultipleTokensMove",
"onChangeMap" -> {
macroScriptNameMap.put(macroName, macroName + ".mts");
legacyEventNameMap.put(macroName, macroName);
}
Expand Down
Loading