Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/gamesettings/GameSettings.js
/** | /** | ||||
* Data store for game settings. | * Data store for game settings. | ||||
* | * | ||||
* This is intended as a helper to create the settings object for a game. | * This is intended as a helper to create the settings object for a game. | ||||
* This object is referred to as: | * This object is referred to as: | ||||
* - g_GameAttributes in the GUI session context | * - g_InitAttributes in the GUI session context | ||||
* - InitAttributes in the JS simulation context | * - InitAttributes in the JS simulation context | ||||
* - Either InitAttributes or MapSettings in the C++ simulation. | * - Either InitAttributes or MapSettings in the C++ simulation. | ||||
* Settings can depend on each other, and the map provides many. | * Settings can depend on each other, and the map provides many. | ||||
* This class's job is thus to provide a simpler interface around that. | * This class's job is thus to provide a simpler interface around that. | ||||
*/ | */ | ||||
class GameSettings | class GameSettings | ||||
{ | { | ||||
init(mapCache) | init(mapCache) | ||||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | for (let comp in this) | ||||
if (this[comp].fromInitAttributes && | if (this[comp].fromInitAttributes && | ||||
comp !== "map" && comp !== "playerCount" && comp !== "victoryConditions") | comp !== "map" && comp !== "playerCount" && comp !== "victoryConditions") | ||||
this[comp].fromInitAttributes(attribs); | this[comp].fromInitAttributes(attribs); | ||||
} | } | ||||
/** | /** | ||||
* Send the game settings to the server. | * Send the game settings to the server. | ||||
*/ | */ | ||||
setNetworkGameAttributes() | setNetworkInitAttributes() | ||||
{ | { | ||||
if (this.isNetworked && this.isController) | if (this.isNetworked && this.isController) | ||||
Engine.SetNetworkGameAttributes(this.toInitAttributes()); | Engine.SendGameSetupMessage(this.toInitAttributes()); | ||||
} | } | ||||
/** | /** | ||||
* Change "random" settings into their proper settings. | * Change "random" settings into their proper settings. | ||||
*/ | */ | ||||
pickRandomItems() | pickRandomItems() | ||||
{ | { | ||||
let components = Object.keys(this); | let components = Object.keys(this); | ||||
Show All 19 Lines | class GameSettings | ||||
* 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); | Engine.SetRankedGame(this.rating.enabled); | ||||
this.setNetworkGameAttributes(); | this.setNetworkInitAttributes(); | ||||
// Replace player names with the real players. | // Replace player names with the real players. | ||||
for (let guid in playerAssignments) | for (let guid in playerAssignments) | ||||
if (playerAssignments[guid].player !== -1) | if (playerAssignments[guid].player !== -1) | ||||
this.playerName.values[playerAssignments[guid].player -1] = playerAssignments[guid].name; | 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) | ||||
Show All 11 Lines |
Wildfire Games · Phabricator