Page MenuHomeWildfire Games

Map specific Gamesetup option: SeaLevelRise for Extinct Volcano map
ClosedPublic

Authored by elexis on Jan 23 2020, 9:14 AM.

Details

Summary

This revision implements the gamesetup option to control the time at which the sea level rises for the maps that support it (currently only Extinct Volcano), as planned in #4838.
The purpose of this feature is to make this map more enjoyable and versatile, suited to the users wishes, and secondly to showcase more how to implement map specific gamesetup options.

Test Plan

Notice that this GameSettingControl, alike the Daytime and Landscape option from rP23392/D2564, does not hardcode the map but just checks if the map json/xml data enables this option. This way it can be reused by other maps too.

Event Timeline

elexis created this revision.Jan 23 2020, 9:14 AM
elexis added inline comments.Jan 23 2020, 9:18 AM
binaries/data/mods/public/gui/gamesetup/Controls/GameSettingsControl.js
189

This mapChange move can be committed separately, has the purpose of actually doing what the comment says, and it does not do what the comment says, because an onMapChange handler that calls updateGameAttributes will call the onUpdateGameAttributes handler prior to the onMapChange handler; and can be reproduced by for example selecting the Danubius map, selecting a Daytime, then closing and reopening the gamesetup. Expected behavior is that the Daytime option is restored, but its reset to Random without this diff (same with the sea level time in this diff).

elexis updated this revision to Diff 11153.Jan 23 2020, 9:19 AM

Missing file

Successful build - Chance fights ever on the side of the prudent.

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/1632/display/redirect

Successful build - Chance fights ever on the side of the prudent.

Link to build: https://jenkins.wildfiregames.com/job/docker-differential/1633/display/redirect

elexis added inline comments.Jan 23 2020, 4:50 PM
binaries/data/mods/public/gui/gamesetup/Controls/GameSettingsControl.js
189

I can't reproduce it anymore, the code still seems to have that bug, it might be that it depends on a specific gamesetting that is updated when opening the page. So I will leave this unchanged until further evidence.

Diff was:

Index: binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/Panels/MapPreview.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/Panels/MapPreview.js	(revision 23432)
+++ binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/Panels/MapPreview.js	(working copy)
@@ -8,12 +8,20 @@
 		this.mapInfoName = Engine.GetGUIObjectByName("mapInfoName");
 		this.mapPreview = Engine.GetGUIObjectByName("mapPreview");
 
-		this.gameSettingsControl.registerMapChangeHandler(this.onMapChange.bind(this));
+		this.previousMap = undefined;
+
+		this.gameSettingsControl.registerGameAttributesChangeHandler(this.onGameAttributesChange.bind(this));
 		this.gameSettingsControl.registerGameAttributesBatchChangeHandler(this.onGameAttributesBatchChange.bind(this));
 	}
 
-	onMapChange(mapData)
+	onGameAttributesChange()
 	{
+		if (!g_GameAttributes.map || this.previousMap == g_GameAttributes.map || !g_GameAttributes.mapType)
+			return;
+
+		this.previousMap = g_GameAttributes.map;
+		let mapData = this.mapCache.getMapData(g_GameAttributes.mapType, g_GameAttributes.map);
+
 		let preview = mapData && mapData.settings && mapData.settings.Preview;
 		if (!g_GameAttributes.settings.Preview || g_GameAttributes.settings.Preview != preview)
 		{
Index: binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/GameSettingControl.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/GameSettingControl.js	(revision 23432)
+++ binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/GameSettingControl.js	(working copy)
@@ -60,13 +60,13 @@
 		this.setHidden(false);
 
 		if (this.onMapChange)
-			this.gameSettingsControl.registerMapChangeHandler(this.onMapChange.bind(this));
+			this.previousMap = undefined;
 
 		if (this.onLoad)
 			this.setupWindow.registerLoadHandler(this.onLoad.bind(this));
 
 		if (this.onGameAttributesChange)
-			this.gameSettingsControl.registerGameAttributesChangeHandler(this.onGameAttributesChange.bind(this));
+			this.gameSettingsControl.registerGameAttributesChangeHandler(this.onGameAttributesChangeSuper.bind(this));
 
 		if (this.onGameAttributesBatchChange)
 			this.gameSettingsControl.registerGameAttributesBatchChangeHandler(this.onGameAttributesBatchChange.bind(this));
@@ -84,6 +84,20 @@
 			this.playerAssignmentsControl.registerPlayerAssignmentsChangeHandler(this.onPlayerAssignmentsChange.bind(this));
 	}
 
+	onGameAttributesChangeSuper()
+	{
+		// Map change handlers are triggered first, so that GameSettingControls can update their
+		// gameAttributes model prior to applying that model in their gameAttributesChangeHandler.
+		if (this.onMapChange && g_GameAttributes.map && this.previousMap != g_GameAttributes.map && g_GameAttributes.mapType)
+		{
+			this.previousMap = g_GameAttributes.map;
+			let mapData = this.mapCache.getMapData(g_GameAttributes.mapType, g_GameAttributes.map);
+			this.onMapChange(mapData);
+		}
+
+		this.onGameAttributesChange();
+	}
+
 	setTitle(titleCaption)
 	{
 		this.autocompleteTitle = titleCaption;
Index: binaries/data/mods/public/gui/gamesetup/Controls/GameSettingsControl.js
===================================================================
--- binaries/data/mods/public/gui/gamesetup/Controls/GameSettingsControl.js	(revision 23432)
+++ binaries/data/mods/public/gui/gamesetup/Controls/GameSettingsControl.js	(working copy)
@@ -10,7 +10,6 @@
 		this.mapCache = mapCache;
 		this.gameSettingsFile = new GameSettingsFile(setupWindow);
 
-		this.previousMap = undefined;
 		this.depth = 0;
 
 		// This property may be read from publicly
@@ -21,7 +20,6 @@
 		this.gameAttributesFinalizeHandlers = new Set();
 		this.pickRandomItemsHandlers = new Set();
 		this.assignPlayerHandlers = new Set();
-		this.mapChangeHandlers = new Set();
 
 		setupWindow.registerLoadHandler(this.onLoad.bind(this));
 		setupWindow.registerGetHotloadDataHandler(this.onGetHotloadData.bind(this));
@@ -32,16 +30,6 @@
 			netMessages.registerNetMessageHandler("gamesetup", this.onGamesetupMessage.bind(this));
 	}
 
-	registerMapChangeHandler(handler)
-	{
-		this.mapChangeHandlers.add(handler);
-	}
-
-	unregisterMapChangeHandler(handler)
-	{
-		this.mapChangeHandlers.delete(handler);
-	}
-
 	/**
 	 * This message is triggered everytime g_GameAttributes change.
 	 * Handlers may subsequently change g_GameAttributes and trigger this message again.
@@ -178,16 +166,6 @@
 					g_GameAttributes.settings.PlayerData[i] = {};
 		}
 
-		// Map change handlers are triggered first, so that GameSettingControls can update their
-		// gameAttributes model prior to applying that model in their gameAttributesChangeHandler.
-		if (g_GameAttributes.map && this.previousMap != g_GameAttributes.map && g_GameAttributes.mapType)
-		{
-			this.previousMap = g_GameAttributes.map;
-			let mapData = this.mapCache.getMapData(g_GameAttributes.mapType, g_GameAttributes.map);
-			for (let handler of this.mapChangeHandlers)
-				handler(mapData);
-		}
-
 		for (let handler of this.gameAttributesChangeHandlers)
 			handler();
elexis updated the Trac tickets for this revision.Jan 23 2020, 4:54 PM
This revision was not accepted when it landed; it landed in state Needs Review.Jan 23 2020, 4:58 PM
This revision was automatically updated to reflect the committed changes.
Owners added subscribers: Restricted Owners Package, Restricted Owners Package.Jan 23 2020, 4:58 PM