Differential D3711 Diff 16562 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
Show All 36 Lines | class GameSettingsControl | ||||
registerSettingsChangeHandler(handler) | registerSettingsChangeHandler(handler) | ||||
{ | { | ||||
this.settingsChangeHandlers.add(handler); | this.settingsChangeHandlers.add(handler); | ||||
} | } | ||||
onLoad(initData, hotloadData) | onLoad(initData, hotloadData) | ||||
{ | { | ||||
if (hotloadData) | if (hotloadData) | ||||
this.parseSettings(hotloadData.gameAttributes); | this.parseSettings(hotloadData.initAttributes); | ||||
else if (g_IsController && this.gameSettingsFile.enabled) | else if (g_IsController && this.gameSettingsFile.enabled) | ||||
{ | { | ||||
let settings = this.gameSettingsFile.loadFile(); | let settings = this.gameSettingsFile.loadFile(); | ||||
if (settings) | if (settings) | ||||
this.parseSettings(settings); | this.parseSettings(settings); | ||||
} | } | ||||
this.updateLayout(); | this.updateLayout(); | ||||
this.setNetworkGameAttributes(); | this.setNetworkInitAttributes(); | ||||
} | } | ||||
onClose() | onClose() | ||||
{ | { | ||||
this.gameSettingsFile.saveFile(); | this.gameSettingsFile.saveFile(); | ||||
} | } | ||||
onGetHotloadData(object) | onGetHotloadData(object) | ||||
{ | { | ||||
object.gameAttributes = this.getSettings(); | object.initAttributes = this.getSettings(); | ||||
} | } | ||||
onGamesetupMessage(message) | onGamesetupMessage(message) | ||||
{ | { | ||||
if (!message.data || g_IsController) | if (!message.data || g_IsController) | ||||
return; | return; | ||||
this.parseSettings(message.data); | this.parseSettings(message.data); | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | class GameSettingsControl | ||||
* This function is to be called when a GUI control has initiated a value change. | * This function is to be called when a GUI control has initiated a value change. | ||||
* | * | ||||
* To avoid an infinite loop, do not call this function when a game setup message was | * To avoid an infinite loop, do not call this function when a game setup message was | ||||
* received and the data had only been modified deterministically. | * received and the data had only been modified deterministically. | ||||
* | * | ||||
* This is run on a timer to avoid flooding the network with messages, | * This is run on a timer to avoid flooding the network with messages, | ||||
* e.g. when modifying a slider. | * e.g. when modifying a slider. | ||||
*/ | */ | ||||
setNetworkGameAttributes() | setNetworkInitAttributes() | ||||
{ | { | ||||
for (let handler of this.settingsChangeHandlers) | for (let handler of this.settingsChangeHandlers) | ||||
handler(); | handler(); | ||||
if (g_IsNetworked && this.timer === undefined) | if (g_IsNetworked && this.timer === undefined) | ||||
this.timer = setTimeout(this.setNetworkGameAttributesImmediately.bind(this), this.Timeout); | this.timer = setTimeout(this.setNetworkInitAttributesImmediately.bind(this), this.Timeout); | ||||
} | } | ||||
setNetworkGameAttributesImmediately() | setNetworkInitAttributesImmediately() | ||||
{ | { | ||||
if (this.timer) | if (this.timer) | ||||
{ | { | ||||
clearTimeout(this.timer); | clearTimeout(this.timer); | ||||
delete this.timer; | delete this.timer; | ||||
} | } | ||||
g_GameSettings.setNetworkGameAttributes(); | g_GameSettings.setNetworkInitAttributes(); | ||||
} | } | ||||
onLaunchGame() | onLaunchGame() | ||||
{ | { | ||||
// Save the file before random settings are resolved. | // Save the file before random settings are resolved. | ||||
this.gameSettingsFile.saveFile(); | this.gameSettingsFile.saveFile(); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Wait (at most) this many milliseconds before sending network messages. | * Wait (at most) this many milliseconds before sending network messages. | ||||
*/ | */ | ||||
GameSettingsControl.prototype.Timeout = 400; | GameSettingsControl.prototype.Timeout = 400; |
Wildfire Games · Phabricator