Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/gamesettings/GameSettings.js
Show All 31 Lines | init(mapCache) | ||||
for (let comp in GameSettings.prototype.Attributes) | for (let comp in GameSettings.prototype.Attributes) | ||||
{ | { | ||||
let name = comp[0].toLowerCase() + comp.substr(1); | let name = comp[0].toLowerCase() + comp.substr(1); | ||||
if (name in this) | if (name in this) | ||||
error("Game Settings attribute '" + name + "' is already used."); | error("Game Settings attribute '" + name + "' is already used."); | ||||
this[name] = new GameSettings.prototype.Attributes[comp](this); | this[name] = new GameSettings.prototype.Attributes[comp](this); | ||||
} | } | ||||
for (let comp in this) | for (let comp in this) | ||||
if (this[comp].init) | |||||
this[comp].init(); | this[comp].init(); | ||||
wraitii: I'm not sure this is better than the current code, and it makes the diff un-necessarily large. | |||||
return this; | return this; | ||||
} | } | ||||
/** | /** | ||||
* 'Serialize' the settings into the InitAttributes format, | * 'Serialize' the settings into the InitAttributes format, | ||||
* which can then be saved as JSON. | * which can then be saved as JSON. | ||||
* Used to set the InitAttributes, for network synching, for hotloading & for persistence. | * Used to set the InitAttributes, for network synching, for hotloading & for persistence. | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | class GameSettings | ||||
* This is here because there's limited value in having a separate folder/file for it, | * This is here because there's limited value in having a separate folder/file for it, | ||||
* since you'll need a GameSettings object anyways. | * since you'll need a GameSettings object anyways. | ||||
* @param playerAssignments - A dict of 'local'/GUID per player and their name/slot. | * @param playerAssignments - A dict of 'local'/GUID per player and their name/slot. | ||||
*/ | */ | ||||
launchGame(playerAssignments) | launchGame(playerAssignments) | ||||
{ | { | ||||
this.pickRandomItems(); | this.pickRandomItems(); | ||||
Engine.SetRankedGame(this.rating.enabled); | // Let the settings finalize themselves. Let them do anything they need to do before the | ||||
// game starts and set any value in the attributes which mustn't be persisted. | |||||
const attribs = this.toInitAttributes(); | |||||
for (const comp in this) | |||||
if (this[comp].onFinalizeAttributes) | |||||
this[comp].onFinalizeAttributes(attribs, playerAssignments); | |||||
// Replace player names with the real players. | Object.defineProperty(this, "finalizedAttributes", { | ||||
for (let guid in playerAssignments) | "value": attribs | ||||
Not Done Inline Actionsjust out of niceness you should make this non-writable / freeze it. That being said, I think my preference would actually be to call a C++ function to get the actual, proper finalised attributes instead of a JS copy of it that may-or-may-not be accurate. This seems to only be actually used for the campaign switch to the loading page, which totally could use such a C++ function instead. wraitii: just out of niceness you should make this non-writable / freeze it.
That being said, I think… | |||||
Done Inline Actionsit is already non-writable is it? Moving to cpp means extra cpp/js conversions bb: it is already non-writable is it?
Moving to cpp means extra cpp/js conversions | |||||
if (playerAssignments[guid].player !== -1) | }); | ||||
this.playerName.values[playerAssignments[guid].player -1] = playerAssignments[guid].name; | |||||
// NB: for multiplayer support, the clients must be listening to "start" net messages. | // NB: for multiplayer support, the clients must be listening to "start" net messages. | ||||
if (this.isNetworked) | if (this.isNetworked) | ||||
Engine.StartNetworkGame(this.toInitAttributes()); | Engine.StartNetworkGame(this.finalizedAttributes); | ||||
else | else | ||||
Engine.StartGame(this.toInitAttributes(), playerAssignments.local.player); | Engine.StartGame(this.finalizedAttributes, playerAssignments.local.player); | ||||
} | } | ||||
} | } | ||||
Object.defineProperty(GameSettings.prototype, "Attributes", { | Object.defineProperty(GameSettings.prototype, "Attributes", { | ||||
"value": {}, | "value": {}, | ||||
"enumerable": false, | "enumerable": false, | ||||
"writable": true, | "writable": true, | ||||
}); | }); |
Wildfire Games · Phabricator
I'm not sure this is better than the current code, and it makes the diff un-necessarily large.