Changeset View
Standalone View
lobby.js
Context not available. | |||||
function resetFilters() | function resetFilters() | ||||
{ | { | ||||
Engine.GetGUIObjectByName("mapSizeFilter").selected = 0; | Engine.GetGUIObjectByName("mapSizeFilter").selected = 0; | ||||
Engine.GetGUIObjectByName("playersNumberFilter").selected = 0; | Engine.GetGUIObjectByName("playersNumberFilter").selected = 0; | ||||
Engine.GetGUIObjectByName("mapTypeFilter").selected = g_MapTypes.Default; | Engine.GetGUIObjectByName("mapTypeFilter").selected = g_MapTypes.Default; | ||||
Engine.GetGUIObjectByName("showFullFilter").checked = false; | Engine.GetGUIObjectByName("showFullFilter").checked = true; | ||||
elexis: This is out of scope of the gamerank sorting. so the change has to be removed in this patch. | |||||
applyFilters(); | applyFilters(); | ||||
} | } | ||||
function applyFilters() | function applyFilters() | ||||
Context not available. | |||||
* 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 || "rating"; | ||||
elexisAuthorUnsubmitted Not Done Inline ActionsDelete code that is commented out elexis: Delete code that is commented out | |||||
let sortBy = "rating"; | |||||
let sortOrder = playersBox.selected_column_order || 1; | let sortOrder = playersBox.selected_column_order || 1; | ||||
// sortOrder = (sortOrder == -1) ? 1 : -1; | |||||
SandaracUnsubmitted Not Done Inline ActionsCommented-out code should not be added in a diff. Sandarac: Commented-out code should not be added in a diff. | |||||
if (sortOrder == -1) sortOrder = 1; else sortOrder= -1; | |||||
elexisAuthorUnsubmitted Not Done Inline ActionssortOrder *= -1 ? elexis: `sortOrder *= -1` ? | |||||
//warn(uneval(playersBox.selected_column_order)); | |||||
if (playersBox.selected > -1) | if (playersBox.selected > -1) | ||||
g_SelectedPlayer = playersBox.list[playersBox.selected]; | g_SelectedPlayer = playersBox.list[playersBox.selected]; | ||||
let playerList = []; | let playerList = []; | ||||
Context not available. | |||||
{ | { | ||||
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; | ||||
} | } | ||||
Not Done Inline ActionsA JS map function would be neat, like g_GameList = Engine.GetGameList().map(game => { ... }).filter(the one from below) elexis: A JS map function would be neat, like
```g_GameList = Engine.GetGameList().map(game => {
... | |||||
Not Done Inline Actionsno map call below ffffffff: no map call below
| |||||
g_GameList = Engine.GetGameList().filter(game => !filterGame(game)).sort((a, b) => { | let g_GameList_pr = Engine.GetGameList(); | ||||
elexisAuthorUnsubmitted Not Done Inline Actionsg_ prefix only used for globals, rename it to gameList elexis: `g_` prefix only used for globals, rename it to `gameList` | |||||
for (let i in g_GameList_pr) | |||||
elexisAuthorUnsubmitted Not Done Inline ActionsUse a for ... of loop, since you don't use i anywhere, thus the next line becomes unneeded too elexis: Use a `for ... of` loop, since you don't use `i` anywhere, thus the next line becomes unneeded… | |||||
{ | |||||
let game = g_GameList_pr[i]; | |||||
var re = /^\S+\ \((\d+)\)$/g; | |||||
elexisAuthorUnsubmitted Not Done Inline ActionsUse let instead of var throughout this file (except for globals at the begin of the file) elexis: Use `let` instead of `var` throughout this file (except for globals at the begin of the file) | |||||
ffffffffUnsubmitted Not Done Inline Actionshow to hide the error player.Name? ffffffff: how to hide the error player.Name? | |||||
let pls = stringifiedTeamListToPlayerData(game.players); | |||||
elexisAuthorUnsubmitted Not Done Inline Actionspls -> players elexis: pls -> players | |||||
Not Done Inline Actionsternary? Imarok: ternary?
`(player.Team == "observer" ? specRatings : ratings).push(rating);` | |||||
let ratings = []; | |||||
let specRatings = []; | |||||
for (let j in pls) { | |||||
elexisAuthorUnsubmitted Not Done Inline Actions{ to the next line elexis: `{` to the next line | |||||
let name = pls[j].Name; | |||||
let team = pls[j].Team; | |||||
elexisAuthorUnsubmitted Not Done Inline Actionsjust use players[j].Name instead of introducing a new variable (same true for team) elexis: just use `players[j].Name` instead of introducing a new variable (same true for `team`) | |||||
if (team != "observer") { | |||||
SandaracUnsubmitted Not Done Inline ActionsOpening braces should start on a new line, as per http://trac.wildfiregames.com/wiki/Coding_Conventions#Formatting Sandarac: Opening braces should start on a new line, as per http://trac.wildfiregames. | |||||
var result = re.exec(name); re.lastIndex = 0; | |||||
elexisAuthorUnsubmitted Not Done Inline ActionsThe lastIndex reset can be avoided by nuking the re variable and doing /...regex.../g.exec(....) elexis: The `lastIndex` reset can be avoided by nuking the `re` variable and doing `/...regex.../g.exec… | |||||
elexisAuthorUnsubmitted Not Done Inline ActionsNuke the peculiar lastIndex line and fix it by nuking / inlining re elexis: Nuke the peculiar lastIndex line and fix it by nuking / inlining `re` | |||||
var rating = result ? +result[1] : 1200; | |||||
ratings.push(rating); | |||||
} else { | |||||
elexisAuthorUnsubmitted Not Done Inline ActionsWhat is the use case of the average spectator ranking? Finding the game where the good players observe, so one can join that game too? elexis: What is the use case of the average spectator ranking? Finding the game where the good players… | |||||
var result = re.exec(name); re.lastIndex = 0; | |||||
var rating = result ? +result[1] : 1200; | |||||
specRatings.push(rating); | |||||
} | |||||
} | |||||
Not Done Inline ActionsA "-" in the table would mess up the sorting (consider average > 1200 and < 1200), so use numbers only. Same for the other reduce. So if you're lucky, you can avoid 2 more variables and end up with game.nRank = reduce.... elexis: A "-" in the table would mess up the sorting (consider average > 1200 and < 1200), so use… | |||||
Not Done Inline Actionscannot be avoided due to its unclear for recude call on empty object. ffffffff: cannot be avoided due to its unclear for recude call on empty object. | |||||
var average = 1200; | |||||
if (ratings.length > 0) { | |||||
elexisAuthorUnsubmitted Not Done Inline ActionsSuperfluous braces. they can be removed if it contains only one statement elexis: Superfluous braces. they can be removed if it contains only one statement | |||||
average = Math.round(ratings.reduce((sum, current) => sum + current) / ratings.length); | |||||
} | |||||
var specAverage = 1200; | |||||
if (specRatings.length > 0) { | |||||
specAverage = Math.round(specRatings.reduce((sum, current) => sum + current) / specRatings.length); | |||||
} | |||||
g_GameList_pr[i].nRank = average; | |||||
g_GameList_pr[i].nSpecRank = specAverage; | |||||
} | |||||
g_GameList = g_GameList_pr.filter(game => !filterGame(game)).sort((a, b) => { | |||||
let sortA, sortB; | let sortA, sortB; | ||||
switch (sortBy) | switch (sortBy) | ||||
{ | { | ||||
case 'name': | case 'name': | ||||
case 'mapSize': | case 'mapSize': | ||||
Context not available. | |||||
case 'nPlayers': | case 'nPlayers': | ||||
// Compare playercount ratio | // Compare playercount ratio | ||||
sortA = a.nbp * b.maxnbp; | sortA = a.nbp * b.maxnbp; | ||||
sortB = b.nbp * a.maxnbp; | sortB = b.nbp * a.maxnbp; | ||||
break; | break; | ||||
case 'nRank': | |||||
sortA = a.nRank; | |||||
sortB = b.nRank; | |||||
break; | |||||
case 'nSpecRank': | |||||
sortA = a.nSpecRank; | |||||
sortB = b.nSpecRank; | |||||
break; | |||||
case 'status': | case 'status': | ||||
default: | default: | ||||
sortA = g_GameStatusOrder.indexOf(a.state); | sortA = g_GameStatusOrder.indexOf(a.state); | ||||
sortB = g_GameStatusOrder.indexOf(b.state); | sortB = g_GameStatusOrder.indexOf(b.state); | ||||
break; | break; | ||||
Context not available. | |||||
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_nRank = []; | |||||
let list_nSpecRank = []; | |||||
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) | ||||
Context not available. | |||||
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] || ""); | ||||
list_nPlayers.push(game.nbp + "/" + game.maxnbp); | list_nPlayers.push(game.nbp + "/" + game.maxnbp); | ||||
list_nRank.push(game.nRank); | |||||
list_nSpecRank.push(game.nSpecRank); | |||||
list.push(gameName); | list.push(gameName); | ||||
list_data.push(i); | list_data.push(i); | ||||
} | } | ||||
gamesBox.list_name = list_name; | gamesBox.list_name = list_name; | ||||
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_nRank = list_nRank; | |||||
gamesBox.list_nSpecRank = list_nSpecRank; | |||||
// Change these last, otherwise crash | // Change these last, otherwise crash | ||||
gamesBox.list = list; | gamesBox.list = list; | ||||
gamesBox.list_data = list_data; | gamesBox.list_data = list_data; | ||||
gamesBox.selected = selectedGameIndex; | gamesBox.selected = selectedGameIndex; | ||||
Context not available. |
This is out of scope of the gamerank sorting. so the change has to be removed in this patch.
(Different people, different taste, we could save the most recent checkbox state in the user config perhaps).