Differential D4039 Diff 17917 ps/trunk/binaries/data/mods/public/gui/gamesetup/Controllers/GameSettingsController.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/gamesetup/Controllers/GameSettingsController.js
Show All 17 Lines | constructor(setupWindow, netMessages, playerAssignmentsController, mapCache) | ||||
// If this is true, the ready controller won't reset readiness. | // If this is true, the ready controller won't reset readiness. | ||||
// TODO: ideally the ready controller would be somewhat independent from this one, | // TODO: ideally the ready controller would be somewhat independent from this one, | ||||
// possibly by listening to gamesetup messages itself. | // possibly by listening to gamesetup messages itself. | ||||
this.gameStarted = false; | this.gameStarted = false; | ||||
this.updateLayoutHandlers = new Set(); | this.updateLayoutHandlers = new Set(); | ||||
this.settingsChangeHandlers = new Set(); | this.settingsChangeHandlers = new Set(); | ||||
this.loadingChangeHandlers = new Set(); | this.loadingChangeHandlers = new Set(); | ||||
this.settingsLoadedHandlers = 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)); | ||||
setupWindow.registerClosePageHandler(this.onClose.bind(this)); | setupWindow.registerClosePageHandler(this.onClose.bind(this)); | ||||
if (g_IsNetworked) | if (g_IsNetworked) | ||||
{ | { | ||||
Show All 27 Lines | class GameSettingsController | ||||
/** | /** | ||||
* @param handler will be called when the 'loading' state change. | * @param handler will be called when the 'loading' state change. | ||||
*/ | */ | ||||
registerLoadingChangeHandler(handler) | registerLoadingChangeHandler(handler) | ||||
{ | { | ||||
this.loadingChangeHandlers.add(handler); | this.loadingChangeHandlers.add(handler); | ||||
} | } | ||||
/** | |||||
* @param handler will be called when the initial settings have been loaded. | |||||
*/ | |||||
registerSettingsLoadedHandler(handler) | |||||
{ | |||||
this.settingsLoadedHandlers.add(handler); | |||||
} | |||||
onLoad(initData, hotloadData) | onLoad(initData, hotloadData) | ||||
{ | { | ||||
if (hotloadData) | if (hotloadData) | ||||
this.parseSettings(hotloadData.initAttributes); | this.parseSettings(hotloadData.initAttributes); | ||||
else if (g_IsController && this.persistentMatchSettings.enabled) | else if (g_IsController && (initData?.gameSettings || this.persistentMatchSettings.enabled)) | ||||
{ | { | ||||
let settings = this.persistentMatchSettings.loadFile(); | // Allow opting-in to persistence when sending initial data (though default off) | ||||
if (initData?.gameSettings) | |||||
this.persistentMatchSettings.enabled = !!initData.gameSettings?.usePersistence; | |||||
const settings = initData?.gameSettings || this.persistentMatchSettings.loadFile(); | |||||
if (settings) | if (settings) | ||||
{ | |||||
this.parseSettings(settings); | this.parseSettings(settings); | ||||
} | |||||
// If the new settings led to AI & players conflict, remove the AI. | // If the new settings led to AI & players conflict, remove the AI. | ||||
for (let guid in g_PlayerAssignments) | for (const guid in g_PlayerAssignments) | ||||
if (g_PlayerAssignments[guid].player !== -1 && | if (g_PlayerAssignments[guid].player !== -1 && | ||||
g_GameSettings.playerAI.get(g_PlayerAssignments[guid].player - 1)) | g_GameSettings.playerAI.get(g_PlayerAssignments[guid].player - 1)) | ||||
g_GameSettings.playerAI.set(g_PlayerAssignments[guid].player - 1, undefined); | g_GameSettings.playerAI.set(g_PlayerAssignments[guid].player - 1, undefined); | ||||
} | |||||
} | for (const handler of this.settingsLoadedHandlers) | ||||
handler(); | |||||
this.updateLayout(); | this.updateLayout(); | ||||
this.setNetworkInitAttributes(); | this.setNetworkInitAttributes(); | ||||
// If we are the controller, we are done loading. | // If we are the controller, we are done loading. | ||||
if (hotloadData || !g_IsNetworked || g_IsController) | if (hotloadData || !g_IsNetworked || g_IsController) | ||||
this.setLoading(false); | this.setLoading(false); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 198 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator