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.
Details
- Reviewers
- None
- Commits
- rP23434: Gamestup option to select the time the sea level starts to rise on Extinct…
- Trac Tickets
- #4838
Diff Detail
- Repository
- rP 0 A.D. Public Repository
- Branch
- /ps/trunk
- Lint
Lint OK - Unit
No Unit Test Coverage - Build Status
Buildable 10924 Build 19191: Vulcan Build Jenkins Build 19190: Vulcan Build (macOS) Jenkins Build 19189: Vulcan Build (Windows) Jenkins Build 19188: arc lint + arc unit
Event Timeline
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). |
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
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(); |