1
0
forked from mirrors/0ad

Session chat cleanup.

Use .property instead of ["property"].
Use if (object.property) instead of if ("property" in object).
Use array- and fat-arrow functions.

This was SVN commit r17537.
This commit is contained in:
elexis
2015-12-22 17:37:22 +00:00
parent 3ba50b4ed4
commit ae92736b02
2 changed files with 25 additions and 36 deletions
@@ -93,46 +93,41 @@ var g_NotificationsTypes =
{
let message = {
"type": "message",
"guid": findGuidForPlayerID(g_PlayerAssignments, player) || -1,
"text": notification.message
};
let guid = findGuidForPlayerID(g_PlayerAssignments, player);
if (guid == undefined)
{
message["guid"] = -1;
message["player"] = player;
} else {
message["guid"] = guid;
}
if (message.guid == -1)
message.player = player;
addChatMessage(message);
},
"aichat": function(notification, player)
{
let message = {
"guid": findGuidForPlayerID(g_PlayerAssignments, player) || -1,
"type": "message",
"text": notification.message
"text": notification.message,
"translate": true
};
message["translate"] = true;
if ("translateParameters" in notification)
if (message.guid == -1)
message.player = player;
if (notification.translateParameters)
{
message["translateParameters"] = notification["translateParameters"];
message["parameters"] = notification["parameters"];
message.translateParameters = notification.translateParameters;
message.parameters = notification.parameters;
// special case for formatting of player names which are transmitted as _player_num
for (let param in message["parameters"])
for (let param in message.parameters)
{
if (!param.startsWith("_player_"))
continue;
let colorName = getUsernameAndColor(+message["parameters"][param]);
message["parameters"][param] = "[color=\"" + colorName[1] + "\"]" + colorName[0] + "[/color]";
let colorName = getUsernameAndColor(+message.parameters[param]);
message.parameters[param] = "[color=\"" + colorName[1] + "\"]" + colorName[0] + "[/color]";
}
}
let guid = findGuidForPlayerID(g_PlayerAssignments, player);
if (guid == undefined)
{
message["guid"] = -1;
message["player"] = player;
} else {
message["guid"] = guid;
}
addChatMessage(message);
},
"defeat": function(notification, player)
@@ -574,11 +569,11 @@ function formatTributeMessage(msg)
// Format the amounts to proper English: 200 food, 100 wood, and 300 metal; 100 food; 400 wood and 200 stone
let amounts = Object.keys(msg.amounts)
.filter(function (type) { return msg.amounts[type] > 0; })
.map(function (type) { return sprintf(translate("%(amount)s %(resourceType)s"), {
.filter(type => msg.amounts[type] > 0)
.map(type => sprintf(translate("%(amount)s %(resourceType)s"), {
"amount": msg.amounts[type],
"resourceType": getLocalizedResourceName(type, "withinSentence")});
});
"resourceType": getLocalizedResourceName(type, "withinSentence")
}));
if (amounts.length > 1)
{
@@ -55,15 +55,9 @@ function getPlayerData(playerAssignments)
return players;
}
function findGuidForPlayerID(playerAssignments, player)
function findGuidForPlayerID(playerID)
{
for (var playerGuid in playerAssignments)
{
var playerAssignment = playerAssignments[playerGuid];
if (playerAssignment.player == player)
return playerGuid;
}
return undefined;
return Object.keys(g_PlayerAssignments).find(guid => g_PlayerAssignments[guid].player == playerID);
}
// Update player data when a host has connected