Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/lobby/lobby.js
Show First 20 Lines • Show All 85 Lines • ▼ Show 20 Lines | |||||
var g_UserRating = ""; | var g_UserRating = ""; | ||||
/** | /** | ||||
* All games currently running. | * All games currently running. | ||||
*/ | */ | ||||
var g_GameList = {}; | var g_GameList = {}; | ||||
/** | /** | ||||
* All games where buddy joined. | |||||
*/ | |||||
var g_BuddyGames = undefined; | |||||
/** | |||||
* Used to restore the selection after updating the playerlist. | * Used to restore the selection after updating the playerlist. | ||||
*/ | */ | ||||
var g_SelectedPlayer = ""; | var g_SelectedPlayer = ""; | ||||
/** | /** | ||||
* Used to restore the selection after updating the gamelist. | * Used to restore the selection after updating the gamelist. | ||||
*/ | */ | ||||
var g_SelectedGameIP = ""; | var g_SelectedGameIP = ""; | ||||
▲ Show 20 Lines • Show All 797 Lines • ▼ Show 20 Lines | function updateGameList() | ||||
let sortOrder = gamesBox.selected_column_order; | let sortOrder = gamesBox.selected_column_order; | ||||
if (gamesBox.selected > -1) | if (gamesBox.selected > -1) | ||||
{ | { | ||||
g_SelectedGameIP = g_GameList[gamesBox.selected].ip; | g_SelectedGameIP = g_GameList[gamesBox.selected].ip; | ||||
g_SelectedGamePort = g_GameList[gamesBox.selected].port; | g_SelectedGamePort = g_GameList[gamesBox.selected].port; | ||||
} | } | ||||
if (g_BuddyGames) | |||||
g_BuddyGames.stillRunning = !g_BuddyGames.stillRunning; | |||||
g_GameList = Engine.GetGameList().map(game => { | g_GameList = Engine.GetGameList().map(game => { | ||||
game.hasBuddies = 0; | game.hasBuddies = 0; | ||||
// Compute average rating of participating players | // Compute average rating of participating players | ||||
let playerRatings = []; | let playerRatings = []; | ||||
let initBuddyGames = !g_BuddyGames; | |||||
if (initBuddyGames) | |||||
g_BuddyGames = {"games": [], "stillRunning": true}; | |||||
if (!g_BuddyGames.games[game]) | |||||
g_BuddyGames.games[game] = {"running": g_BuddyGames.stillRunning, "buddies": []}; | |||||
else | |||||
g_BuddyGames.games[game].running = g_BuddyGames.stillRunning; | |||||
for (let player of stringifiedTeamListToPlayerData(game.players)) | for (let player of stringifiedTeamListToPlayerData(game.players)) | ||||
{ | { | ||||
let [nick, rating] = splitRatingFromNick(player.Name); | let [nick, rating] = splitRatingFromNick(player.Name); | ||||
if (player.Team != "observer") | if (player.Team != "observer") | ||||
playerRatings.push(rating || g_DefaultLobbyRating); | playerRatings.push(rating || g_DefaultLobbyRating); | ||||
if (g_Buddies.indexOf(nick) != -1 && | |||||
g_BuddyGames.games[game].buddies.indexOf(nick) == -1) | |||||
{ | |||||
g_BuddyGames.games[game].buddies.push(nick); | |||||
let nickName = (player.role && player.role == "moderator" ? g_ModeratorPrefix : "") + nick; | |||||
if (!initBuddyGames) | |||||
addChatMessage({ | |||||
"info": true, | |||||
"text": sprintf( | |||||
translate("%(buddy)s has joined game %(game)s."), | |||||
{"buddy": coloredText(g_BuddySymbol + " " + nickName, getPlayerColor(nickName)), | |||||
"game": coloredText(g_BuddySymbol + " " + game.name, g_GameColors[game.state])} | |||||
)} | |||||
); | |||||
} | |||||
// Sort games with playing buddies above games with spectating buddies | // 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(nick) != -1) | ||||
game.hasBuddies = player.Team == "observer" ? 1 : 2; | game.hasBuddies = player.Team == "observer" ? 1 : 2; | ||||
} | } | ||||
game.gameRating = | game.gameRating = | ||||
playerRatings.length ? | playerRatings.length ? | ||||
Math.round(playerRatings.reduce((sum, current) => sum + current) / playerRatings.length) : | Math.round(playerRatings.reduce((sum, current) => sum + current) / playerRatings.length) : | ||||
Show All 27 Lines | case 'nPlayers': | ||||
sortB = b.maxnbp; | sortB = b.maxnbp; | ||||
break; | break; | ||||
} | } | ||||
if (sortA < sortB) return -sortOrder; | if (sortA < sortB) return -sortOrder; | ||||
if (sortA > sortB) return +sortOrder; | if (sortA > sortB) return +sortOrder; | ||||
return 0; | return 0; | ||||
}); | }); | ||||
if (g_BuddyGames) | |||||
for (let game in g_BuddyGames.games) | |||||
if (g_BuddyGames.games[game].running != g_BuddyGames.stillRunning) | |||||
delete g_BuddyGames.games[game]; | |||||
let list_buddy = []; | let list_buddy = []; | ||||
let list_name = []; | let list_name = []; | ||||
let list_mapName = []; | let list_mapName = []; | ||||
let list_mapSize = []; | let list_mapSize = []; | ||||
let list_mapType = []; | let list_mapType = []; | ||||
let list_nPlayers = []; | let list_nPlayers = []; | ||||
let list_gameRating = []; | let list_gameRating = []; | ||||
let list = []; | let list = []; | ||||
▲ Show 20 Lines • Show All 394 Lines • ▼ Show 20 Lines | case "special": | ||||
}); | }); | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
default: | default: | ||||
return ""; | return ""; | ||||
} | } | ||||
} | } | ||||
else if (msg.info) | |||||
formattedMessage = sprintf(translate("* %(info)s"), { | |||||
"info": msg.text | |||||
}); | |||||
else | else | ||||
{ | { | ||||
let senderString; | let senderString; | ||||
// Translation: IRC message prefix. | // Translation: IRC message prefix. | ||||
if (msg.private) | if (msg.private) | ||||
senderString = sprintf(translateWithContext("lobby private message", "(%(private)s) <%(sender)s>"), { | senderString = sprintf(translateWithContext("lobby private message", "(%(private)s) <%(sender)s>"), { | ||||
"private": coloredText(translate("Private"), g_PrivateMessageColor), | "private": coloredText(translate("Private"), g_PrivateMessageColor), | ||||
▲ Show 20 Lines • Show All 90 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator