Differential D2593 Diff 11153 binaries/data/mods/public/gui/gamesetup/Controls/GameSettingsControl.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/gamesetup/Controls/GameSettingsControl.js
/** | /** | ||||
* This class provides a property independent interface to g_GameAttributes events. | * This class provides a property independent interface to g_GameAttributes events. | ||||
* Classes may use this interface in order to react to changing g_GameAttributes. | * Classes may use this interface in order to react to changing g_GameAttributes. | ||||
*/ | */ | ||||
class GameSettingsControl | class GameSettingsControl | ||||
{ | { | ||||
constructor(setupWindow, netMessages, startGameControl, mapCache) | constructor(setupWindow, netMessages, startGameControl, mapCache) | ||||
{ | { | ||||
this.startGameControl = startGameControl; | this.startGameControl = startGameControl; | ||||
this.mapCache = mapCache; | this.mapCache = mapCache; | ||||
this.gameSettingsFile = new GameSettingsFile(setupWindow); | this.gameSettingsFile = new GameSettingsFile(setupWindow); | ||||
this.previousMap = undefined; | |||||
this.depth = 0; | this.depth = 0; | ||||
// This property may be read from publicly | // This property may be read from publicly | ||||
this.autostart = false; | this.autostart = false; | ||||
this.gameAttributesChangeHandlers = new Set(); | this.gameAttributesChangeHandlers = new Set(); | ||||
this.gameAttributesBatchChangeHandlers = new Set(); | this.gameAttributesBatchChangeHandlers = new Set(); | ||||
this.gameAttributesFinalizeHandlers = new Set(); | this.gameAttributesFinalizeHandlers = new Set(); | ||||
this.pickRandomItemsHandlers = new Set(); | this.pickRandomItemsHandlers = new Set(); | ||||
this.assignPlayerHandlers = new Set(); | this.assignPlayerHandlers = new Set(); | ||||
this.mapChangeHandlers = new Set(); | |||||
setupWindow.registerLoadHandler(this.onLoad.bind(this)); | setupWindow.registerLoadHandler(this.onLoad.bind(this)); | ||||
setupWindow.registerGetHotloadDataHandler(this.onGetHotloadData.bind(this)); | setupWindow.registerGetHotloadDataHandler(this.onGetHotloadData.bind(this)); | ||||
startGameControl.registerLaunchGameHandler(this.onLaunchGame.bind(this)); | startGameControl.registerLaunchGameHandler(this.onLaunchGame.bind(this)); | ||||
if (g_IsNetworked) | if (g_IsNetworked) | ||||
netMessages.registerNetMessageHandler("gamesetup", this.onGamesetupMessage.bind(this)); | 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. | * This message is triggered everytime g_GameAttributes change. | ||||
* Handlers may subsequently change g_GameAttributes and trigger this message again. | * Handlers may subsequently change g_GameAttributes and trigger this message again. | ||||
*/ | */ | ||||
registerGameAttributesChangeHandler(handler) | registerGameAttributesChangeHandler(handler) | ||||
{ | { | ||||
this.gameAttributesChangeHandlers.add(handler); | this.gameAttributesChangeHandlers.add(handler); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 120 Lines • ▼ Show 20 Lines | // Basic sanitization | ||||
if (!g_GameAttributes.settings.PlayerData) | if (!g_GameAttributes.settings.PlayerData) | ||||
g_GameAttributes.settings.PlayerData = new Array(this.DefaultPlayerCount); | g_GameAttributes.settings.PlayerData = new Array(this.DefaultPlayerCount); | ||||
for (let i = 0; i < g_GameAttributes.settings.PlayerData.length; ++i) | for (let i = 0; i < g_GameAttributes.settings.PlayerData.length; ++i) | ||||
if (!g_GameAttributes.settings.PlayerData[i]) | if (!g_GameAttributes.settings.PlayerData[i]) | ||||
g_GameAttributes.settings.PlayerData[i] = {}; | 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); | |||||
} | |||||
elexis: This mapChange move can be committed separately, has the purpose of actually doing what the… | |||||
Done Inline ActionsI 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: I can't reproduce it anymore, the code still seems to have that bug, it might be that it… | |||||
for (let handler of this.gameAttributesChangeHandlers) | for (let handler of this.gameAttributesChangeHandlers) | ||||
handler(); | handler(); | ||||
--this.depth; | --this.depth; | ||||
if (this.depth == 0) | if (this.depth == 0) | ||||
{ | { | ||||
for (let handler of this.gameAttributesBatchChangeHandlers) | for (let handler of this.gameAttributesBatchChangeHandlers) | ||||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
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).