Differential D4240 Diff 19682 ps/trunk/binaries/data/mods/public/gui/gamesettings/attributes/PlayerName.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/gamesettings/attributes/PlayerName.js
/** | /** | ||||
* Stores in-game names for all players. | * Stores in-game names for all players. | ||||
* | * | ||||
* NB: the regular gamesetup has a particular handling of this setting. | * NB: the regular gamesetup has a particular handling of this setting. | ||||
* The names are loaded from the map, but the GUI also show playernames | * The names are loaded from the map, but the GUI also show playernames. | ||||
* and forces them when starting the game. | * Force these at the start of the match. | ||||
* This is therefore just handling map-defined names & AI random bot names. | |||||
*/ | */ | ||||
GameSettings.prototype.Attributes.PlayerName = class PlayerName extends GameSetting | GameSettings.prototype.Attributes.PlayerName = class PlayerName extends GameSetting | ||||
{ | { | ||||
init() | init() | ||||
{ | { | ||||
// NB: watchers aren't auto-triggered when modifying array elements. | // NB: watchers aren't auto-triggered when modifying array elements. | ||||
this.values = []; | this.values = []; | ||||
this.settings.playerCount.watch(() => this.maybeUpdate(), ["nbPlayers"]); | this.settings.playerCount.watch(() => this.maybeUpdate(), ["nbPlayers"]); | ||||
this.settings.map.watch(() => this.onMapChange(), ["map"]); | this.settings.map.watch(() => this.onMapChange(), ["map"]); | ||||
} | } | ||||
toInitAttributes(attribs) | toInitAttributes(attribs) | ||||
{ | { | ||||
if (!attribs.settings.PlayerData) | if (!attribs.settings.PlayerData) | ||||
attribs.settings.PlayerData = []; | attribs.settings.PlayerData = []; | ||||
while (attribs.settings.PlayerData.length < this.values.length) | while (attribs.settings.PlayerData.length < this.values.length) | ||||
attribs.settings.PlayerData.push({}); | attribs.settings.PlayerData.push({}); | ||||
for (let i in this.values) | for (let i in this.values) | ||||
if (this.values[i]) | if (this.values[i]) | ||||
attribs.settings.PlayerData[i].Name = this.values[i]; | attribs.settings.PlayerData[i].Name = this.values[i]; | ||||
} | } | ||||
fromInitAttributes(attribs) | |||||
{ | |||||
if (!this.getLegacySetting(attribs, "PlayerData")) | |||||
return; | |||||
const pData = this.getLegacySetting(attribs, "PlayerData"); | |||||
if (this.values.length < pData.length) | |||||
this._resize(pData.length); | |||||
for (const i in pData) | |||||
if (pData[i] && pData[i].Name !== undefined) | |||||
{ | |||||
this.values[i] = pData[i].Name; | |||||
this.trigger("values"); | |||||
} | |||||
} | |||||
_resize(nb) | _resize(nb) | ||||
{ | { | ||||
while (this.values.length > nb) | while (this.values.length > nb) | ||||
this.values.pop(); | this.values.pop(); | ||||
while (this.values.length < nb) | while (this.values.length < nb) | ||||
this.values.push(undefined); | this.values.push(undefined); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | for (let i in this.values) | ||||
}) : | }) : | ||||
chosenName; | chosenName; | ||||
} | } | ||||
if (picked) | if (picked) | ||||
this.trigger("values"); | this.trigger("values"); | ||||
return picked; | return picked; | ||||
} | } | ||||
onFinalizeAttributes(attribs, playerAssignments) | |||||
{ | |||||
// Replace client player names with the real players. | |||||
for (const guid in playerAssignments) | |||||
if (playerAssignments[guid].player !== -1) | |||||
attribs.settings.PlayerData[playerAssignments[guid].player -1].Name = playerAssignments[guid].name; | |||||
} | |||||
_getMapData(i) | _getMapData(i) | ||||
{ | { | ||||
let data = this.settings.map.data; | let data = this.settings.map.data; | ||||
if (!data || !data.settings || !data.settings.PlayerData) | if (!data || !data.settings || !data.settings.PlayerData) | ||||
return undefined; | return undefined; | ||||
if (data.settings.PlayerData.length <= i) | if (data.settings.PlayerData.length <= i) | ||||
return undefined; | return undefined; | ||||
return data.settings.PlayerData[i].Name; | return data.settings.PlayerData[i].Name; | ||||
Show All 14 Lines |
Wildfire Games · Phabricator