Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/lobby/lobby.js
Show All 23 Lines | |||||
const g_Username = Engine.LobbyGetNick(); | const g_Username = Engine.LobbyGetNick(); | ||||
/** | /** | ||||
* Lobby server address to construct host JID. | * Lobby server address to construct host JID. | ||||
*/ | */ | ||||
const g_LobbyServer = Engine.ConfigDB_GetValue("user", "lobby.server"); | const g_LobbyServer = Engine.ConfigDB_GetValue("user", "lobby.server"); | ||||
/** | /** | ||||
* Current games will be listed in these colors. | * Current games will be listed formatted with these tags. | ||||
*/ | */ | ||||
var g_GameColors = { | var g_GameTextTags = { | ||||
"init": "0 219 0", | "init": { "color": "0 219 0" }, | ||||
"waiting": "255 127 0", | "waiting": { "color": "255 127 0" }, | ||||
"running": "219 0 0", | "running": { "color": "219 0 0" }, | ||||
"incompatible": "gray" | "incompatible": { "color": "gray" } | ||||
}; | }; | ||||
/** | /** | ||||
* Initial sorting order of the gamelist. | * Initial sorting order of the gamelist. | ||||
*/ | */ | ||||
var g_GameStatusOrder = ["init", "waiting", "running", "incompatible"]; | var g_GameStatusOrder = ["init", "waiting", "running", "incompatible"]; | ||||
/** | /** | ||||
* The playerlist will be assembled using these values. | * The playerlist will be assembled using these values. | ||||
*/ | */ | ||||
var g_PlayerStatuses = { | var g_PlayerStatuses = { | ||||
"available": { "color": "0 219 0", "status": translate("Online") }, | "available": { "textTags": { "color": "0 219 0" }, "status": translate("Online") }, | ||||
"away": { "color": "229 76 13", "status": translate("Away") }, | "away": { "textTags": { "color": "229 76 13" }, "status": translate("Away") }, | ||||
"playing": { "color": "200 0 0", "status": translate("Busy") }, | "playing": { "textTags": { "color": "200 0 0" }, "status": translate("Busy") }, | ||||
"offline": { "color": "0 0 0", "status": translate("Offline") }, | "offline": { "textTags": { "color": "0 0 0" }, "status": translate("Offline") }, | ||||
"unknown": { "color": "178 178 178", "status": translateWithContext("lobby presence", "Unknown") } | "unknown": { "textTags": { "color": "178 178 178" }, "status": translateWithContext("lobby presence", "Unknown") } | ||||
}; | }; | ||||
elexis: (Aligning whitespace will be removed in d2261 to please Jenkins) | |||||
Done Inline Actionssame xP (hint: naming of the object) elexis: same xP (hint: naming of the object) | |||||
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. | ||||
*/ | */ | ||||
var g_SystemColor = "150 0 0"; | var g_SystemColor = "150 0 0"; | ||||
/** | /** | ||||
* Color for private messages in the chat. | * Color for private messages in the chat. | ||||
*/ | */ | ||||
var g_PrivateMessageColor = "0 150 0"; | var g_PrivateMessageTextTags = { "color": "0 150 0" }; | ||||
/** | /** | ||||
* Used for highlighting the sender of chat messages. | * Used for highlighting the sender of chat messages. | ||||
*/ | */ | ||||
var g_SenderFont = "sans-bold-13"; | var g_SenderTextTags = { "font": "sans-bold-13" }; | ||||
/** | /** | ||||
* Color to highlight chat commands in the explanation. | * Color to highlight chat commands in the explanation. | ||||
*/ | */ | ||||
var g_ChatCommandColor = "200 200 255"; | var g_ChatCommandTextTags = { "color": "200 200 255" }; | ||||
/** | /** | ||||
* Indicates if the lobby is opened as a dialog or window. | * Indicates if the lobby is opened as a dialog or window. | ||||
*/ | */ | ||||
var g_Dialog = false; | var g_Dialog = false; | ||||
/** | /** | ||||
* 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). | ||||
▲ Show 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | "help": { | ||||
"description": translate("Show this help."), | "description": translate("Show this help."), | ||||
"handler": args => { | "handler": args => { | ||||
let isModerator = Engine.LobbyGetPlayerRole(g_Username) == "moderator"; | let isModerator = Engine.LobbyGetPlayerRole(g_Username) == "moderator"; | ||||
let text = translate("Chat commands:"); | let text = translate("Chat commands:"); | ||||
for (let command in g_ChatCommands) | for (let command in g_ChatCommands) | ||||
if (!g_ChatCommands[command].moderatorOnly || isModerator) | if (!g_ChatCommands[command].moderatorOnly || isModerator) | ||||
// Translation: Chat command help format | // Translation: Chat command help format | ||||
text += "\n" + sprintf(translate("%(command)s - %(description)s"), { | text += "\n" + sprintf(translate("%(command)s - %(description)s"), { | ||||
"command": coloredText(command, g_ChatCommandColor), | "command": setStringTags(command, g_ChatCommandTextTags), | ||||
"description": g_ChatCommands[command].description | "description": g_ChatCommands[command].description | ||||
}); | }); | ||||
addChatMessage({ | addChatMessage({ | ||||
"from": "system", | "from": "system", | ||||
"text": text | "text": text | ||||
}); | }); | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 374 Lines • ▼ Show 20 Lines | for (let player of cleanPlayerList) | ||||
if (player.rating && player.name == g_Username) | if (player.rating && player.name == g_Username) | ||||
g_UserRating = player.rating; | g_UserRating = player.rating; | ||||
let rating = player.rating ? (" " + player.rating).substr(-5) : " -"; | let rating = player.rating ? (" " + player.rating).substr(-5) : " -"; | ||||
let presence = g_PlayerStatuses[player.presence] ? player.presence : "unknown"; | let presence = g_PlayerStatuses[player.presence] ? player.presence : "unknown"; | ||||
if (presence == "unknown") | if (presence == "unknown") | ||||
warn("Unknown presence:" + player.presence); | warn("Unknown presence:" + player.presence); | ||||
let statusColor = g_PlayerStatuses[presence].color; | buddyStatusList.push(player.isBuddy ? setStringTags(g_BuddySymbol, g_PlayerStatuses[presence].textTags) : ""); | ||||
Done Inline ActionsThis JS object seems avoidable, and the "modders" argument doesn't apply (as its stored in the other variable. elexis: This JS object seems avoidable, and the "modders" argument doesn't apply (as its stored in the… | |||||
buddyStatusList.push(player.isBuddy ? coloredText(g_BuddySymbol, statusColor) : ""); | |||||
playerList.push(colorPlayerName((player.role == "moderator" ? g_ModeratorPrefix : "") + player.name)); | playerList.push(colorPlayerName((player.role == "moderator" ? g_ModeratorPrefix : "") + player.name)); | ||||
presenceList.push(coloredText(g_PlayerStatuses[presence].status, statusColor)); | presenceList.push(setStringTags(g_PlayerStatuses[presence].status, g_PlayerStatuses[presence].textTags)); | ||||
ratingList.push(coloredText(rating, statusColor)); | ratingList.push(setStringTags(rating, g_PlayerStatuses[presence].textTags)); | ||||
nickList.push(player.name); | nickList.push(player.name); | ||||
} | } | ||||
playersBox.list_buddy = buddyStatusList; | 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; | ||||
playersBox.list = nickList; | playersBox.list = nickList; | ||||
▲ Show 20 Lines • Show All 313 Lines • ▼ Show 20 Lines | function updateGameList() | ||||
{ | { | ||||
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); | ||||
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 ? coloredText(g_BuddySymbol, g_GameColors[game.state]) : ""); | list_buddy.push(game.hasBuddies ? setStringTags(g_BuddySymbol, g_GameTextTags[game.state]) : ""); | ||||
list_name.push(coloredText(gameName, g_GameColors[game.state])); | list_name.push(setStringTags(gameName, g_GameTextTags[game.state])); | ||||
Done Inline Actionsavoidable JS objects elexis: avoidable JS objects | |||||
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); | ||||
list.push(gameName); | list.push(gameName); | ||||
list_data.push(i); | list_data.push(i); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 253 Lines • ▼ Show 20 Lines | function handleChatCommand(text) | ||||
args = ircSplit("/" + args); | args = ircSplit("/" + args); | ||||
if (!g_ChatCommands[cmd]) | if (!g_ChatCommands[cmd]) | ||||
{ | { | ||||
addChatMessage({ | addChatMessage({ | ||||
"from": "system", | "from": "system", | ||||
"text": sprintf( | "text": sprintf( | ||||
translate("The command '%(cmd)s' is not supported."), { | translate("The command '%(cmd)s' is not supported."), { | ||||
"cmd": coloredText(cmd, g_ChatCommandColor) | "cmd": setStringTags(cmd, g_ChatCommandTextTags) | ||||
}) | }) | ||||
}); | }); | ||||
return false; | return false; | ||||
} | } | ||||
if (g_ChatCommands[cmd].moderatorOnly && Engine.LobbyGetPlayerRole(g_Username) != "moderator") | if (g_ChatCommands[cmd].moderatorOnly && Engine.LobbyGetPlayerRole(g_Username) != "moderator") | ||||
{ | { | ||||
addChatMessage({ | addChatMessage({ | ||||
"from": "system", | "from": "system", | ||||
"text": sprintf( | "text": sprintf( | ||||
translate("The command '%(cmd)s' is restricted to moderators."), { | translate("The command '%(cmd)s' is restricted to moderators."), { | ||||
"cmd": coloredText(cmd, g_ChatCommandColor) | "cmd": setStringTags(cmd, g_ChatCommandTextTags) | ||||
}) | }) | ||||
}); | }); | ||||
return false; | return false; | ||||
} | } | ||||
return g_ChatCommands[cmd].handler(args); | return g_ChatCommands[cmd].handler(args); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | if (msg.text && msg.text[0] == '/') | ||||
{ | { | ||||
// Translation: IRC message prefix when the sender uses the /me command. | // Translation: IRC message prefix when the sender uses the /me command. | ||||
let senderString = sprintf(translate("* %(sender)s"), { | let senderString = sprintf(translate("* %(sender)s"), { | ||||
"sender": coloredFrom | "sender": coloredFrom | ||||
}); | }); | ||||
// Translation: IRC message issued using the ‘/me’ command. | // Translation: IRC message issued using the ‘/me’ command. | ||||
formattedMessage = sprintf(translate("%(sender)s %(action)s"), { | formattedMessage = sprintf(translate("%(sender)s %(action)s"), { | ||||
"sender": senderFont(senderString), | "sender": setStringTags(senderString, g_SenderTextTags), | ||||
"action": message | "action": message | ||||
}); | }); | ||||
break; | break; | ||||
} | } | ||||
case "say": | case "say": | ||||
{ | { | ||||
// Translation: IRC message prefix. | // Translation: IRC message prefix. | ||||
let senderString = sprintf(translate("<%(sender)s>"), { | let senderString = sprintf(translate("<%(sender)s>"), { | ||||
"sender": coloredFrom | "sender": coloredFrom | ||||
}); | }); | ||||
// Translation: IRC message. | // Translation: IRC message. | ||||
formattedMessage = sprintf(translate("%(sender)s %(message)s"), { | formattedMessage = sprintf(translate("%(sender)s %(message)s"), { | ||||
"sender": senderFont(senderString), | "sender": setStringTags(senderString, g_SenderTextTags), | ||||
"message": message | "message": message | ||||
}); | }); | ||||
break; | break; | ||||
} | } | ||||
case "special": | case "special": | ||||
{ | { | ||||
if (msg.isSpecial) | if (msg.isSpecial) | ||||
// Translation: IRC system message. | // Translation: IRC system message. | ||||
formattedMessage = senderFont(sprintf(translate("== %(message)s"), { | formattedMessage = setStringTags(sprintf(translate("== %(message)s"), { | ||||
"message": message | "message": message | ||||
})); | }), g_SenderTextTags); | ||||
else | else | ||||
{ | { | ||||
// Translation: IRC message prefix. | // Translation: IRC message prefix. | ||||
let senderString = sprintf(translate("<%(sender)s>"), { | let senderString = sprintf(translate("<%(sender)s>"), { | ||||
"sender": coloredFrom | "sender": coloredFrom | ||||
}); | }); | ||||
// Translation: IRC message. | // Translation: IRC message. | ||||
formattedMessage = sprintf(translate("%(sender)s %(message)s"), { | formattedMessage = sprintf(translate("%(sender)s %(message)s"), { | ||||
"sender": senderFont(senderString), | "sender": setStringTags(senderString, g_SenderTextTags), | ||||
"message": message | "message": message | ||||
}); | }); | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
default: | default: | ||||
return ""; | return ""; | ||||
} | } | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
let senderString; | let senderString; | ||||
// Translation: IRC message prefix. | // Translation: IRC message prefix. | ||||
if (msg.private) | if (msg.private) | ||||
senderString = sprintf(translateWithContext("lobby private message", "(%(private)s) <%(sender)s>"), { | senderString = sprintf(translateWithContext("lobby private message", "(%(private)s) <%(sender)s>"), { | ||||
"private": coloredText(translate("Private"), g_PrivateMessageColor), | "private": setStringTags(translate("Private"), g_PrivateMessageTextTags), | ||||
"sender": coloredFrom | "sender": coloredFrom | ||||
}); | }); | ||||
else | else | ||||
senderString = sprintf(translate("<%(sender)s>"), { | senderString = sprintf(translate("<%(sender)s>"), { | ||||
"sender": coloredFrom | "sender": coloredFrom | ||||
}); | }); | ||||
// Translation: IRC message. | // Translation: IRC message. | ||||
formattedMessage = sprintf(translate("%(sender)s %(message)s"), { | formattedMessage = sprintf(translate("%(sender)s %(message)s"), { | ||||
"sender": senderFont(senderString), | "sender": setStringTags(senderString, g_SenderTextTags), | ||||
"message": msg.text | "message": msg.text | ||||
}); | }); | ||||
} | } | ||||
// Add chat message timestamp | // Add chat message timestamp | ||||
if (Engine.ConfigDB_GetValue("user", "chat.timestamp") != "true") | if (Engine.ConfigDB_GetValue("user", "chat.timestamp") != "true") | ||||
return formattedMessage; | return formattedMessage; | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | function colorPlayerName(playername, rating) | ||||
return coloredText( | return coloredText( | ||||
(rating ? sprintf( | (rating ? sprintf( | ||||
translate("%(nick)s (%(rating)s)"), { | translate("%(nick)s (%(rating)s)"), { | ||||
"nick": playername, | "nick": playername, | ||||
"rating": rating | "rating": rating | ||||
}) : playername | }) : playername | ||||
), | ), | ||||
getPlayerColor(playername.replace(g_ModeratorPrefix, ""))); | getPlayerColor(playername.replace(g_ModeratorPrefix, ""))); | ||||
} | } | ||||
Done Inline Actions(same) elexis: (same) | |||||
function senderFont(text) | |||||
{ | |||||
return '[font="' + g_SenderFont + '"]' + text + "[/font]"; | |||||
} | |||||
function formatWinRate(attr) | function formatWinRate(attr) | ||||
Done Inline Actions(I suppose the function is short enough to be removed now) elexis: (I suppose the function is short enough to be removed now) | |||||
{ | { | ||||
if (!attr.totalGamesPlayed) | if (!attr.totalGamesPlayed) | ||||
return translateWithContext("Used for an undefined winning rate", "-"); | return translateWithContext("Used for an undefined winning rate", "-"); | ||||
return sprintf(translate("%(percentage)s%%"), { | return sprintf(translate("%(percentage)s%%"), { | ||||
"percentage": (attr.wins / attr.totalGamesPlayed * 100).toFixed(2) | "percentage": (attr.wins / attr.totalGamesPlayed * 100).toFixed(2) | ||||
}); | }); | ||||
} | } |
Wildfire Games · Phabricator
(Aligning whitespace will be removed in d2261 to please Jenkins)