forked from 0ad/0ad
Use an object in splitRatingFromNick instead of an array and some cleanups
Patch By: ffffffff Differential Revision: https://code.wildfiregames.com/D1087 This was SVN commit r20675.
This commit is contained in:
parent
e0bd348bce
commit
7d7a4a6b14
@ -21,11 +21,7 @@ var g_BuddyListDelimiter = ",";
|
||||
function splitRatingFromNick(playerName)
|
||||
{
|
||||
let result = /^(\S+)\ \((\d+)\)$/g.exec(playerName);
|
||||
|
||||
if (!result)
|
||||
return [playerName, ""];
|
||||
|
||||
return [result[1], +result[2]];
|
||||
return { "nick": result ? result[1] : playerName, "rating": result ? +result[2] : "" };
|
||||
}
|
||||
|
||||
/**
|
||||
@ -152,13 +148,14 @@ function formatPlayerInfo(playerDataArray, playerStates)
|
||||
if (!playerDescriptions[teamIdx])
|
||||
playerDescriptions[teamIdx] = [];
|
||||
|
||||
let playerNick = splitRatingFromNick(playerData.Name).nick;
|
||||
playerDescriptions[teamIdx].push(sprintf(playerDescription, {
|
||||
"playerName":
|
||||
coloredText(
|
||||
(g_Buddies.indexOf(splitRatingFromNick(playerData.Name)[0]) != -1 ? g_BuddySymbol + " " : "") +
|
||||
(g_Buddies.indexOf(playerNick) != -1 ? g_BuddySymbol + " " : "") +
|
||||
escapeText(playerData.Name),
|
||||
(typeof getPlayerColor == 'function' ?
|
||||
(isAI ? "white" : getPlayerColor(splitRatingFromNick(playerData.Name)[0])) :
|
||||
(isAI ? "white" : getPlayerColor(playerNick)) :
|
||||
rgbToGuiColor(playerData.Color || g_Settings.PlayerDefaults[playerIdx].Color))),
|
||||
|
||||
"civ":
|
||||
|
@ -1375,7 +1375,7 @@ function onClientJoin(newGUID, newAssignments)
|
||||
{
|
||||
let assignOption = Engine.ConfigDB_GetValue("user", "gui.gamesetup.assignplayers");
|
||||
if (assignOption == "disabled" ||
|
||||
assignOption == "buddies" && g_Buddies.indexOf(splitRatingFromNick(playername)[0]) == -1)
|
||||
assignOption == "buddies" && g_Buddies.indexOf(splitRatingFromNick(playername).nick) == -1)
|
||||
return;
|
||||
}
|
||||
|
||||
@ -2261,7 +2261,7 @@ function addChatMessage(msg)
|
||||
{
|
||||
let userName = g_PlayerAssignments[Engine.GetPlayerGUID()].name;
|
||||
if (userName != g_PlayerAssignments[msg.guid].name &&
|
||||
msg.text.toLowerCase().indexOf(splitRatingFromNick(userName)[0].toLowerCase()) != -1)
|
||||
msg.text.toLowerCase().indexOf(splitRatingFromNick(userName).nick.toLowerCase()) != -1)
|
||||
soundNotification("nick");
|
||||
}
|
||||
|
||||
|
@ -716,8 +716,7 @@ function selectGameFromPlayername()
|
||||
for (let i = 0; i < g_GameList.length; ++i)
|
||||
for (let player of stringifiedTeamListToPlayerData(g_GameList[i].players))
|
||||
{
|
||||
let nick = splitRatingFromNick(player.Name)[0];
|
||||
if (g_SelectedPlayer != nick)
|
||||
if (g_SelectedPlayer != splitRatingFromNick(player.Name).nick)
|
||||
continue;
|
||||
|
||||
if (player.Team == "observer")
|
||||
@ -913,13 +912,13 @@ function updateGameList()
|
||||
|
||||
for (let player of stringifiedTeamListToPlayerData(game.players))
|
||||
{
|
||||
let [nick, rating] = splitRatingFromNick(player.Name);
|
||||
let playerNickRating = splitRatingFromNick(player.Name);
|
||||
|
||||
if (player.Team != "observer")
|
||||
playerRatings.push(rating || g_DefaultLobbyRating);
|
||||
playerRatings.push(playerNickRating.rating || g_DefaultLobbyRating);
|
||||
|
||||
// Sort games with playing buddies above games with spectating buddies
|
||||
if (game.hasBuddies < 2 && g_Buddies.indexOf(nick) != -1)
|
||||
if (game.hasBuddies < 2 && g_Buddies.indexOf(playerNickRating.nick) != -1)
|
||||
game.hasBuddies = player.Team == "observer" ? 1 : 2;
|
||||
}
|
||||
|
||||
@ -1144,9 +1143,9 @@ function getRejoinRating(game)
|
||||
{
|
||||
for (let player of stringifiedTeamListToPlayerData(game.players))
|
||||
{
|
||||
let [nick, rating] = splitRatingFromNick(player.Name);
|
||||
if (nick == g_Username)
|
||||
return rating;
|
||||
let playerNickRating = splitRatingFromNick(player.Name);
|
||||
if (playerNickRating.nick == g_Username)
|
||||
return playerNickRating.rating;
|
||||
}
|
||||
return g_UserRating;
|
||||
}
|
||||
|
@ -1107,7 +1107,7 @@ function formatChatCommand(msg)
|
||||
|
||||
let userName = g_PlayerAssignments[Engine.GetPlayerGUID()].name;
|
||||
if (userName != g_PlayerAssignments[msg.guid].name &&
|
||||
msg.text.toLowerCase().indexOf(splitRatingFromNick(userName)[0].toLowerCase()) != -1)
|
||||
msg.text.toLowerCase().indexOf(splitRatingFromNick(userName).nick.toLowerCase()) != -1)
|
||||
soundNotification("nick");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user