Changeset View
Standalone View
binaries/data/mods/public/gui/lobby/lobby.js
Context not available. | |||||
const g_SenderFont = "sans-bold-13"; | const g_SenderFont = "sans-bold-13"; | ||||
/** | /** | ||||
* User buddies | |||||
*/ | |||||
var g_UserBuddies = Engine.ConfigDB_GetValue("user", "lobby.buddies").split("|"); | |||||
elexis: a sign is +/- or something seen in traffc, the word symbol seems to fit better.
I know all the… | |||||
/** | |||||
* All chat messages received since init (i.e. after lobby join and after returning from a game). | * All chat messages received since init (i.e. after lobby join and after returning from a game). | ||||
Not Done Inline ActionsComments having the exact same character composition a the variable name should be removed. So if we want to keep this JSdoc format, it should explain in which situation this icon is used. elexis: Comments having the exact same character composition a the variable name should be removed. | |||||
*/ | */ | ||||
var g_ChatMessages = []; | var g_ChatMessages = []; | ||||
Not Done Inline Actionsfor now i split buddy names by "|" sign if thinks is no allowed in names in lobby. ffffffff: for now i split buddy names by "|" sign if thinks is no allowed in names in lobby. | |||||
Not Done Inline ActionsVladislav recommended to use comma, as it resembles CSV format and since that is also forbidden by our lobby policy (see sanitizePlayerName). A more stable solution would be using a character that is prohibited by the XMPP specs, but it seems to allow every special character on my keyboard, even slash, backslash, so comma is ok. elexis: Vladislav recommended to use comma, as it resembles CSV format and since that is also forbidden… | |||||
Context not available. | |||||
updateGameSelection(); | updateGameSelection(); | ||||
} | } | ||||
function rateRemove(playerName) | |||||
{ | |||||
let result = /^(\S+)\ \(\d+\)$/g.exec(playerName); | |||||
return result ? result[1] : playerName; | |||||
} | |||||
/** | /** | ||||
* Filter a game based on the status of the filter dropdowns. | * Filter a game based on the status of the filter dropdowns. | ||||
* | * | ||||
Context not available. | |||||
if (playersBox.selected > -1) | if (playersBox.selected > -1) | ||||
g_SelectedPlayer = playersBox.list[playersBox.selected]; | g_SelectedPlayer = playersBox.list[playersBox.selected]; | ||||
let buddyStatusList = []; | |||||
let playerList = []; | let playerList = []; | ||||
let presenceList = []; | let presenceList = []; | ||||
let nickList = []; | let nickList = []; | ||||
let ratingList = []; | let ratingList = []; | ||||
let cleanPlayerList = Engine.GetPlayerList().sort((a, b) => { | let cleanPlayerList = Engine.GetPlayerList().map(player => { | ||||
player.isBuddy = false; | |||||
if (g_UserBuddies.concat(g_Username).indexOf(player.name) != -1) | |||||
player.isBuddy = true; | |||||
return player; }).sort((a, b) => { | |||||
Not Done Inline ActionsIt's a design decision whether the player will be shown as a buddy of oneself. Might make the code shorter if not caring about this, but we can keep that design decision. I'd rather check for g_Username == player.name || g_UserBuddies.indexOf(player.name) != -1 though instead of the concat elexis: It's a design decision whether the player will be shown as a buddy of oneself. Might make the… | |||||
let sortA, sortB; | let sortA, sortB; | ||||
switch (sortBy) | switch (sortBy) | ||||
{ | { | ||||
Not Done Inline Actionsas suggest by vladis seperat sort and filter command. ffffffff: as suggest by vladis seperat sort and filter command. | |||||
Not Done Inline Actionsas suggest by vladis seperat sort and map command. (previous mentioned filter was wrong). ffffffff: as suggest by vladis seperat sort and map command. (previous mentioned filter was wrong). | |||||
Not Done Inline ActionsIndeed a bit odd with the whitespace, but having a straight concatenation means that it is a tiny bit more obvious that these things are executed consecutively on the same array elexis: Indeed a bit odd with the whitespace, but having a straight concatenation means that it is a… | |||||
case 'buddy': | |||||
sortA = g_UserBuddies.indexOf(a.name); | |||||
sortB = g_UserBuddies.indexOf(b.name); | |||||
break; | |||||
case 'rating': | case 'rating': | ||||
sortA = +a.rating; | sortA = +a.rating; | ||||
sortB = +b.rating; | sortB = +b.rating; | ||||
Not Done Inline Actionsi wanted to prefer here when selecting buddy sorting buddy then presence [online,away,playing..] and then name in this prio if its ok. ffffffff: i wanted to prefer here when selecting buddy sorting buddy then presence [online,away,playing.. | |||||
Not Done Inline ActionsThe design looks weird, but it's basically correct, since players have all unique names and ratings. elexis: The design looks weird, but it's basically correct, since players have all unique names and… | |||||
Context not available. | |||||
let coloredName = colorPlayerName((player.role == "moderator" ? g_ModeratorPrefix : "") + player.name); | let coloredName = colorPlayerName((player.role == "moderator" ? g_ModeratorPrefix : "") + player.name); | ||||
let coloredPresence = '[color="' + statusColor + '"]' + g_PlayerStatuses[presence].status + "[/color]"; | let coloredPresence = '[color="' + statusColor + '"]' + g_PlayerStatuses[presence].status + "[/color]"; | ||||
let coloredRating = '[color="' + statusColor + '"]' + rating + "[/color]"; | let coloredRating = '[color="' + statusColor + '"]' + rating + "[/color]"; | ||||
buddyStatusList.push('[font="sans-10"][color="' + g_PlayerStatuses[presence].color + ' ' + (player.isBuddy ? "255" : "0") + '"]●[/color][/font]'); | |||||
playerList.push(coloredName); | playerList.push(coloredName); | ||||
presenceList.push(coloredPresence); | presenceList.push(coloredPresence); | ||||
Not Done Inline ActionsUsing the alpha transparency to hide the sign we later add is pointless if we can just not add anything instead. elexis: Using the alpha transparency to hide the sign we later add is pointless if we can just not add… | |||||
Context not available. | |||||
nickList.push(player.name); | nickList.push(player.name); | ||||
} | } | ||||
playersBox.list_buddy = buddyStatusList; | |||||
playersBox.list_name = playerList; | playersBox.list_name = playerList; | ||||
playersBox.list_status = presenceList; | playersBox.list_status = presenceList; | ||||
playersBox.list_rating = ratingList; | playersBox.list_rating = ratingList; | ||||
Context not available. | |||||
playersBox.selected = playersBox.list.indexOf(g_SelectedPlayer); | playersBox.selected = playersBox.list.indexOf(g_SelectedPlayer); | ||||
} | } | ||||
Not Done Inline Actionsim for showing username as buddied alltime ffffffff: im for showing username as buddied alltime | |||||
function unhideToggleBuddy(playersBox) | |||||
{ | |||||
if (playersBox.selected != -1) | |||||
{ | |||||
Engine.GetGUIObjectByName("leftPanel").size = "20 30 20% 100%-310"; | |||||
Engine.GetGUIObjectByName("profilePanel").size="20 100%-305 20% 100%-110"; | |||||
Not Done Inline Actionstabs instead of spaces elexis: tabs instead of spaces | |||||
Engine.GetGUIObjectByName("leftButtonPanel").size="20 100%-105 20% 100%-20"; | |||||
Engine.GetGUIObjectByName("toggleBuddy").hidden = false; | |||||
Not Done Inline ActionsThose hardcoded numbers are bad. People should be able to only change the XML without having to change the JS numbers. Write code to compute the numbers dynamically. Why do we have this code at all, the button should always be visible. elexis: Those hardcoded numbers are bad. People should be able to only change the XML without having to… | |||||
} | |||||
Not Done Inline Actionsmissing spaces at = elexis: missing spaces at = | |||||
else | |||||
{ | |||||
Engine.GetGUIObjectByName("leftPanel").size = "20 30 20% 100%-280"; | |||||
Engine.GetGUIObjectByName("profilePanel").size="20 100%-275 20% 100%-80"; | |||||
Engine.GetGUIObjectByName("leftButtonPanel").size="20 100%-75 20% 100%-20"; | |||||
Engine.GetGUIObjectByName("toggleBuddy").hidden = true; | |||||
} | |||||
} | |||||
/** | |||||
Not Done Inline Actions.hidden = can be pulled out of the if statement to reduce code elexis: .hidden = can be pulled out of the if statement to reduce code | |||||
* Toggle buddy state for a player in playerlist within the user config | |||||
*/ | |||||
function toggleBuddy() | |||||
{ | |||||
var buddies = Engine.ConfigDB_GetValue("user", "lobby.buddies"); | |||||
let playerList = Engine.GetGUIObjectByName("playersBox"); | |||||
let name = playerList.list[playerList.selected]; | |||||
Not Done Inline Actionslet? also unused, so delete elexis: let? also unused, so delete | |||||
let index = g_UserBuddies.indexOf(name); | |||||
if (index != -1) | |||||
g_UserBuddies.splice(index, 1); | |||||
Not Done Inline ActionsShould have an early return, so that the user can't be a buddy of himself. selected == -1 if no player has been selected before can't occur with your patch on init becaues you hide the button, but instead the button should always be visible and just not do anything if the player is not selected. However selected == -1 can occur if a player is selected but goes offline! elexis: Should have an early return, so that the user can't be a buddy of himself.
selected == -1 if… | |||||
else | |||||
g_UserBuddies.push(name); | |||||
Engine.ConfigDB_CreateValue("user", "lobby.buddies", g_UserBuddies.join("|")); | |||||
Engine.ConfigDB_WriteValueToFile("user", "lobby.buddies", g_UserBuddies.join("|"), "config/user.cfg"); | |||||
updatePlayerList(); | |||||
updateGameList(); | |||||
Not Done Inline Actionsg_UserBuddies.join(",") duplication can be reduced elexis: `g_UserBuddies.join(",")` duplication can be reduced | |||||
} | |||||
/** | /** | ||||
* Select the game listing the selected player when toggling the full games filter. | * Select the game listing the selected player when toggling the full games filter. | ||||
*/ | */ | ||||
Context not available. | |||||
g_SelectedGamePort = g_GameList[gamesBox.selected].port; | g_SelectedGamePort = g_GameList[gamesBox.selected].port; | ||||
} | } | ||||
Not Done Inline Actionsnice work u applied my status order for gamelists thx! ffffffff: nice work u applied my status order for gamelists thx! | |||||
g_GameList = Engine.GetGameList().filter(game => !filterGame(game)).sort((a, b) => { | g_GameList = Engine.GetGameList().map(game => { | ||||
game.buddy = 0; | |||||
for (let player of stringifiedTeamListToPlayerData(game.players)) | |||||
{ | |||||
Not Done Inline ActionshasBuddies (in accordance with isBuddy) elexis: hasBuddies (in accordance with isBuddy) | |||||
if (!player.Name) | |||||
continue; | |||||
if (g_UserBuddies.indexOf(rateRemove(player.Name)) != -1) | |||||
Not Done Inline ActionsIf a player doesn't have a name, that's a serious bug outside of this code. elexis: If a player doesn't have a name, that's a serious bug outside of this code.
If we want this… | |||||
{ | |||||
game.buddy = player.Team == "observer" ? 2 : 1; | |||||
Not Done Inline Actionsjust save the name without rating once, then we can get rid of that rating removal function altogether elexis: just save the name without rating once, then we can get rid of that rating removal function… | |||||
if (player.Team != "observer") | |||||
break; | |||||
} | |||||
} | |||||
return game; | |||||
}).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': | ||||
case 'mapType': | case 'mapType': | ||||
case 'buddy': | |||||
sortA = a[sortBy]; | sortA = a[sortBy]; | ||||
sortB = b[sortBy]; | sortB = b[sortBy]; | ||||
break; | break; | ||||
Not Done Inline Actionsprefer game state over name in buddysorting. this b/a change in buddy attribute object is willingly due to buddy numberings from 0 (nobuddy game) to 1 (buddy in observer game), 2 (buddy in game playing), 3 (user playing in game for easier finding when dropped from game). so highest is priorized ffffffff: prefer game state over name in buddysorting. this b/a change in buddy attribute object is… | |||||
Not Done Inline ActionsOkay with the playing buddy vs. spectating buddy priorization, should have a comment in the code to clarify to future devs who don't read through this webpage elexis: Okay with the playing buddy vs. spectating buddy priorization, should have a comment in the… | |||||
Not Done Inline ActionsString() is more explicit than adding an empty string to a number in order to convert it elexis: String() is more explicit than adding an empty string to a number in order to convert it | |||||
Context not available. | |||||
return 0; | return 0; | ||||
}); | }); | ||||
let list_buddy = []; | |||||
let list_name = []; | let list_name = []; | ||||
let list_mapName = []; | let list_mapName = []; | ||||
let list_mapSize = []; | let list_mapSize = []; | ||||
Context not available. | |||||
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('[font="sans-10"][color="' + g_GameColors[game.state] + ' ' + (game.buddy ? "255" : "0") + '"]●[/color][/font]'); | |||||
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)); | ||||
Context not available. | |||||
list_data.push(i); | list_data.push(i); | ||||
} | } | ||||
gamesBox.list_buddy = list_buddy; | |||||
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; | ||||
Context not available. |
a sign is +/- or something seen in traffc, the word symbol seems to fit better.
I know all the rest is const and I made it const, but sanderd17 has convinced me some time ago that var is better for mods, so they can change it from an external file