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; | |||||
/** | |||||
* Color used for buddy info sender in chat. | |||||
*/ | |||||
var g_BuddyInfoColor = "255 128 255"; | |||||
/** | |||||
* 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 801 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({ | |||||
"from": "buddyinfo", | |||||
"text": sprintf( | |||||
translate("%(buddy)s has joined game %(game)s."), | |||||
{"buddy": '[color="' + getPlayerColor(nickName) + '"]' + | |||||
g_BuddySymbol + " " + nickName + '[/color]', | |||||
"game": '[color="' + g_GameColors[game.state] + '"]' + g_BuddySymbol + " " + game.name + '[/color]'} | |||||
)} | |||||
); | |||||
} | |||||
// 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 333 Lines • ▼ Show 20 Lines | |||||
* | * | ||||
* @param {Object} msg - Received chat message. | * @param {Object} msg - Received chat message. | ||||
* @returns {string} - Formatted text. | * @returns {string} - Formatted text. | ||||
*/ | */ | ||||
function ircFormat(msg) | function ircFormat(msg) | ||||
{ | { | ||||
let formattedMessage = ""; | let formattedMessage = ""; | ||||
let coloredFrom = msg.from && colorPlayerName(msg.from); | let coloredFrom = msg.from && colorPlayerName(msg.from); | ||||
if (msg.from && msg.from == "buddyinfo") | |||||
coloredFrom = '[color="' + g_BuddyInfoColor + '"]' + translate("Buddy") + '[/color]'; | |||||
// Handle commands allowed past handleChatCommand. | // Handle commands allowed past handleChatCommand. | ||||
if (msg.text[0] == '/') | if (msg.text[0] == '/') | ||||
{ | { | ||||
let [command, message] = ircSplit(msg.text); | let [command, message] = ircSplit(msg.text); | ||||
switch (command) | switch (command) | ||||
{ | { | ||||
case "me": | case "me": | ||||
▲ Show 20 Lines • Show All 151 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator