Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/lobby/lobby.js
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | |||||
var g_PlayerStatuses = { | var g_PlayerStatuses = { | ||||
"available": { "color": "0 219 0", "status": translate("Online") }, | "available": { "color": "0 219 0", "status": translate("Online") }, | ||||
"away": { "color": "229 76 13", "status": translate("Away") }, | "away": { "color": "229 76 13", "status": translate("Away") }, | ||||
"playing": { "color": "200 0 0", "status": translate("Busy") }, | "playing": { "color": "200 0 0", "status": translate("Busy") }, | ||||
"offline": { "color": "0 0 0", "status": translate("Offline") }, | "offline": { "color": "0 0 0", "status": translate("Offline") }, | ||||
"unknown": { "color": "178 178 178", "status": translateWithContext("lobby presence", "Unknown") } | "unknown": { "color": "178 178 178", "status": translateWithContext("lobby presence", "Unknown") } | ||||
}; | }; | ||||
/** | |||||
* Playerlist sort order array. | |||||
*/ | |||||
let g_PlayerListSort = []; | |||||
var g_RoleNames = { | var g_RoleNames = { | ||||
"moderator": translate("Moderator"), | "moderator": translate("Moderator"), | ||||
"participant": translate("Player"), | "participant": translate("Player"), | ||||
"visitor": translate("Muted Player") | "visitor": translate("Muted Player") | ||||
}; | }; | ||||
/** | /** | ||||
* Color for error messages in the chat. | * Color for error messages in the chat. | ||||
Show All 27 Lines | |||||
var g_UserRating = ""; | var g_UserRating = ""; | ||||
/** | /** | ||||
* All games currently running. | * All games currently running. | ||||
*/ | */ | ||||
var g_GameList = {}; | var g_GameList = {}; | ||||
/** | /** | ||||
* Gamelist sort order array. | |||||
*/ | |||||
let g_GameListSort = []; | |||||
/** | |||||
* 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 278 Lines • ▼ Show 20 Lines | function init(attribs) | ||||
{ | { | ||||
returnToMainMenu(); | returnToMainMenu(); | ||||
return; | return; | ||||
} | } | ||||
initMusic(); | initMusic(); | ||||
global.music.setState(global.music.states.MENU); | global.music.setState(global.music.states.MENU); | ||||
initSortOrder(); | |||||
initGameFilters(); | initGameFilters(); | ||||
Engine.LobbySetPlayerPresence("available"); | Engine.LobbySetPlayerPresence("available"); | ||||
// When rejoining the lobby after a game, we don't need to process presence changes | // When rejoining the lobby after a game, we don't need to process presence changes | ||||
Engine.LobbyClearPresenceUpdates(); | Engine.LobbyClearPresenceUpdates(); | ||||
updatePlayerList(); | updatePlayerList(); | ||||
updateSubject(Engine.LobbyGetRoomSubject()); | updateSubject(Engine.LobbyGetRoomSubject()); | ||||
updateLobbyColumns(); | updateLobbyColumns(); | ||||
updateToggleBuddy(); | updateToggleBuddy(); | ||||
Engine.GetGUIObjectByName("chatInput").tooltip = colorizeAutocompleteHotkey(); | Engine.GetGUIObjectByName("chatInput").tooltip = colorizeAutocompleteHotkey(); | ||||
// Get all messages since the login | // Get all messages since the login | ||||
for (let msg of Engine.LobbyGuiPollHistoricMessages()) | for (let msg of Engine.LobbyGuiPollHistoricMessages()) | ||||
g_NetMessageTypes[msg.type][msg.level](msg); | g_NetMessageTypes[msg.type][msg.level](msg); | ||||
} | } | ||||
function initSortOrder() | |||||
{ | |||||
g_GameListSort = Engine.ConfigDB_GetValue("user", "lobby.games.sortBy").split(g_ConfigListDelimiter); | |||||
g_PlayerListSort = Engine.ConfigDB_GetValue("user", "lobby.players.sortBy").split(g_ConfigListDelimiter); | |||||
Engine.GetGUIObjectByName("playersBox").selected_column = g_PlayerListSort[0] || "name"; | |||||
Engine.GetGUIObjectByName("gamesBox").selected_column = g_GameListSort[0] || "name"; | |||||
Engine.GetGUIObjectByName("playersBox").selected_column_order = Engine.ConfigDB_GetValue("user", "lobby.players.sortOrder") == "ascending" ? 1 : -1; | |||||
Engine.GetGUIObjectByName("gamesBox").selected_column_order = Engine.ConfigDB_GetValue("user", "lobby.games.sortOrder") == "ascending" ? 1 : -1; | |||||
} | |||||
function updateLobbyColumns() | function updateLobbyColumns() | ||||
{ | { | ||||
let gameRating = Engine.ConfigDB_GetValue("user", "lobby.columns.gamerating") == "true"; | let gameRating = Engine.ConfigDB_GetValue("user", "lobby.columns.gamerating") == "true"; | ||||
// Only show the selected columns | // Only show the selected columns | ||||
let gamesBox = Engine.GetGUIObjectByName("gamesBox"); | let gamesBox = Engine.GetGUIObjectByName("gamesBox"); | ||||
gamesBox.hidden_mapType = gameRating; | gamesBox.hidden_mapType = gameRating; | ||||
gamesBox.hidden_gameRating = !gameRating; | gamesBox.hidden_gameRating = !gameRating; | ||||
▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | function updateToggleBuddy() | ||||
let playerName = playerList.list[playerList.selected]; | let playerName = playerList.list[playerList.selected]; | ||||
let toggleBuddyButton = Engine.GetGUIObjectByName("toggleBuddyButton"); | let toggleBuddyButton = Engine.GetGUIObjectByName("toggleBuddyButton"); | ||||
toggleBuddyButton.caption = g_Buddies.indexOf(playerName) != -1 ? translate("Unmark as Buddy") : translate("Mark as Buddy"); | toggleBuddyButton.caption = g_Buddies.indexOf(playerName) != -1 ? translate("Unmark as Buddy") : translate("Mark as Buddy"); | ||||
toggleBuddyButton.enabled = playerName && playerName != g_Username; | toggleBuddyButton.enabled = playerName && playerName != g_Username; | ||||
} | } | ||||
/** | /** | ||||
* Align number to fixed digits (according to toFixed() function), but from the right digits to the left. | |||||
* It fills up front with zeros if necessary. | |||||
*/ | |||||
ffffffff: Maybe this function into somewhere common?
| |||||
function toLeftFixed(number, digits) | |||||
{ | |||||
return (Array(digits).join("0") + number).slice(-digits); | |||||
} | |||||
/** | |||||
* Update order of playerlist. Save it to config. | |||||
*/ | |||||
function updatePlayerListSortOrder(sortBy, sortOrder) | |||||
{ | |||||
if (sortBy != g_PlayerListSort[0]) | |||||
{ | |||||
while (g_PlayerListSort.lastIndexOf(sortBy) != -1) | |||||
g_PlayerListSort.splice(g_PlayerListSort.lastIndexOf(sortBy), 1); | |||||
g_PlayerListSort.unshift(sortBy); | |||||
setUserConfigValues("lobby.players.sortBy", g_PlayerListSort); | |||||
} | |||||
setUserConfigValues("lobby.players.sortOrder", [sortOrder == 1 ? "ascending" : "descending"]); | |||||
writeUserConfig(); | |||||
updatePlayerList(); | |||||
} | |||||
/** | |||||
Done Inline Actionsthis coming block is indent false will come correct in final diff if all finished ffffffff: this coming block is indent false will come correct in final diff if all finished | |||||
* Do a full update of the player listing, including ratings from cached C++ information. | * Do a full update of the player listing, including ratings from cached C++ information. | ||||
*/ | */ | ||||
function updatePlayerList() | function updatePlayerList() | ||||
{ | { | ||||
let playersBox = Engine.GetGUIObjectByName("playersBox"); | let playersBox = Engine.GetGUIObjectByName("playersBox"); | ||||
let sortBy = playersBox.selected_column || "name"; | let sortBy = playersBox.selected_column; | ||||
let sortOrder = playersBox.selected_column_order || 1; | let sortOrder = playersBox.selected_column_order; | ||||
Not Done Inline Actionsrid off not needed inline ffffffff: rid off not needed inline | |||||
let buddyStatusList = []; | let buddyStatusList = []; | ||||
let playerList = []; | let playerList = []; | ||||
let presenceList = []; | let presenceList = []; | ||||
let nickList = []; | let nickList = []; | ||||
let ratingList = []; | let ratingList = []; | ||||
let cleanPlayerList = Engine.GetPlayerList().map(player => { | let cleanPlayerList = [{name:"fpre", presence:"available", rating:"1700", role:"participant", isBuddy:false}, {name:"nigel87", presence:"available", rating:"1560", role:"participant", isBuddy:true}, {name:"phoenixdesk", presence:"available", rating:"1229", role:"participant", isBuddy:true}, {name:"Achelao", presence:"playing", rating:"1547", role:"participant", isBuddy:true}, {name:"borg-", presence:"playing", rating:"2159", role:"participant", isBuddy:true}, {name:"chrstgtr", presence:"playing", rating:"1641", role:"participant", isBuddy:true}, {name:"elexis", presence:"playing", rating:"", role:"moderator", isBuddy:true}, {name:"iApprove", presence:"playing", rating:"1464", role:"participant", isBuddy:true}, {name:"LeGenDz", presence:"playing", rating:"1471", role:"participant", isBuddy:true}, {name:"Pretension", presence:"playing", rating:"", role:"participant", isBuddy:true}, {name:"user1", presence:"playing", rating:"", role:"moderator", isBuddy:true}, {name:"fsvn", presence:"available", rating:"1175", role:"participant", isBuddy:false}, {name:"GoodBay", presence:"available", rating:"1135", role:"participant", isBuddy:false}, {name:"MadMeatBallMan", presence:"available", rating:"", role:"participant", isBuddy:false}, {name:"Ratings", presence:"available", rating:"", role:"moderator", isBuddy:false}, {name:"roxanne", presence:"available", rating:"909", role:"participant", isBuddy:false}, {name:"WFGbot", presence:"available", rating:"", role:"moderator", isBuddy:false}, {name:"ahmedteling", presence:"playing", rating:"1030", role:"participant", isBuddy:false}, {name:"Andresfcb2003", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"Bolvar", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"CaptIsler", presence:"playing", rating:"1100", role:"participant", isBuddy:false}, {name:"cleuberjs", presence:"playing", rating:"1064", role:"participant", isBuddy:false}, {name:"Crowley", presence:"playing", rating:"1135", role:"participant", isBuddy:false}, {name:"Emilio2006", presence:"playing", rating:"1089", role:"participant", isBuddy:false}, {name:"Ferhat_C", presence:"playing", rating:"961", role:"participant", isBuddy:false}, {name:"gaetheboss", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"good", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"HirnWolf", presence:"playing", rating:"1311", role:"participant", isBuddy:false}, {name:"iceblendedmocha", presence:"playing", rating:"1253", role:"participant", isBuddy:false}, {name:"imperator3", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"josavatar", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"K4OS", presence:"playing", rating:"1353", role:"participant", isBuddy:false}, {name:"kazutoo", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"Kuchen", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"Lombave", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"lucasbr788", presence:"playing", rating:"1202", role:"participant", isBuddy:false}, {name:"marciofly1", presence:"playing", rating:"1185", role:"participant", isBuddy:false}, {name:"markeloff_1.6", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"MTT123", presence:"playing", rating:"1283", role:"participant", isBuddy:false}, {name:"OutLander1", presence:"playing", rating:"1265", role:"participant", isBuddy:false}, {name:"outlander384", presence:"playing", rating:"1226", role:"participant", isBuddy:false}, {name:"Outlaw_7", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"Pale.May", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"playsofty", presence:"playing", rating:"1109", role:"participant", isBuddy:false}, {name:"protolich", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"Quicksilver", presence:"playing", rating:"1277", role:"participant", isBuddy:false}, {name:"Ragnark-", presence:"playing", rating:"1222", role:"participant", isBuddy:false}, {name:"Resul-55", presence:"playing", rating:"1335", role:"participant", isBuddy:false}, {name:"silius117", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"softcase", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"thatazoreanguy", presence:"playing", rating:"", role:"participant", isBuddy:false}, {name:"thered", presence:"playing", rating:"", role:"participant", isBuddy:false}].map(player => { | ||||
player.isBuddy = g_Buddies.indexOf(player.name) != -1; | player.isBuddy = g_Buddies.indexOf(player.name) != -1; | ||||
return player; | return player; | ||||
}).sort((a, b) => { | }).sort((a, b) => { | ||||
let sortA, sortB; | let sortA = ""; | ||||
let sortB = ""; | |||||
let statusOrder = Object.keys(g_PlayerStatuses); | let statusOrder = Object.keys(g_PlayerStatuses); | ||||
let statusA = statusOrder.indexOf(a.presence) + a.name.toLowerCase(); | let statusA = statusOrder.indexOf(a.presence) + a.name.toLowerCase(); | ||||
let statusB = statusOrder.indexOf(b.presence) + b.name.toLowerCase(); | let statusB = statusOrder.indexOf(b.presence) + b.name.toLowerCase(); | ||||
Not Done Inline Actionstesting ffffffff: testing | |||||
switch (sortBy) | for (let i = 0; i < g_PlayerListSort.length; i++) | ||||
switch (g_PlayerListSort[i]) | |||||
{ | { | ||||
case 'buddy': | case 'buddy': | ||||
sortA = (a.isBuddy ? 1 : 2) + statusA; | sortA += "" + (a.name.toLowerCase() == g_Username.toLowerCase() ? 1 : a.isBuddy ? 1 : 2); | ||||
sortB = (b.isBuddy ? 1 : 2) + statusB; | sortB += "" + (b.name.toLowerCase() == g_Username.toLowerCase() ? 1 : b.isBuddy ? 1 : 2); | ||||
break; | break; | ||||
case 'rating': | case 'rating': | ||||
sortA = +a.rating; | sortA += toLeftFixed(b.rating ? b.rating : 1, 6); | ||||
sortB = +b.rating; | sortB += toLeftFixed(a.rating ? a.rating : 1, 6); | ||||
break; | break; | ||||
case 'status': | case 'status': | ||||
sortA = statusA; | sortA += "" + statusOrder.indexOf(a.presence); | ||||
sortB = statusB; | sortB += "" + statusOrder.indexOf(b.presence); | ||||
break; | break; | ||||
case 'name': | case 'name': | ||||
default: | default: | ||||
sortA = a.name.toLowerCase(); | sortA += a.name.toLowerCase(); | ||||
sortB = b.name.toLowerCase(); | sortB += b.name.toLowerCase(); | ||||
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; | ||||
}); | }); | ||||
// Colorize list entries | // Colorize list entries | ||||
for (let player of cleanPlayerList) | for (let player of cleanPlayerList) | ||||
{ | { | ||||
Show All 24 Lines | |||||
/** | /** | ||||
* Toggle buddy state for a player in playerlist within the user config | * Toggle buddy state for a player in playerlist within the user config | ||||
*/ | */ | ||||
function toggleBuddy() | function toggleBuddy() | ||||
{ | { | ||||
let playerList = Engine.GetGUIObjectByName("playersBox"); | let playerList = Engine.GetGUIObjectByName("playersBox"); | ||||
let name = playerList.list[playerList.selected]; | let name = playerList.list[playerList.selected]; | ||||
if (!name || name == g_Username || name.indexOf(g_ConfigListDelimiter) != -1) | |||||
if (!name || name == g_Username || name.indexOf(g_BuddyListDelimiter) != -1) | |||||
return; | return; | ||||
let index = g_Buddies.indexOf(name); | let index = g_Buddies.indexOf(name); | ||||
if (index != -1) | if (index != -1) | ||||
g_Buddies.splice(index, 1); | g_Buddies.splice(index, 1); | ||||
else | else | ||||
g_Buddies.push(name); | g_Buddies.push(name); | ||||
updateToggleBuddy(); | updateToggleBuddy(); | ||||
// Don't save empty strings to the config file | setUserConfigValues("lobby.buddies", g_Buddies); | ||||
let buddies = g_Buddies.filter(nick => nick).join(g_BuddyListDelimiter) || g_BuddyListDelimiter; | writeUserConfig(); | ||||
Engine.ConfigDB_CreateValue("user", "lobby.buddies", buddies); | |||||
Engine.ConfigDB_WriteValueToFile("user", "lobby.buddies", buddies, "config/user.cfg"); | |||||
updatePlayerList(); | updatePlayerList(); | ||||
updateGameList(); | updateGameList(); | ||||
} | } | ||||
/** | /** | ||||
* Select the game where the selected player is currently playing, observing or offline. | * Select the game where the selected player is currently playing, observing or offline. | ||||
* Selects in that order to account for players that occur in multiple games. | * Selects in that order to account for players that occur in multiple games. | ||||
▲ Show 20 Lines • Show All 178 Lines • ▼ Show 20 Lines | function updateLeaderboard() | ||||
leaderboard.list_rank = list_rank; | leaderboard.list_rank = list_rank; | ||||
leaderboard.list = list; | leaderboard.list = list; | ||||
if (leaderboard.selected >= leaderboard.list.length) | if (leaderboard.selected >= leaderboard.list.length) | ||||
leaderboard.selected = -1; | leaderboard.selected = -1; | ||||
} | } | ||||
/** | /** | ||||
* Update sort order of gamelist. Save it to config. | |||||
*/ | |||||
function updateGameListSortOrder(sortBy, sortOrder) | |||||
{ | |||||
if (sortBy != g_GameListSort[0]) | |||||
{ | |||||
while (g_GameListSort.lastIndexOf(sortBy) != -1) | |||||
g_GameListSort.splice(g_GameListSort.lastIndexOf(sortBy), 1); | |||||
g_GameListSort.unshift(sortBy); | |||||
setUserConfigValues("lobby.games.sortBy", g_GameListSort); | |||||
} | |||||
setUserConfigValues("lobby.games.sortOrder", [sortOrder == 1 ? "ascending" : "descending"]); | |||||
writeUserConfig(); | |||||
applyFilters(); | |||||
} | |||||
/** | |||||
* Update the game listing from data cached in C++. | * Update the game listing from data cached in C++. | ||||
*/ | */ | ||||
function updateGameList() | function updateGameList() | ||||
{ | { | ||||
let gamesBox = Engine.GetGUIObjectByName("gamesBox"); | let gamesBox = Engine.GetGUIObjectByName("gamesBox"); | ||||
let sortBy = gamesBox.selected_column; | let sortBy = gamesBox.selected_column; | ||||
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; | ||||
} | } | ||||
g_GameList = Engine.GetGameList().map(game => { | g_GameList = [{name:"CaptIsler's game", ip:"69.79.227.33", port:"20595", stunIP:"69.79.227.33", stunPort:"20595", hostUsername:"CaptIsler", state:"waiting", nbp:"3", maxnbp:"4", players:"{\"0\":\\[{\"Name\":\"borg- (2159)\",\"Team\":0},{\"Name\":\"marciofly1 (1185)\",\"Team\":0}],\"1\":\\[{\"Name\":\"Andresfcb2003\",\"Team\":1},{\"Name\":\"delfinouno\",\"Team\":1,\"Offline\":true,\"State\":\"defeated\"}]}", mapName:"maps/random/mainland", niceMapName:"Mainland", mapSize:"384", mapType:"random", victoryCondition:"conquest", startTime:"1502491208", hasBuddies:0, gameRating:1171}, {name:"jjoin", ip:"88.232.31.170", port:"20595", stunIP:"", stunPort:"", hostUsername:"Resul-55", state:"waiting", nbp:"1", maxnbp:"4", players:"{\"0\":\\[{\"Name\":\"Resul-55 (1335)\",\"Team\":0,\"State\":\"defeated\"},{\"Name\":\"JordiStc2 (1157)\",\"Team\":0,\"Offline\":true,\"State\":\"defeated\"}],\"1\":\\[{\"Name\":\"Adrianoo (1132)\",\"Team\":1,\"Offline\":true,\"State\":\"won\"},{\"Name\":\"ElJaUnCa\",\"Team\":1,\"Offline\":true,\"State\":\"defeated\"}]}", mapName:"maps/skirmishes/Corinthian Isthmus (4)", niceMapName:"Corinthian Isthmus (4)", mapSize:"Default", mapType:"skirmish", victoryCondition:"conquest", startTime:"1502484628", hasBuddies:0, gameRating:1206}, {name:"1c1", ip:"73.191.6.77", port:"20595", stunIP:"73.191.6.77", stunPort:"20595", hostUsername:"protolich", state:"running", nbp:"2", maxnbp:"2", players:"{\"-1\":\\[{\"Name\":\"protolich\",\"Team\":-1},{\"Name\":\"outlander384 (1226)\",\"Team\":-1}]}", mapName:"maps/random/unknown_land", niceMapName:"Unknown Land", mapSize:"256", mapType:"random", victoryCondition:"conquest", startTime:"1502492620", hasBuddies:0, gameRating:1213}, {name:"2v2 3v3", ip:"80.142.22.43", port:"20595", stunIP:"80.142.22.43", stunPort:"20595", hostUsername:"Quicksilver", state:"running", nbp:"4", maxnbp:"4", players:"{\"0\":\\[{\"Name\":\"Quicksilver (1258)\",\"Team\":0},{\"Name\":\"K4OS (1353)\",\"Team\":0}],\"1\":\\[{\"Name\":\"MTT123 (1283)\",\"Team\":1},{\"Name\":\"markeloff_1.6\",\"Team\":1}],\"observer\":\\[{\"Name\":\"user1\",\"Team\":\"observer\"},{\"Name\":\"Achelao (1547)\",\"Team\":\"observer\"}]}", mapName:"maps/random/african_plains", niceMapName:"African Plains", mapSize:"256", mapType:"random", victoryCondition:"conquest", startTime:"1502493352", hasBuddies:1, gameRating:1274}, {name:"2vs2 for noobs", ip:"24.133.23.153", port:"20595", stunIP:"24.133.23.153", stunPort:"48043", hostUsername:"Ferhat_C", state:"running", nbp:"4", maxnbp:"4", players:"{\"0\":\\[{\"Name\":\"Ferhat_C (961)\",\"Team\":0},{\"Name\":\"softcase\",\"Team\":0}],\"1\":\\[{\"Name\":\"silius117\",\"Team\":1},{\"Name\":\"Ragnark- (1222)\",\"Team\":1}]}", mapName:"maps/random/mainland", niceMapName:"Mainland", mapSize:"256", mapType:"random", victoryCondition:"conquest", startTime:"1502493326", hasBuddies:0, gameRating:1146}, {name:"ahmedteling's game", ip:"197.2.63.204", port:"20595", stunIP:"197.2.63.204", stunPort:"20595", hostUsername:"ahmedteling", state:"running", nbp:"2", maxnbp:"2", players:"{\"0\":\\[{\"Name\":\"ahmedteling (1062)\",\"Team\":0}],\"1\":\\[{\"Name\":\"playsofty (1055)\",\"Team\":1}]}", mapName:"maps/random/empire", niceMapName:"Empire", mapSize:"320", mapType:"random", victoryCondition:"conquest", startTime:"1502493395", hasBuddies:0, gameRating:1059}, {name:"Crowley's game", ip:"5.146.195.89", port:"20595", stunIP:"5.146.195.89", stunPort:"23806", hostUsername:"Crowley", state:"running", nbp:"3", maxnbp:"5", players:"{\"0\":\\[{\"Name\":\"Crowley (1135)\",\"Team\":0},{\"Name\":\"OutLander1 (1265)\",\"Team\":0},{\"Name\":\"Kuchen\",\"Team\":0}],\"1\":\\[{\"Name\":\"Viriato\",\"Team\":1,\"AI\":\"petra\",\"AIDiff\":3},{\"Name\":\"Demosthenes\",\"Team\":1,\"AI\":\"petra\",\"AIDiff\":3}]}", mapName:"maps/random/island_stronghold", niceMapName:"Island Stronghold", mapSize:"384", mapType:"random", victoryCondition:"conquest_structures", startTime:"1502485786", hasBuddies:0, gameRating:1200}, {name:"Emilio2006's game", ip:"189.216.75.3", port:"20595", stunIP:"189.216.75.3", stunPort:"18583", hostUsername:"Emilio2006", state:"init", nbp:"2", maxnbp:"2", players:"{\"-1\":\\[{\"Name\":\"Emilio2006 (1089)\",\"Team\":-1},{\"Name\":\"iceblendedmocha (1253)\",\"Team\":-1}],\"observer\":\\[{\"Name\":\"imperator3\",\"Team\":\"observer\"}]}", mapName:"maps/random/cycladic_archipelago", niceMapName:"Cycladic Archipelago", mapSize:"256", mapType:"random", victoryCondition:"conquest", startTime:"1502494400", hasBuddies:0, gameRating:1171}, {name:"gaetheboss's game", ip:"85.69.131.38", port:"20595", stunIP:"85.69.131.38", stunPort:"20595", hostUsername:"gaetheboss", state:"running", nbp:"2", maxnbp:"4", players:"{\"0\":\\[{\"Name\":\"gaetheboss\",\"Team\":0},{\"Name\":\"Lombave\",\"Team\":0}],\"1\":\\[{\"Name\":\"Alcibiades\",\"Team\":1,\"AI\":\"petra\",\"AIDiff\":3},{\"Name\":\"Antiochus V Eupator\",\"Team\":1,\"AI\":\"petra\",\"AIDiff\":3}]}", mapName:"maps/skirmishes/Corinthian Isthmus (4)", niceMapName:"Corinthian Isthmus (4)", mapSize:"Default", mapType:"skirmish", victoryCondition:"conquest", startTime:"1502488118", hasBuddies:0, gameRating:1200}, {name:"HirnWolf's game", ip:"151.62.141.194", port:"20595", stunIP:"151.62.141.194", stunPort:"20595", hostUsername:"HirnWolf", state:"running", nbp:"4", maxnbp:"4", players:"{\"0\":\\[{\"Name\":\"HirnWolf (1311)\",\"Team\":0},{\"Name\":\"kazutoo\",\"Team\":0}],\"1\":\\[{\"Name\":\"lucasbr788 (1202)\",\"Team\":1},{\"Name\":\"cleuberjs (1064)\",\"Team\":1}]}", mapName:"maps/random/rivers", niceMapName:"Rivers", mapSize:"320", mapType:"random", victoryCondition:"conquest", startTime:"1502491882", hasBuddies:0, gameRating:1194}, {name:"Pale.May's game", ip:"85.242.180.216", port:"20595", stunIP:"85.242.180.216", stunPort:"20595", hostUsername:"Pale.May", state:"running", nbp:"2", maxnbp:"6", players:"{\"0\":\\[{\"Name\":\"Pale.May\",\"Team\":0},{\"Name\":\"thatazoreanguy\",\"Team\":0},{\"Name\":\"Darayavahush I\",\"Team\":0,\"AI\":\"petra\",\"AIDiff\":1}],\"1\":\\[{\"Name\":\"Viriato\",\"Team\":1,\"AI\":\"petra\",\"AIDiff\":1}],\"2\":\\[{\"Name\":\"Demosthenes\",\"Team\":2,\"AI\":\"petra\",\"AIDiff\":1}],\"3\":\\[{\"Name\":\"Hasdrubal Barca\",\"Team\":3,\"AI\":\"petra\",\"AIDiff\":1}]}", mapName:"maps/skirmishes/Two Seas (6)", niceMapName:"Two Seas (6)", mapSize:"Default", mapType:"skirmish", victoryCondition:"conquest", startTime:"1502492263", hasBuddies:0, gameRating:1200}, {name:"please dont join", ip:"24.66.44.35", port:"20595", stunIP:"24.66.44.35", stunPort:"20595", hostUsername:"Bolvar", state:"running", nbp:"2", maxnbp:"4", players:"{\"0\":\\[{\"Name\":\"Bolvar\",\"Team\":0},{\"Name\":\"Outlaw_7\",\"Team\":0}],\"1\":\\[{\"Name\":\"Ashokavardhan Maurya\",\"Team\":1,\"AI\":\"petra\",\"AIDiff\":2},{\"Name\":\"Gaius Servilius Structus Ahala\",\"Team\":1,\"AI\":\"petra\",\"AIDiff\":2}]}", mapName:"maps/skirmishes/Caspian Sea (2v2)", niceMapName:"Caspian Sea (2v2)", mapSize:"Default", mapType:"skirmish", victoryCondition:"conquest", startTime:"1502490832", hasBuddies:0, gameRating:1200}, {name:"Pretension's game", ip:"81.240.97.23", port:"20595", stunIP:"81.240.97.23", stunPort:"58098", hostUsername:"Pretension", state:"init", nbp:"4", maxnbp:"4", players:"{\"0\":\\[{\"Name\":\"Pretension\",\"Team\":0},{\"Name\":\"iApprove (1464)\",\"Team\":0}],\"1\":\\[{\"Name\":\"chrstgtr (1641)\",\"Team\":1},{\"Name\":\"LeGenDz (1471)\",\"Team\":1}]}", mapName:"maps/random/african_plains", niceMapName:"African Plains", mapSize:"320", mapType:"random", victoryCondition:"conquest", startTime:"1502492173", hasBuddies:2, gameRating:1444}].map(game => { | ||||
game.hasBuddies = 0; | game.hasBuddies = 0; | ||||
// Compute average rating of participating players | // Compute average rating of participating players | ||||
let playerRatings = []; | let playerRatings = []; | ||||
for (let player of stringifiedTeamListToPlayerData(game.players)) | for (let player of stringifiedTeamListToPlayerData(game.players)) | ||||
{ | { | ||||
Done Inline Actionstwo lines or let sortA = "", sortB = ""; ffffffff: two lines or let sortA = "", sortB = ""; | |||||
let [nick, rating] = splitRatingFromNick(player.Name); | let [nick, rating] = splitRatingFromNick(player.Name); | ||||
if (player.Team != "observer") | if (player.Team != "observer") | ||||
Not Done Inline Actionsold remove line ffffffff: old remove line | |||||
playerRatings.push(rating || g_DefaultLobbyRating); | playerRatings.push(rating || g_DefaultLobbyRating); | ||||
// 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; | ||||
} | } | ||||
Not Done Inline Actionsthis coming block is indent false will come correct in final diff if all finished ffffffff: this coming block is indent false will come correct in final diff if all finished | |||||
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) : | ||||
g_DefaultLobbyRating; | g_DefaultLobbyRating; | ||||
return game; | return game; | ||||
}).filter(game => !filterGame(game)).sort((a, b) => { | }).filter(game => !filterGame(game)).sort((a, b) => { | ||||
let sortA, sortB; | let sortA = ""; | ||||
switch (sortBy) | let sortB = ""; | ||||
for (let i = 0; i < g_GameListSort.length; i++) | |||||
switch (g_GameListSort[i]) | |||||
Not Done Inline Actionstesting ffffffff: testing | |||||
{ | { | ||||
case 'name': | case 'buddy': | ||||
sortA = g_GameStatusOrder.indexOf(a.state) + a.name.toLowerCase(); | sortA += String(b.hasBuddies); | ||||
sortB = g_GameStatusOrder.indexOf(b.state) + b.name.toLowerCase(); | sortB += String(a.hasBuddies); | ||||
break; | break; | ||||
case 'gameRating': | case 'gameRating': | ||||
sortA += toLeftFixed(b.gameRating ? b.gameRating : 1, 6); | |||||
sortB += toLeftFixed(a.gameRating ? a.gameRating : 1, 6); | |||||
break; | |||||
case 'mapSize': | case 'mapSize': | ||||
case 'mapType': | sortA += a.mapSize; | ||||
sortA = a[sortBy]; | sortB += b.mapSize; | ||||
sortB = b[sortBy]; | |||||
break; | break; | ||||
case 'buddy': | case 'mapType': | ||||
sortA = String(b.hasBuddies) + g_GameStatusOrder.indexOf(a.state) + a.name.toLowerCase(); | sortA += a.mapType; | ||||
sortB = String(a.hasBuddies) + g_GameStatusOrder.indexOf(b.state) + b.name.toLowerCase(); | sortB += b.mapType; | ||||
break; | break; | ||||
case 'mapName': | case 'mapName': | ||||
sortA = translate(a.niceMapName); | sortA += translate(a.niceMapName); | ||||
sortB = translate(b.niceMapName); | sortB += translate(b.niceMapName); | ||||
Done Inline Actionswrong indent ffffffff: wrong indent | |||||
break; | break; | ||||
case 'nPlayers': | case 'nPlayers': | ||||
sortA = a.maxnbp; | sortA += toLeftFixed(eval(a.nbp) + eval(a.maxnbp), 6); | ||||
sortB = b.maxnbp; | sortB += toLeftFixed(eval(b.nbp) + eval(b.maxnbp), 6); | ||||
break; | |||||
case 'name': | |||||
default: | |||||
sortA += g_GameStatusOrder.indexOf(a.state) + a.name.toLowerCase(); | |||||
sortB += g_GameStatusOrder.indexOf(b.state) + b.name.toLowerCase(); | |||||
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; | ||||
}); | }); | ||||
let list_buddy = []; | let list_buddy = []; | ||||
let list_name = []; | let list_name = []; | ||||
let list_mapName = []; | let list_mapName = []; | ||||
Show All 15 Lines | if (game.ip == g_SelectedGameIP && game.port == g_SelectedGamePort) | ||||
selectedGameIndex = +i; | selectedGameIndex = +i; | ||||
list_buddy.push(game.hasBuddies ? coloredText(g_BuddySymbol, g_GameColors[game.state]) : ""); | list_buddy.push(game.hasBuddies ? coloredText(g_BuddySymbol, g_GameColors[game.state]) : ""); | ||||
list_name.push(coloredText(gameName, g_GameColors[game.state])); | list_name.push(coloredText(gameName, g_GameColors[game.state])); | ||||
list_mapName.push(translateMapTitle(game.niceMapName)); | list_mapName.push(translateMapTitle(game.niceMapName)); | ||||
list_mapSize.push(translateMapSize(game.mapSize)); | list_mapSize.push(translateMapSize(game.mapSize)); | ||||
list_mapType.push(g_MapTypes.Title[mapTypeIdx] || ""); | list_mapType.push(g_MapTypes.Title[mapTypeIdx] || ""); | ||||
list_nPlayers.push(game.nbp + "/" + game.maxnbp); | list_nPlayers.push(game.nbp + "/" + game.maxnbp); | ||||
list_gameRating.push(game.gameRating); | list_gameRating.push(game.gameRating); | ||||
Not Done Inline Actionsafter all changes maybe inline function ffffffff: after all changes maybe inline function | |||||
list.push(gameName); | list.push(gameName); | ||||
list_data.push(i); | list_data.push(i); | ||||
} | } | ||||
Not Done Inline Actionskill if unneed just unshift ffffffff: kill if unneed just unshift | |||||
gamesBox.list_buddy = list_buddy; | gamesBox.list_buddy = list_buddy; | ||||
Not Done Inline ActionsMove sort by column to front ffffffff: Move sort by column to front | |||||
gamesBox.list_name = list_name; | gamesBox.list_name = list_name; | ||||
Not Done Inline Actionskill while one splice enough unshift(splice(obj,1) || obj); ffffffff: kill while one splice enough
``` unshift(splice(obj,1) || obj); ``` | |||||
gamesBox.list_mapName = list_mapName; | gamesBox.list_mapName = list_mapName; | ||||
gamesBox.list_mapSize = list_mapSize; | gamesBox.list_mapSize = list_mapSize; | ||||
gamesBox.list_mapType = list_mapType; | gamesBox.list_mapType = list_mapType; | ||||
gamesBox.list_nPlayers = list_nPlayers; | gamesBox.list_nPlayers = list_nPlayers; | ||||
gamesBox.list_gameRating = list_gameRating; | gamesBox.list_gameRating = list_gameRating; | ||||
// Change these last, otherwise crash | // Change these last, otherwise crash | ||||
gamesBox.list = list; | gamesBox.list = list; | ||||
Not Done Inline Actionssync to current base maybe kill some vars ffffffff: sync to current base maybe kill some vars | |||||
gamesBox.list_data = list_data; | gamesBox.list_data = list_data; | ||||
gamesBox.selected = selectedGameIndex; | gamesBox.selected = selectedGameIndex; | ||||
updateGameSelection(); | updateGameSelection(); | ||||
Not Done Inline Actionstwo lines sync no vars ffffffff: two lines sync no vars | |||||
} | } | ||||
/** | /** | ||||
* Populate the game info area with information on the current game selection. | * Populate the game info area with information on the current game selection. | ||||
*/ | */ | ||||
function updateGameSelection() | function updateGameSelection() | ||||
{ | { | ||||
let game = selectedGame(); | let game = selectedGame(); | ||||
▲ Show 20 Lines • Show All 455 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Maybe this function into somewhere common?