Changeset View
Standalone View
lobby.js
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; | ||||
} | } | ||||
g_GameList = Engine.GetGameList().filter(game => !filterGame(game)).sort((a, b) => { | let gameList = Engine.GetGameList(); | ||||
for (let game of gameList) | |||||
elexis: A JS map function would be neat, like
```g_GameList = Engine.GetGameList().map(game => {
... | |||||
ffffffffUnsubmitted Not Done Inline Actionsno map call below ffffffff: no map call below
| |||||
{ | |||||
let re = /^\S+\ \((\d+)\)$/g; | |||||
Not Done Inline Actionsg_ prefix only used for globals, rename it to gameList elexis: `g_` prefix only used for globals, rename it to `gameList` | |||||
let players = stringifiedTeamListToPlayerData(game.players); | |||||
let ratings = []; | |||||
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 specRatings = []; | |||||
for (let player of players) { | |||||
let result = re.exec(player.Name); | |||||
re.lastIndex = 0; | |||||
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) | |||||
Not Done Inline Actionshow to hide the error player.Name? ffffffff: how to hide the error player.Name? | |||||
let rating = result ? +result[1] : 1200; | |||||
Not Done Inline Actionspls -> players elexis: pls -> players | |||||
Not Done Inline Actionsternary? Imarok: ternary?
`(player.Team == "observer" ? specRatings : ratings).push(rating);` | |||||
if (player.Team != "observer") | |||||
ratings.push(rating); | |||||
else | |||||
Not Done Inline Actions{ to the next line elexis: `{` to the next line | |||||
specRatings.push(rating); | |||||
} | |||||
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`) | |||||
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 average = 1200; | |||||
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… | |||||
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` | |||||
if (ratings.length > 0) | |||||
average = Math.round(ratings.reduce((sum, current) => sum + current) / ratings.length); | |||||
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 specAverage = 1200; | |||||
if (specRatings.length > 0) | |||||
specAverage = Math.round(specRatings.reduce((sum, current) => sum + current) / specRatings.length); | |||||
else | |||||
specAverage = "-"; | |||||
elexisAuthorUnsubmitted 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… | |||||
ffffffffUnsubmitted 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. | |||||
game.nRank = average; | |||||
game.nSpecRank = specAverage; | |||||
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 | |||||
} | |||||
g_GameList = gameList.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. |
A JS map function would be neat, like