Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/lobby/lobby.js
Show First 20 Lines • Show All 364 Lines • ▼ Show 20 Lines | "quit": { | ||||
"handler": args => { | "handler": args => { | ||||
returnToMainMenu(); | returnToMainMenu(); | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
/** | /** | ||||
* Initial sorting order for playerslist | |||||
*/ | |||||
let g_PlayersSort = Engine.ConfigDB_GetValue("user", "lobby.players.sortBy").split(g_ConfigListDelimiter); | |||||
/** | |||||
* Initial sorting order for gameslist | |||||
*/ | |||||
let g_GamesSort = Engine.ConfigDB_GetValue("user", "lobby.games.sortBy").split(g_ConfigListDelimiter); | |||||
/** | |||||
* Called after the XmppConnection succeeded and when returning from a game. | * Called after the XmppConnection succeeded and when returning from a game. | ||||
* | * | ||||
* @param {Object} attribs | * @param {Object} attribs | ||||
*/ | */ | ||||
function init(attribs) | function init(attribs) | ||||
{ | { | ||||
if (!g_Settings) | if (!g_Settings) | ||||
{ | { | ||||
returnToMainMenu(); | returnToMainMenu(); | ||||
return; | return; | ||||
} | } | ||||
initMusic(); | initMusic(); | ||||
global.music.setState(global.music.states.MENU); | global.music.setState(global.music.states.MENU); | ||||
Engine.GetGUIObjectByName("playersBox").selected_column = g_PlayersSort[0] || "name"; | |||||
Engine.GetGUIObjectByName("gamesBox").selected_column = g_GamesSort[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; | |||||
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()); | ||||
▲ Show 20 Lines • Show All 195 Lines • ▼ Show 20 Lines | function updateToggleBuddy() | ||||
let playerList = Engine.GetGUIObjectByName("playersBox"); | let playerList = Engine.GetGUIObjectByName("playersBox"); | ||||
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; | ||||
} | } | ||||
function reverseNumberRoundedToDigit(number, digit) | |||||
{ | |||||
return Math.round((1/number)*Math.pow(10, digit))/Math.pow(10, digit); | |||||
} | |||||
/** | |||||
* Fills up number to length with zeros in front (f.e. for number as string comparison) | |||||
*/ | |||||
function fedUpWithZeros(number, length) | |||||
{ | |||||
return (Array(length).join("0") + number).slice(-length); | |||||
} | |||||
ffffffff: Maybe this function into somewhere common?
| |||||
/** | |||||
* Update order of playerlist. Save it to config. | |||||
*/ | |||||
function setOrderPlayerList(playersBox) | |||||
{ | |||||
let sortBy = playersBox.selected_column; | |||||
if (sortBy != g_PlayersSort[0]) | |||||
{ | |||||
while (g_PlayersSort.lastIndexOf(sortBy) != -1) | |||||
g_PlayersSort.splice(g_PlayersSort.lastIndexOf(sortBy), 1); | |||||
g_PlayersSort.unshift(sortBy); | |||||
setUserConfigValues("lobby.players.sortBy", g_PlayersSort); | |||||
} | |||||
setUserConfigValues("lobby.players.sortOrder", [playersBox.selected_column_order == 1 ? "ascending" : "descending"]); | |||||
writeUserConfig(); | |||||
updatePlayerList(); | |||||
} | |||||
/** | /** | ||||
* 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() | ||||
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 | |||||
{ | { | ||||
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; | ||||
let buddyStatusList = []; | let buddyStatusList = []; | ||||
let playerList = []; | let playerList = []; | ||||
let presenceList = []; | let presenceList = []; | ||||
Not Done Inline Actionsrid off not needed inline ffffffff: rid off not needed inline | |||||
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(); | ||||
switch (sortBy) | for (let i = 0; i < g_PlayersSort.length; i++) | ||||
switch (g_PlayersSort[i]) | |||||
Not Done Inline Actionstesting ffffffff: testing | |||||
{ | { | ||||
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; | // switch order desc/asc cause rate importance shall be first | ||||
sortB = +b.rating; | if (i != 0) | ||||
{ | |||||
/** | |||||
* Divide 1 with rate to turn around order and | |||||
* round to 8th decimal place (setted to fixed 8 decimal places) | |||||
*/ | |||||
sortA += (+(reverseNumberRoundedToDigit(a.rating ? a.rating : 1, 8))).toFixed(8); | |||||
sortB += (+(reverseNumberRoundedToDigit(b.rating ? b.rating : 1, 8))).toFixed(8); | |||||
} | |||||
else | |||||
{ | |||||
sortA += fedUpWithZeros(b.rating ? b.rating : 1, 6); | |||||
sortB += fedUpWithZeros(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 28 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 order of gamelist. Save it to config. | |||||
*/ | |||||
function setOrderGameList(gamesBox) | |||||
{ | |||||
let sortBy = gamesBox.selected_column; | |||||
if (sortBy != g_GamesSort[0]) | |||||
{ | |||||
while (g_GamesSort.lastIndexOf(sortBy) != -1) | |||||
g_GamesSort.splice(g_GamesSort.lastIndexOf(sortBy), 1); | |||||
g_GamesSort.unshift(sortBy); | |||||
setUserConfigValues("lobby.games.sortBy", g_GamesSort); | |||||
} | |||||
setUserConfigValues("lobby.games.sortOrder", [gamesBox.selected_column_order == 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; | ||||
Done Inline Actionstwo lines or let sortA = "", sortB = ""; ffffffff: two lines or let sortA = "", sortB = ""; | |||||
if (gamesBox.selected > -1) | if (gamesBox.selected > -1) | ||||
{ | { | ||||
Not Done Inline Actionsold remove line ffffffff: old remove line | |||||
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; | ||||
} | } | ||||
warn(uneval(g_GamesSort)) | |||||
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; | ||||
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 | |||||
// 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)) | ||||
{ | { | ||||
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); | ||||
// 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) | ||||
Not Done Inline Actionstesting ffffffff: testing | |||||
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) : | ||||
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_GamesSort.length; i++) | |||||
switch (g_GamesSort[i]) | |||||
{ | { | ||||
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; | ||||
Done Inline Actionswrong indent ffffffff: wrong indent | |||||
case 'gameRating': | case 'gameRating': | ||||
// switch order desc/asc cause rate importance shall be first | |||||
if (i != 0) | |||||
{ | |||||
/** | |||||
* Divide 1 with rate to turn around order and | |||||
* round to 8th decimal place (setted to fixed 8 decimal places) | |||||
*/ | |||||
sortA += (+(reverseNumberRoundedToDigit(a.gameRating ? a.gameRating : 1, 8))).toFixed(8); | |||||
sortB += (+(reverseNumberRoundedToDigit(b.gameRating ? b.gameRating : 1, 8))).toFixed(8); | |||||
} | |||||
else | |||||
{ | |||||
sortA += fedUpWithZeros(b.gameRating ? b.gameRating : 1, 6); | |||||
sortB += fedUpWithZeros(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); | ||||
break; | break; | ||||
case 'nPlayers': | case 'nPlayers': | ||||
sortA = a.maxnbp; | sortA += fedUpWithZeros(eval(a.nbp) + eval(a.maxnbp), 6); | ||||
sortB = b.maxnbp; | sortB += fedUpWithZeros(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; | ||||
}); | }); | ||||
Not Done Inline Actionsafter all changes maybe inline function ffffffff: after all changes maybe inline function | |||||
let list_buddy = []; | let list_buddy = []; | ||||
let list_name = []; | let list_name = []; | ||||
Not Done Inline Actionskill if unneed just unshift ffffffff: kill if unneed just unshift | |||||
let list_mapName = []; | let list_mapName = []; | ||||
let list_mapSize = []; | let list_mapSize = []; | ||||
Not Done Inline ActionsMove sort by column to front ffffffff: Move sort by column to front | |||||
let list_mapType = []; | let list_mapType = []; | ||||
Not Done Inline Actionskill while one splice enough unshift(splice(obj,1) || obj); ffffffff: kill while one splice enough
``` unshift(splice(obj,1) || obj); ``` | |||||
let list_nPlayers = []; | let list_nPlayers = []; | ||||
let list_gameRating = []; | let list_gameRating = []; | ||||
let list = []; | let list = []; | ||||
let list_data = []; | let list_data = []; | ||||
let selectedGameIndex = -1; | let selectedGameIndex = -1; | ||||
for (let i in g_GameList) | for (let i in g_GameList) | ||||
{ | { | ||||
Not Done Inline Actionssync to current base maybe kill some vars ffffffff: sync to current base maybe kill some vars | |||||
let game = g_GameList[i]; | let game = g_GameList[i]; | ||||
let gameName = escapeText(game.name); | let gameName = escapeText(game.name); | ||||
let mapTypeIdx = g_MapTypes.Name.indexOf(game.mapType); | let mapTypeIdx = g_MapTypes.Name.indexOf(game.mapType); | ||||
Not Done Inline Actionstwo lines sync no vars ffffffff: two lines sync no vars | |||||
if (game.ip == g_SelectedGameIP && game.port == g_SelectedGamePort) | if (game.ip == g_SelectedGameIP && game.port == g_SelectedGamePort) | ||||
selectedGameIndex = +i; | selectedGameIndex = +i; | ||||
list_buddy.push(game.hasBuddies ? '[color="' + g_GameColors[game.state] + '"]' + g_BuddySymbol + '[/color]' : ""); | list_buddy.push(game.hasBuddies ? '[color="' + g_GameColors[game.state] + '"]' + g_BuddySymbol + '[/color]' : ""); | ||||
list_name.push('[color="' + g_GameColors[game.state] + '"]' + gameName); | list_name.push('[color="' + g_GameColors[game.state] + '"]' + gameName); | ||||
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] || ""); | ||||
▲ Show 20 Lines • Show All 483 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
Maybe this function into somewhere common?