From 26f919b9ced0b65e55de600c083f7a550aa3359d Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Fri, 11 Dec 2020 21:08:19 +0100 Subject: [PATCH 01/33] chat: define atomic markup rendering --- core/code/chat.js | 75 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 17 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index ca4f7d988..4b6097649 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -380,30 +380,17 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is break; case 'TEXT': - msg += $('
').text(markup[1].plain).html().autoLink(); + msg += chat.renderText(markup[1]); break; case 'AT_PLAYER': var thisToPlayer = (markup[1].plain == ('@'+window.PLAYER.nickname)); - var spanClass = thisToPlayer ? "pl_nudge_me" : (markup[1].team + " pl_nudge_player"); - var atPlayerName = markup[1].plain.replace(/^@/, ""); - msg += $('').html($('') - .attr('class', spanClass) - .attr('onclick',"window.chat.nicknameClicked(event, '"+atPlayerName+"')") - .text(markup[1].plain)).html(); + msg += chat.renderPlayer(markup[1], true); msgToPlayer = msgToPlayer || thisToPlayer; break; case 'PORTAL': - var lat = markup[1].latE6/1E6, lng = markup[1].lngE6/1E6; - var perma = window.makePermalink([lat,lng]); - var js = 'window.selectPortalByLatLng('+lat+', '+lng+');return false'; - - msg += '' - + window.chat.getChatPortalName(markup[1]) - + ''; + msg += chat.renderPortal(markup[1]); break; case 'SECURE': @@ -413,7 +400,7 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is default: //handle unknown types by outputting the plain text version, marked with it's type - msg += $('').text(markup[0]+':<'+markup[1].plain+'>').html(); + msg += chat.renderMarkupEntity(markup); break; } }); @@ -452,6 +439,60 @@ window.chat.getChatPortalName = function(markup) { return name; } +window.chat.renderText = function (text) { + return $('').text(text.plain).html().autoLink(); +} + +window.chat.renderPortal = function (portal) { + var lat = portal.latE6/1E6, lng = portal.lngE6/1E6; + var perma = window.makePermalink([lat,lng]); + var js = 'window.selectPortalByLatLng('+lat+', '+lng+');return false'; + return '' + + window.chat.getChatPortalName(portal) + + ''; +} + +window.chat.renderFactionEnt = function (faction) { + var name = faction.team == "ENLIGHTENED" ? "Enlightened" : "Resistance"; + var spanClass = faction.team == "ENLIGHTENED" ? TEAM_ENL : TEAM_RES; + return $('').html($('') + .attr('class', spanClass) + .text(name)).html(); +} + +window.chat.renderPlayer = function (player, at, sender) { + var name = (sender) ? player.plain.slice(0, -2) : (at) ? player.plain.slice(1) : player.plain; + var thisToPlayer = name == window.PLAYER.nickname; + var spanClass = thisToPlayer ? "pl_nudge_me" : (player.team + " pl_nudge_player"); + return $('').html($('') + .attr('class', spanClass) + .attr('onclick',"window.chat.nicknameClicked(event, '"+name+"')") + .text((at ? '@' : '') + name)).html(); +} + +window.chat.renderMarkupEntity = function (ent) { + switch (ent[0]) { + case 'TEXT': + return chat.renderText(ent[1]); + case 'PORTAL': + return chat.renderPortal(ent[1]); + case 'FACTION': + return chat.renderFactionEnt(ent[1]); + case 'SENDER': + return chat.renderPlayer(ent[1], false, true); + case 'PLAYER': + return chat.renderPlayer(ent[1]); + case 'AT_PLAYER': + return chat.renderPlayer(ent[1], true); + case 'TEXT': + return $('').text(ent[1].plain).html().autoLink(); + default: + } + return $('').text(ent[0]+':<'+ent[1].plain+'>').html(); +} + // renders data from the data-hash to the element defined by the given // ID. Set 3rd argument to true if it is likely that old data has been // added. Latter is only required for scrolling. From 0e0d0afa176b51dc07c7c51f8a29efcc6d0560e3 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Fri, 11 Dec 2020 21:53:00 +0100 Subject: [PATCH 02/33] chat: use plext.categories --- core/code/chat.js | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index 4b6097649..37ead80d8 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -355,8 +355,12 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is // avoid duplicates if(json[0] in storageHash.data) return true; - var isSecureMessage = false; - var msgToPlayer = false; + var categories = json[2].plext.categories; + var isPublic = (categories & 1) == 1; + var isSecure = (categories & 2) == 2; + var msgAlert = (categories & 4) == 4; + + var msgToPlayer = msgAlert && (isPublic || isSecure); var time = json[1]; var team = json[2].plext.team === 'RESISTANCE' ? TEAM_RES : TEAM_ENL; @@ -384,9 +388,7 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is break; case 'AT_PLAYER': - var thisToPlayer = (markup[1].plain == ('@'+window.PLAYER.nickname)); msg += chat.renderPlayer(markup[1], true); - msgToPlayer = msgToPlayer || thisToPlayer; break; case 'PORTAL': @@ -395,7 +397,6 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is case 'SECURE': //NOTE: we won't add the '[secure]' string here - it'll be handled below instead - isSecureMessage = true; break; default: @@ -418,9 +419,9 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is //both the public and private channels //we don't include this '[secure]' text above, as it's redundant in the faction-only channel //let's add it here though if we have a secure message in the public channel, or the reverse if a non-secure in the faction one - if (!auto && !(isPublicChannel===false) && isSecureMessage) msg = '[faction] ' + msg; + if (!auto && !(isPublicChannel===false) && isSecure) msg = '[faction] ' + msg; //and, add the reverse - a 'public' marker to messages in the private channel - if (!auto && !(isPublicChannel===true) && (!isSecureMessage)) msg = '[public] ' + msg; + if (!auto && !(isPublicChannel===true) && (!isSecure)) msg = '[public] ' + msg; // format: timestamp, autogenerated, HTML message From 96e457cc45a4232a0257e5312fe7b45c1083457b Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Fri, 11 Dec 2020 21:58:58 +0100 Subject: [PATCH 03/33] chat: use renderMarkupEntity for some refactor --- core/code/chat.js | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index 37ead80d8..ef6302113 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -383,24 +383,12 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is if(ind > 0) msg += nick; // don’t repeat nick directly break; - case 'TEXT': - msg += chat.renderText(markup[1]); - break; - - case 'AT_PLAYER': - msg += chat.renderPlayer(markup[1], true); - break; - - case 'PORTAL': - msg += chat.renderPortal(markup[1]); - break; - case 'SECURE': //NOTE: we won't add the '[secure]' string here - it'll be handled below instead break; default: - //handle unknown types by outputting the plain text version, marked with it's type + // add other enitities whatever the type msg += chat.renderMarkupEntity(markup); break; } From 6fc7c70e4135d44f82a495b3362ac4bedff84a0e Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Fri, 11 Dec 2020 23:46:19 +0100 Subject: [PATCH 04/33] chat: use css for [public]/[faction] --- core/code/chat.js | 23 ++++++++++++----------- core/style.css | 16 ++++++++++++++++ 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index ef6302113..1b69c555d 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -402,18 +402,18 @@ window.chat.writeDataToHash = function(newData, storageHash, isPublicChannel, is // if ((!isPublicChannel) && (!isSecureMessage)) return true; - //NOTE: these two are redundant with the above two tests in place - but things have changed... - //from the server, private channel messages are flagged with a SECURE string '[secure] ', and appear in - //both the public and private channels - //we don't include this '[secure]' text above, as it's redundant in the faction-only channel - //let's add it here though if we have a secure message in the public channel, or the reverse if a non-secure in the faction one - if (!auto && !(isPublicChannel===false) && isSecure) msg = '[faction] ' + msg; - //and, add the reverse - a 'public' marker to messages in the private channel - if (!auto && !(isPublicChannel===true) && (!isSecure)) msg = '[public] ' + msg; + // //NOTE: these two are redundant with the above two tests in place - but things have changed... + // //from the server, private channel messages are flagged with a SECURE string '[secure] ', and appear in + // //both the public and private channels + // //we don't include this '[secure]' text above, as it's redundant in the faction-only channel + // //let's add it here though if we have a secure message in the public channel, or the reverse if a non-secure in the faction one + // if (!auto && !(isPublicChannel===false) && isSecure) msg = '[faction] ' + msg; + // //and, add the reverse - a 'public' marker to messages in the private channel + // if (!auto && !(isPublicChannel===true) && (!isSecure)) msg = '[public] ' + msg; // format: timestamp, autogenerated, HTML message - storageHash.data[json[0]] = [json[1], auto, chat.renderMsg(msg, nick, time, team, msgToPlayer, systemNarrowcast), nick]; + storageHash.data[json[0]] = [json[1], auto, chat.renderMsg(msg, nick, time, team, msgToPlayer, systemNarrowcast, isPublic, isSecure, msgAlert), nick]; }); } @@ -517,7 +517,7 @@ window.chat.renderDivider = function(text) { } -window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarrowcast) { +window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarrowcast, isPublic, isSecure, msgAlert) { var ta = unixTimeToHHmm(time); var tb = unixTimeToDateTimeString(time, true); //add tags around the milliseconds @@ -537,7 +537,8 @@ window.chat.renderMsg = function(msg, nick, time, team, msgToPlayer, systemNarro if (nick === window.PLAYER.nickname) color = '#fd6'; //highlight things said/done by the player in a unique colour (similar to @player mentions from others in the chat text itself) var s = 'style="cursor:pointer; color:'+color+'"'; var i = ['<', '>']; - return '