Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/common/gamedescription.js
Show All 10 Lines | |||||
/** | /** | ||||
* XEP-0172 doesn't restrict nicknames, but our lobby policy does. | * XEP-0172 doesn't restrict nicknames, but our lobby policy does. | ||||
* So use this human readable delimiter to separate buddy names in the config file. | * So use this human readable delimiter to separate buddy names in the config file. | ||||
*/ | */ | ||||
var g_BuddyListDelimiter = ","; | var g_BuddyListDelimiter = ","; | ||||
/** | /** | ||||
* Returns the nickname without the lobby rating. | * @Returns {object} containing the name and rating seperately. | ||||
*/ | */ | ||||
function splitRatingFromNick(playerName) | function splitRatingFromNick(playerName) | ||||
{ | { | ||||
let result = /^(\S+)\ \((\d+)\)$/g.exec(playerName); | let result = /^(\S+)\ \((\d+)\)$/g.exec(playerName); | ||||
return { "nick": result ? result[1] : playerName, "rating": result ? +result[2] : "" }; | return { "nick": result ? result[1] : playerName, "rating": result ? +result[2] : "" }; | ||||
} | } | ||||
/** | /** | ||||
* Array of playernames that the current user has marked as buddies. | * Array of playernames that the current user has marked as buddies. | ||||
*/ | */ | ||||
var g_Buddies = Engine.ConfigDB_GetValue("user", "lobby.buddies").split(g_BuddyListDelimiter); | var g_Buddies = Engine.ConfigDB_GetValue("user", "lobby.buddies").split(g_BuddyListDelimiter); | ||||
/** | /** | ||||
* Denotes which players are a lobby buddy of the current user. | * Denotes which players are a lobby buddy of the current user. | ||||
*/ | */ | ||||
var g_BuddySymbol = '•'; | var g_BuddySymbol = '★'; | ||||
/** | /** | ||||
* Returns a formatted string describing the player assignments. | * Returns a formatted string describing the player assignments. | ||||
* Needs g_CivData to translate! | * Needs g_CivData to translate! | ||||
* | * | ||||
Silier: please revert the one space addition | |||||
Done Inline ActionsSure, but why? Grapjas: Sure, but why? | |||||
Not Done Inline Actionsbecause there is mechanism called "blame" which tracks who changed line as the last and this is making harder to track relevant changes Silier: because there is mechanism called "blame" which tracks who changed line as the last and this is… | |||||
Done Inline ActionsI see what you mean, but isn't it wrong to have a leading space everywhere? Shouldn't it be fixed? Grapjas: I see what you mean, but isn't it wrong to have a leading space everywhere? Shouldn't it be… | |||||
* @param {Object} playerDataArray - As known from game setup and sim state. | * @param {Object} playerDataArray - As known from game setup and sim state. | ||||
* @param {(string[]|false)} playerStates - One of "won", "defeated", "active" for each player. | * @param {(string[]|false)} playerStates - One of "won", "defeated", "active" for each player. | ||||
* @returns {string} | * @returns {string} | ||||
*/ | */ | ||||
function formatPlayerInfo(playerDataArray, playerStates) | function formatPlayerInfo(playerDataArray, playerStates) | ||||
{ | { | ||||
let playerDescriptions = {}; | let playerDescriptions = {}; | ||||
let playerIdx = 0; | let playerIdx = 0; | ||||
Show All 11 Lines | for (let playerData of playerDataArray) | ||||
let playerDescription; | let playerDescription; | ||||
if (isAI) | if (isAI) | ||||
{ | { | ||||
if (playerData.Civ) | if (playerData.Civ) | ||||
{ | { | ||||
if (isActive) | if (isActive) | ||||
// Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu | // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu | ||||
playerDescription = translate("%(playerName)s (%(civ)s, %(AIdescription)s)"); | playerDescription = translate("%(status)s %(civ)s %(playerName)s (%(AIdescription)s)"); | ||||
else | else | ||||
// Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu | // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu | ||||
playerDescription = translate("%(playerName)s (%(civ)s, %(AIdescription)s, %(state)s)"); | playerDescription = translate("%(status)s %(civ)s %(state)s %(playerName)s (%(AIdescription)s)"); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
if (isActive) | if (isActive) | ||||
// Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu | // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu | ||||
playerDescription = translate("%(playerName)s (%(AIdescription)s)"); | playerDescription = translate("%(status)s %(playerName)s (%(AIdescription)s)"); | ||||
else | else | ||||
// Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu | // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu | ||||
playerDescription = translate("%(playerName)s (%(AIdescription)s, %(state)s)"); | playerDescription = translate("%(status)s %(state)s %(playerName)s (%(AIdescription)s)"); | ||||
} | } | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
if (playerData.Offline) | if (playerData.Offline) | ||||
{ | { | ||||
// Can only occur in the lobby for now, so no strings with civ needed | // Can only occur in the lobby for now. | ||||
if (isActive) | if (isActive) | ||||
// Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu | // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu | ||||
playerDescription = translate("%(playerName)s (OFFLINE)"); | playerDescription = "%(status)s %(civ)s %(playerName)s"; | ||||
else | else | ||||
// Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu | // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu | ||||
playerDescription = translate("%(playerName)s (OFFLINE, %(state)s)"); | playerDescription = "%(status)s %(civ)s %(state)s %(playerName)s"; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
if (playerData.Civ) | if (playerData.Civ) | ||||
if (isActive) | if (isActive) | ||||
// Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu | // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu | ||||
playerDescription = translate("%(playerName)s (%(civ)s)"); | playerDescription = "%(civ)s %(playerName)s"; | ||||
else | else | ||||
// Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu | // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu | ||||
playerDescription = translate("%(playerName)s (%(civ)s, %(state)s)"); | playerDescription = "%(civ)s %(state)s %(playerName)s"; | ||||
else | else | ||||
if (isActive) | if (isActive) | ||||
// Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu | // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu | ||||
playerDescription = translate("%(playerName)s"); | playerDescription = "%(playerName)s"; | ||||
else | else | ||||
// Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu | // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu | ||||
playerDescription = translate("%(playerName)s (%(state)s)"); | playerDescription = "%(state)s %(playerName)s"; | ||||
} | } | ||||
} | } | ||||
Not Done Inline ActionsI would cache this to variable splitRatingFromNick(playerData.Name) and then do .rating and .nick on that variable also let -> const on anything that will not be changed Silier: I would cache this to variable `splitRatingFromNick(playerData.Name)` and then do .rating and . | |||||
// Sort player descriptions by team | // Sort player descriptions by team | ||||
if (!playerDescriptions[teamIdx]) | if (!playerDescriptions[teamIdx]) | ||||
playerDescriptions[teamIdx] = []; | playerDescriptions[teamIdx] = []; | ||||
let playerNick = splitRatingFromNick(playerData.Name).nick; | let playerNick = splitRatingFromNick(playerData.Name).nick; | ||||
let playerRating = splitRatingFromNick(playerData.Name).rating; | |||||
playerRating ? playerRating = ' (' + coloredText(playerRating, PlayerColor.GetColorByRating(playerRating)) + ')' : playerRating = ""; | |||||
playerDescriptions[teamIdx].push(sprintf(playerDescription, { | playerDescriptions[teamIdx].push(sprintf(playerDescription, { | ||||
"playerName": | "playerName": | ||||
coloredText( | (g_Buddies.indexOf(playerNick) != -1 ? coloredText(g_BuddySymbol, "persiangreen") + " " : "") + | ||||
(g_Buddies.indexOf(playerNick) != -1 ? g_BuddySymbol + " " : "") + | coloredText(escapeText(playerNick), PlayerColor.ColorPlayerNameByRole(Engine.LobbyGetPlayerRole(playerNick))) + playerRating, | ||||
escapeText(playerData.Name), | |||||
(typeof getPlayerColor == 'function' ? | |||||
(isAI ? "white" : getPlayerColor(playerNick)) : | |||||
rgbToGuiColor(playerData.Color || g_Settings.PlayerDefaults[playerIdx].Color))), | |||||
Not Done Inline Actionsi think this should stay because colours are from the match Silier: i think this should stay because colours are from the match | |||||
Done Inline Actionsdon't understand what you mean, reword it. It colors player names in game details, which would only be white or purple as defined by playercolor function. Grapjas: don't understand what you mean, reword it. It colors player names in game details, which would… | |||||
"civ": | "civ": | ||||
!playerData.Civ ? | !playerData.Civ ? | ||||
translate("Unknown Civilization") : | translate("Unknown Civilization") : | ||||
g_CivData && g_CivData[playerData.Civ] && g_CivData[playerData.Civ].Name ? | g_CivData && g_CivData[playerData.Civ] && g_CivData[playerData.Civ].Name ? | ||||
translate(g_CivData[playerData.Civ].Name) : | '[icon="icon_' + playerData.Civ + '"]' : | ||||
playerData.Civ, | playerData.Civ, | ||||
"status": | |||||
isAI ? '[icon="icon_bot"]' : '[icon="icon_offline"]', | |||||
"state": | "state": | ||||
playerState == "defeated" ? | playerState == "defeated" ? | ||||
translateWithContext("playerstate", "defeated") : | '[icon="icon_defeated"]' : | ||||
translateWithContext("playerstate", "won"), | '[icon="icon_victorious"]', | ||||
"AIdescription": translateAISettings(playerData) | "AIdescription": coloredText(translateAISettings(playerData), "0 160 160") | ||||
})); | })); | ||||
} | } | ||||
let teams = Object.keys(playerDescriptions); | let teams = Object.keys(playerDescriptions); | ||||
if (teams.indexOf("observer") > -1) | if (teams.indexOf("observer") > -1) | ||||
teams.splice(teams.indexOf("observer"), 1); | teams.splice(teams.indexOf("observer"), 1); | ||||
let teamDescription = []; | let teamDescription = []; | ||||
// If there are no teams, merge all playersDescriptions | // If there are no teams, merge all playersDescriptions | ||||
if (teams.length == 1) | if (teams.length == 1) | ||||
teamDescription.push(playerDescriptions[teams[0]].join("\n")); | teamDescription.push(playerDescriptions[teams[0]].join("\n")); | ||||
// If there are teams, merge "Team N:" + playerDescriptions | // If there are teams, merge "Team N:" + playerDescriptions | ||||
else | else | ||||
teamDescription = teams.map(team => { | teamDescription = teams.map(team => { | ||||
let teamCaption = team == -1 ? | let teamCaption = team == -1 ? | ||||
translate("No Team") : | translate("No Team") : | ||||
sprintf(translate("Team %(team)s"), { "team": +team + 1 }); | sprintf(translate("Team %(team)s"), { "team": +team + 1 }); | ||||
// Translation: Describe players of one team in a selected game, f.e. in the replay- or savegame menu or lobby | // Translation: Describe players of one team in a selected game, f.e. in the replay- or savegame menu or lobby | ||||
return sprintf(translate("%(team)s:\n%(playerDescriptions)s"), { | return sprintf(translate("%(team)s:\n%(playerDescriptions)s"), { | ||||
"team": '[font="sans-bold-14"]' + teamCaption + "[/font]", | "team": setStringTags(teamCaption, GameDetails.prototype.CaptionTags), | ||||
"playerDescriptions": playerDescriptions[team].join("\n") | "playerDescriptions": playerDescriptions[team].join("\n") | ||||
}); | }); | ||||
}); | }); | ||||
if (playerDescriptions.observer) | if (playerDescriptions.observer) | ||||
teamDescription.push(sprintf(translate("%(team)s:\n%(playerDescriptions)s"), { | teamDescription.push(sprintf(translate("%(team)s:\n%(playerDescriptions)s"), { | ||||
"team": '[font="sans-bold-14"]' + translatePlural("Observer", "Observers", playerDescriptions.observer.length) + "[/font]", | "team": setStringTags(translatePlural("Observer", "Observers", playerDescriptions.observer.length), GameDetails.prototype.CaptionTags), | ||||
"playerDescriptions": playerDescriptions.observer.join("\n") | "playerDescriptions": playerDescriptions.observer.join("\n") | ||||
})); | })); | ||||
return teamDescription.join("\n\n"); | return teamDescription.join("\n\n"); | ||||
} | } | ||||
/** | /** | ||||
* Sets an additional map label, map preview image and describes the chosen game settings more closely. | * Sets an additional map label, map preview image and describes the chosen game settings more closely. | ||||
▲ Show 20 Lines • Show All 266 Lines • ▼ Show 20 Lines | function setOutcomeIcon(state, image) | ||||
} | } | ||||
} | } | ||||
function translateAISettings(playerData) | function translateAISettings(playerData) | ||||
{ | { | ||||
if (!playerData.AI) | if (!playerData.AI) | ||||
return ""; | return ""; | ||||
return sprintf(translate("%(AIdifficulty)s %(AIbehavior)s %(AIname)s"), { | return sprintf(translate("%(AIdifficulty)s"), { | ||||
"AIplayername": playerData.Name, | |||||
"AIname": translateAIName(playerData.AI), | "AIname": translateAIName(playerData.AI), | ||||
"AIdifficulty": translateAIDifficulty(playerData.AIDiff), | "AIdifficulty": translateAIDifficulty(playerData.AIDiff), | ||||
"AIbehavior": translateAIBehavior(playerData.AIBehavior), | "AIbehavior": translateAIBehavior(playerData.AIBehavior), | ||||
}); | }); | ||||
} | } |
Wildfire Games · Phabricator
please revert the one space addition