Differential D2412 Diff 10323 binaries/data/mods/public/gui/lobby/LobbyPage/Chat/ChatMessageFormat/ChatMessageFormat.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/lobby/LobbyPage/Chat/ChatMessageFormat/ChatMessageFormat.js
- This file was added.
Property | Old Value | New Value |
---|---|---|
svn:eol-style | null | native \ No newline at end of property |
/** | |||||
* Formats a chat message accounting for | |||||
* format commands such as /me or /say and | |||||
* private messages. | |||||
* | |||||
* Plays an acoustic notification if the playername was mentioned | |||||
*/ | |||||
class ChatMessageFormat | |||||
{ | |||||
constructor() | |||||
{ | |||||
this.formatMe = new ChatMessageFormatMe(); | |||||
this.formatSay = new ChatMessageFormatSay(); | |||||
this.formatPrivate = new ChatMessagePrivateWrapper(); | |||||
} | |||||
/** | |||||
* Message properties: from, text, historic, optionally private | |||||
*/ | |||||
format(message) | |||||
{ | |||||
let text = message.text; | |||||
if (g_Username != message.from) | |||||
{ | |||||
// Highlight nicknames | |||||
text = text.replace(g_Username, PlayerColor.ColorPlayerName(g_Username)); | |||||
// Notify local player | |||||
if (!message.historic && text.toLowerCase().indexOf(g_Username.toLowerCase()) != -1) | |||||
soundNotification("nick"); | |||||
} | |||||
let sender = message.from; | |||||
if (Engine.LobbyGetPlayerRole(message.from) == "moderator") | |||||
sender = g_ModeratorPrefix + sender; | |||||
sender = PlayerColor.ColorPlayerName(sender); | |||||
// Handle chat format commands | |||||
let formattedMessage; | |||||
if (text.startsWith("/")) | |||||
{ | |||||
let command; | |||||
[command, text] = message.text.substr(1).split(" ", 1); | |||||
switch (command) | |||||
{ | |||||
case "me": | |||||
{ | |||||
formattedMessage = this.formatMe.format(sender, text || ""); | |||||
break; | |||||
} | |||||
case "say": | |||||
{ | |||||
formattedMessage = this.formatSay.format(sender, text || ""); | |||||
break; | |||||
} | |||||
default: | |||||
{ | |||||
formattedMessage = this.formatSay.format(sender, message.text); | |||||
break; | |||||
} | |||||
} | |||||
} | |||||
else | |||||
formattedMessage = this.formatSay.format(sender, text); | |||||
if (message.private) | |||||
formattedMessage = this.formatPrivate.format(formattedMessage); | |||||
return formattedMessage; | |||||
} | |||||
} |
Wildfire Games · Phabricator