Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/lobby/lobby.js
Show First 20 Lines • Show All 1,221 Lines • ▼ Show 20 Lines | |||||
* @param {string} text - Text to be checked for commands. | * @param {string} text - Text to be checked for commands. | ||||
* @returns {boolean} true if the text should be sent via chat. | * @returns {boolean} true if the text should be sent via chat. | ||||
*/ | */ | ||||
function handleChatCommand(text) | function handleChatCommand(text) | ||||
{ | { | ||||
if (text[0] != '/') | if (text[0] != '/') | ||||
return true; | return true; | ||||
let [cmd, args] = ircSplit(text); | let [cmd, args] = splitChatMessage(text); | ||||
args = ircSplit("/" + args); | args = splitChatMessage("/" + 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": coloredText(cmd, g_ChatCommandColor) | ||||
Show All 34 Lines | if (msg.from) | ||||
{ | { | ||||
msg.text = msg.text.replace(g_Username, colorPlayerName(g_Username)); | msg.text = msg.text.replace(g_Username, colorPlayerName(g_Username)); | ||||
if (!msg.historic && msg.text.toLowerCase().indexOf(g_Username.toLowerCase()) != -1) | if (!msg.historic && msg.text.toLowerCase().indexOf(g_Username.toLowerCase()) != -1) | ||||
soundNotification("nick"); | soundNotification("nick"); | ||||
} | } | ||||
} | } | ||||
let formatted = ircFormat(msg); | let formatted = formatChatMessage(msg); | ||||
if (!formatted) | if (!formatted) | ||||
return; | return; | ||||
g_ChatMessages.push(formatted); | g_ChatMessages.push(formatted); | ||||
Engine.GetGUIObjectByName("chatText").caption = g_ChatMessages.join("\n"); | Engine.GetGUIObjectByName("chatText").caption = g_ChatMessages.join("\n"); | ||||
} | } | ||||
/** | /** | ||||
* Splits given input into command and argument. | * Splits given input into command and argument. | ||||
*/ | */ | ||||
function ircSplit(string) | function splitChatMessage(string) | ||||
{ | { | ||||
let idx = string.indexOf(' '); | let idx = string.indexOf(' '); | ||||
bb: (wondering why single `'` are used and not `"`, but out of scope I guess) | |||||
if (idx != -1) | if (idx != -1) | ||||
return [string.substr(1, idx - 1), string.substr(idx + 1)]; | return [string.substr(1, idx - 1), string.substr(idx + 1)]; | ||||
return [string.substr(1), ""]; | return [string.substr(1), ""]; | ||||
} | } | ||||
Not Done Inline ActionsLast time I came around this I didn't find a nice way to obliterate it. Would be nice to find some JS split magic for it and have it inlined. elexis: Last time I came around this I didn't find a nice way to obliterate it. Would be nice to find… | |||||
Not Done Inline Actionsmessages.js uses // Split addressee command and message-text msg.cmd = msg.text.split(/\s/)[0]; msg.text = msg.text.substr(msg.cmd.length + 1); You could do split to get an array of words then add back spaces later. temple: messages.js uses
```
// Split addressee command and message-text
msg.cmd = msg.text.split… | |||||
/** | /** | ||||
* Format text in an IRC-like way. | * Format text in an IRC-like way. | ||||
templeAuthorUnsubmitted Not Done Inline ActionsDon't know what to do here, if anything. temple: Don't know what to do here, if anything. | |||||
bbUnsubmitted Not Done Inline Actionsthe comment seems valid, so nothing is ok imo bb: the comment seems valid, so nothing is ok imo | |||||
* | * | ||||
* @param {Object} msg - Received chat message. | * @param {Object} msg - Received chat message. | ||||
* @returns {string} - Formatted text. | * @returns {string} - Formatted text. | ||||
*/ | */ | ||||
function ircFormat(msg) | function formatChatMessage(msg) | ||||
Not Done Inline ActionsformatChatMessage? elexis: `formatChatMessage`? | |||||
{ | { | ||||
let formattedMessage = ""; | let formattedMessage = ""; | ||||
let coloredFrom = msg.from && colorPlayerName(msg.from); | let coloredFrom = msg.from && colorPlayerName(msg.from); | ||||
// Handle commands allowed past handleChatCommand. | // Handle commands allowed past handleChatCommand. | ||||
if (msg.text[0] == '/') | if (msg.text[0] == '/') | ||||
{ | { | ||||
let [command, message] = ircSplit(msg.text); | let [command, message] = splitChatMessage(msg.text); | ||||
switch (command) | switch (command) | ||||
{ | { | ||||
case "me": | case "me": | ||||
{ | { | ||||
// Translation: IRC message prefix when the sender uses the /me command. | // Translation: Chat 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: Chat message issued using the ‘/me’ command. | ||||
bbUnsubmitted Not Done Inline Actionswhy is here some quotation and in previous comment not? bb: why is here some quotation and in previous comment not? | |||||
formattedMessage = sprintf(translate("%(sender)s %(action)s"), { | formattedMessage = sprintf(translate("%(sender)s %(action)s"), { | ||||
"sender": senderFont(senderString), | "sender": senderFont(senderString), | ||||
"action": message | "action": message | ||||
}); | }); | ||||
break; | break; | ||||
} | } | ||||
case "say": | case "say": | ||||
{ | { | ||||
// Translation: IRC message prefix. | // Translation: Chat message prefix. | ||||
bbUnsubmitted Not Done Inline Actionsand why isn't here the /me type explanation? bb: and why isn't here the /me type explanation? | |||||
let senderString = sprintf(translate("<%(sender)s>"), { | let senderString = sprintf(translate("<%(sender)s>"), { | ||||
"sender": coloredFrom | "sender": coloredFrom | ||||
}); | }); | ||||
// Translation: IRC message. | // Translation: Chat message. | ||||
formattedMessage = sprintf(translate("%(sender)s %(message)s"), { | formattedMessage = sprintf(translate("%(sender)s %(message)s"), { | ||||
"sender": senderFont(senderString), | "sender": senderFont(senderString), | ||||
"message": message | "message": message | ||||
}); | }); | ||||
break; | break; | ||||
} | } | ||||
case "special": | case "special": | ||||
{ | { | ||||
if (msg.isSpecial) | if (msg.isSpecial) | ||||
// Translation: IRC system message. | // Translation: System chat message. | ||||
formattedMessage = senderFont(sprintf(translate("== %(message)s"), { | formattedMessage = senderFont(sprintf(translate("== %(message)s"), { | ||||
"message": message | "message": message | ||||
})); | })); | ||||
else | else | ||||
{ | { | ||||
// Translation: IRC message prefix. | // Translation: Chat message prefix. | ||||
let senderString = sprintf(translate("<%(sender)s>"), { | let senderString = sprintf(translate("<%(sender)s>"), { | ||||
"sender": coloredFrom | "sender": coloredFrom | ||||
}); | }); | ||||
// Translation: IRC message. | // Translation: Chat message. | ||||
formattedMessage = sprintf(translate("%(sender)s %(message)s"), { | formattedMessage = sprintf(translate("%(sender)s %(message)s"), { | ||||
"sender": senderFont(senderString), | "sender": senderFont(senderString), | ||||
"message": message | "message": message | ||||
}); | }); | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
default: | default: | ||||
return ""; | return ""; | ||||
} | } | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
let senderString; | let senderString; | ||||
// Translation: IRC message prefix. | |||||
if (msg.private) | if (msg.private) | ||||
senderString = sprintf(translateWithContext("lobby private message", "(%(private)s) <%(sender)s>"), { | // Translation: Chat message prefix when it is a private message. | ||||
"private": coloredText(translate("Private"), g_PrivateMessageColor), | senderString = sprintf(translate("(%(private)s) <%(sender)s>"), { | ||||
"private": coloredText(translateWithContext("chat message", "Private"), g_PrivateMessageColor), | |||||
"sender": coloredFrom | "sender": coloredFrom | ||||
}); | }); | ||||
else | else | ||||
// Translation: Chat message prefix. | |||||
Not Done Inline ActionsI've always wondered why we speak of IRC messages in XMPP. Can we shoot at it? Just replacing IRC with chat everywhere should do. elexis: I've always wondered why we speak of IRC messages in XMPP. Can we shoot at it? Just replacing… | |||||
senderString = sprintf(translate("<%(sender)s>"), { | senderString = sprintf(translate("<%(sender)s>"), { | ||||
"sender": coloredFrom | "sender": coloredFrom | ||||
}); | }); | ||||
// Translation: IRC message. | // Translation: Chat message. | ||||
formattedMessage = sprintf(translate("%(sender)s %(message)s"), { | formattedMessage = sprintf(translate("%(sender)s %(message)s"), { | ||||
"sender": senderFont(senderString), | "sender": senderFont(senderString), | ||||
"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; | ||||
// Translation: Time as shown in the multiplayer lobby (when you enable it in the options page). | // Translation: Time as shown in the multiplayer lobby (when you enable it in the options page). | ||||
// For a list of symbols that you can use, see: | // For a list of symbols that you can use, see: | ||||
// https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table | // https://sites.google.com/site/icuprojectuserguide/formatparse/datetime?pli=1#TOC-Date-Field-Symbol-Table | ||||
let timeString = Engine.FormatMillisecondsIntoDateStringLocal(msg.time ? msg.time * 1000 : Date.now(), translate("HH:mm")); | let timeString = Engine.FormatMillisecondsIntoDateStringLocal(msg.time ? msg.time * 1000 : Date.now(), translate("HH:mm")); | ||||
// Translation: Time prefix as shown in the multiplayer lobby (when you enable it in the options page). | // Translation: Time prefix as shown in the multiplayer lobby (when you enable it in the options page). | ||||
let timePrefixString = sprintf(translate("\\[%(time)s]"), { | let timePrefixString = sprintf(translate("\\[%(time)s]"), { | ||||
"time": timeString | "time": timeString | ||||
}); | }); | ||||
// Translation: IRC message format when there is a time prefix. | // Translation: Chat message format when there is a time prefix. | ||||
return sprintf(translate("%(time)s %(message)s"), { | return sprintf(translate("%(time)s %(message)s"), { | ||||
"time": senderFont(timePrefixString), | "time": senderFont(timePrefixString), | ||||
"message": formattedMessage | "message": formattedMessage | ||||
}); | }); | ||||
} | } | ||||
/** | /** | ||||
* Generate a (mostly) unique color for this player based on their name. | * Generate a (mostly) unique color for this player based on their name. | ||||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
(wondering why single ' are used and not ", but out of scope I guess)