From 23edee74dd5b32c704799ba97f43ecadbedaef66 Mon Sep 17 00:00:00 2001 From: McBen Date: Sun, 14 May 2023 21:31:03 +0200 Subject: [PATCH 1/8] Chat: Format neutrals (machina) --- core/code/chat.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index fff821b83..0cbe2d7da 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -356,7 +356,14 @@ window.chat.updateOldNewHash = function(newData, storageHash, isOlderMsgs, isAsc } }; -window.chat.parseMsgData = function(data) { +function team2id(team) { + if (team === 'RESISTANCE') return TEAM_RES; + if (team === 'ENLIGHTENED') return TEAM_ENL; + return TEAM_NONE; +} + + +window.chat.parseMsgData = function (data) { var categories = data[2].plext.categories; var isPublic = (categories & 1) === 1; var isSecure = (categories & 2) === 2; @@ -365,7 +372,7 @@ window.chat.parseMsgData = function(data) { var msgToPlayer = msgAlert && (isPublic || isSecure); var time = data[1]; - var team = data[2].plext.team === 'RESISTANCE' ? TEAM_RES : TEAM_ENL; + var team = team2id(data[2].plext.team); var auto = data[2].plext.plextType !== 'PLAYER_GENERATED'; var systemNarrowcast = data[2].plext.plextType === 'SYSTEM_NARROWCAST'; @@ -380,7 +387,7 @@ window.chat.parseMsgData = function(data) { case 'PLAYER': // automatically generated messages nick = ent[1].plain; - team = ent[1].team === 'RESISTANCE' ? TEAM_RES : TEAM_ENL; + team = team2id(ent[1].team); break; default: @@ -545,7 +552,7 @@ window.chat.renderMsgRow = function(data) { var timeCell = chat.renderTimeCell(data.time, timeClass); var nickClasses = ['nickname']; - if (data.player.team === TEAM_ENL || data.player.team === TEAM_RES) { + if (TEAM_TO_CSS[data.player.team]) { nickClasses.push(TEAM_TO_CSS[data.player.team]); } // highlight things said/done by the player in a unique colour From ce355523c7a6048bfc3d3129d39d394cc12c6f5e Mon Sep 17 00:00:00 2001 From: McBen Date: Sun, 14 May 2023 21:33:24 +0200 Subject: [PATCH 2/8] PlayerTracker: Ignore neutral players (Machina) --- plugins/player-activity-tracker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/player-activity-tracker.js b/plugins/player-activity-tracker.js index 8c3f4bff1..912885128 100644 --- a/plugins/player-activity-tracker.js +++ b/plugins/player-activity-tracker.js @@ -169,7 +169,7 @@ window.plugin.playerTracker.processNewData = function(data) { }); // skip unusable events - if(!plrname || !lat || !lng || !id || skipThisMessage) return true; + if (!plrname || !lat || !lng || !id || skipThisMessage || json[2].plext.team === 'NEUTRAL') return true; var newEvent = { latlngs: [[lat, lng]], From 72190192fd0f4c5308f530e2248de3a98fd5b31a Mon Sep 17 00:00:00 2001 From: McBen Date: Mon, 15 May 2023 15:49:03 +0200 Subject: [PATCH 3/8] plugins: Add machina tracker this is basically a copy of the player tracker. But it will track only neutral player and mark all their locations instead of drawing a path --- plugins/machina_tracker.user.js | 263 ++++++++++++++++++++++++++++++++ 1 file changed, 263 insertions(+) create mode 100644 plugins/machina_tracker.user.js diff --git a/plugins/machina_tracker.user.js b/plugins/machina_tracker.user.js new file mode 100644 index 000000000..392d1f005 --- /dev/null +++ b/plugins/machina_tracker.user.js @@ -0,0 +1,263 @@ +// @name IITC Plugin: Machina tracker +// @author McBen +// @category Layer +// @version 1.0.0 +// @description Show locations of Machina activities + +/* exported setup --eslint */ +/* global plugin,L,addHook */ + +// ensure plugin framework is there, even if iitc is not yet loaded +if (typeof window.plugin !== 'function') window.plugin = function () {}; + +// PLUGIN START //////////////////////////////////////////////////////// +window.MACHINA_TRACKER_MAX_TIME = 8 * 60 * 60 * 1000; +window.MACHINA_TRACKER_MIN_ZOOM = 9; +window.MACHINA_TRACKER_MIN_OPACITY = 0.3; + +// use own namespace for plugin +window.plugin.machinaTracker = function () {}; + +window.plugin.machinaTracker.setup = function () { + var iconImage = + 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAgCAYAAAAIXrg4AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGXRFWHRTb2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FvbBMB98XhVlaSXvr9nj/mpAZ7av/9c0jDOJnw+elOpiZmOjqF70d0zACCsKN97dMWKmqqqP9m9e7f9qQO2Dw2NabL8o3w6/Zt71QD8E9pooARVAdfGAAAAAElFTkSuQmCC'; + + plugin.machinaTracker.icon = L.icon({ + iconUrl: iconImage, + iconSize: [26, 32], + iconAnchor: [12, 32], + }); + + plugin.machinaTracker.drawnTraces = new L.LayerGroup(); + window.addLayerGroup('Machina Tracker', plugin.machinaTracker.drawnTraces, true); + + addHook('publicChatDataAvailable', window.plugin.machinaTracker.handleData); + + window.map.on('zoomend', function () { + window.plugin.machinaTracker.zoomListener(); + }); + window.plugin.machinaTracker.zoomListener(); +}; + +window.plugin.machinaTracker.stored = {}; + +window.plugin.machinaTracker.zoomListener = function () { + var ctrl = $('.leaflet-control-layers-selector + span:contains("Machina Tracker")').parent(); + if (window.map.getZoom() < window.MACHINA_TRACKER_MIN_ZOOM) { + plugin.machinaTracker.drawnTraces.clearLayers(); + ctrl.addClass('disabled').attr('title', 'Zoom in to show those.'); + // note: zoomListener is also called at init time to set up things, so we only need to do this in here + window.chat.backgroundChannelData('plugin.machinaTracker', 'all', false); // disable this plugin's interest in 'all' COMM + } else { + ctrl.removeClass('disabled').attr('title', ''); + // note: zoomListener is also called at init time to set up things, so we only need to do this in here + window.chat.backgroundChannelData('plugin.machinaTracker', 'all', true); // enable this plugin's interest in 'all' COMM + } +}; + +window.plugin.machinaTracker.getLimit = function () { + return new Date().getTime() - window.MACHINA_TRACKER_MAX_TIME; +}; + +window.plugin.machinaTracker.discardOldData = function () { + var limit = plugin.machinaTracker.getLimit(); + $.each(plugin.machinaTracker.stored, function (plrname, player) { + var i; + var ev = player.events; + for (i = 0; i < ev.length; i++) { + if (ev[i].time >= limit) break; + } + if (i === 0) return true; + if (i === ev.length) return delete plugin.machinaTracker.stored[plrname]; + plugin.machinaTracker.stored[plrname].events.splice(0, i); + }); +}; + +window.plugin.machinaTracker.eventHasLatLng = function (ev, lat, lng) { + var hasLatLng = false; + $.each(ev.latlngs, function (ind, ll) { + if (ll[0] === lat && ll[1] === lng) { + hasLatLng = true; + return false; + } + }); + return hasLatLng; +}; + +window.plugin.machinaTracker.processNewData = function (data) { + var limit = plugin.machinaTracker.getLimit(); + $.each(data.result, function (ind, json) { + // skip old data + if (json[1] < limit) return true; + + // find player and portal information + var plrname, + lat, + lng, + id = null, + name, + address; + var skipThisMessage = false; + $.each(json[2].plext.markup, function (ind, markup) { + switch (markup[0]) { + case 'TEXT': + // Destroy link and field messages depend on where the link or + // field was originally created. Therefore it’s not clear which + // portal the player is at, so ignore it. + if ( + markup[1].plain.indexOf('destroyed the Link') !== -1 || + markup[1].plain.indexOf('destroyed a Control Field') !== -1 || + markup[1].plain.indexOf('Your Link') !== -1 + ) { + skipThisMessage = true; + return false; + } + break; + case 'PLAYER': + plrname = markup[1].plain; + break; + case 'PORTAL': + // link messages are “player linked X to Y” and the player is at + // X. + lat = lat ? lat : markup[1].latE6 / 1e6; + lng = lng ? lng : markup[1].lngE6 / 1e6; + + // no GUID in the data any more - but we need some unique string. use the latE6,lngE6 + id = markup[1].latE6 + ',' + markup[1].lngE6; + + name = name ? name : markup[1].name; + address = address ? address : markup[1].address; + break; + } + }); + + // skip unusable events + if (!plrname || !lat || !lng || !id || skipThisMessage || json[2].plext.team !== 'NEUTRAL') return true; + + var newEvent = { + latlngs: [[lat, lng]], + ids: [id], + time: json[1], + name: name, + address: address, + }; + + var playerData = window.plugin.machinaTracker.stored[plrname]; + + // short-path if this is a new player + if (!playerData || playerData.events.length === 0) { + plugin.machinaTracker.stored[plrname] = { + nick: plrname, + team: json[2].plext.team, + events: [newEvent], + }; + return true; + } + + var evts = playerData.events; + // there’s some data already. Need to find correct place to insert. + var i; + for (i = 0; i < evts.length; i++) { + if (evts[i].time > json[1]) break; + } + + var cmp = Math.max(i - 1, 0); + + // so we have an event that happened at the same time. Most likely + // this is multiple resos destroyed at the same time. + if (evts[cmp].time === json[1]) { + evts[cmp].latlngs.push([lat, lng]); + evts[cmp].ids.push(id); + plugin.machinaTracker.stored[plrname].events = evts; + return true; + } + + // the time changed. Is the player still at the same location? + + // assume this is an older event at the same location. Then we need + // to look at the next item in the event list. If this event is the + // newest one, there may not be a newer event so check for that. If + // it really is an older event at the same location, then skip it. + if (evts[cmp + 1] && plugin.machinaTracker.eventHasLatLng(evts[cmp + 1], lat, lng)) return true; + + // if this event is newer, need to look at the previous one + var sameLocation = plugin.machinaTracker.eventHasLatLng(evts[cmp], lat, lng); + + // if it’s the same location, just update the timestamp. Otherwise + // push as new event. + if (sameLocation) { + evts[cmp].time = json[1]; + } else { + evts.splice(i, 0, newEvent); + } + + // update player data + plugin.machinaTracker.stored[plrname].events = evts; + }); +}; + +window.plugin.machinaTracker.getLatLngFromEvent = function (ev) { + var lats = 0; + var lngs = 0; + $.each(ev.latlngs, function (i, latlng) { + lats += latlng[0]; + lngs += latlng[1]; + }); + + return L.latLng(lats / ev.latlngs.length, lngs / ev.latlngs.length); +}; + +window.plugin.machinaTracker.ago = function (time, now) { + var s = (now - time) / 1000; + var h = Math.floor(s / 3600); + var m = Math.floor((s % 3600) / 60); + var returnVal = m + 'm'; + if (h > 0) { + returnVal = h + 'h' + returnVal; + } + return returnVal; +}; + +window.plugin.machinaTracker.drawData = function () { + var isTouchDev = window.isTouchDevice(); + + var gllfe = plugin.machinaTracker.getLatLngFromEvent; + + var split = window.MACHINA_TRACKER_MAX_TIME / 4; + var now = new Date().getTime(); + + $.each(plugin.machinaTracker.stored, function (plrname, playerData) { + if (!playerData || playerData.events.length === 0) { + console.error('broken player data for plrname=' + plrname); + return true; + } + + for (var i = 0; i < playerData.events.length; i++) { + var p = playerData.events[i]; + var ageBucket = Math.min(parseInt((now - p.time) / split), 4 - 1); + var position = gllfe(p); + + var title = isTouchDev ? '' : plugin.machinaTracker.ago(p.time, now) + ' ago'; + var icon = plugin.machinaTracker.icon; + var opacity = 1 - 0.2 * ageBucket; + + var m = L.marker(position, { icon, opacity, title }); + // m.on('mouseout', function() { $(this._icon).tooltip('close'); }); + window.registerMarkerForOMS(m); + + m.addTo(plugin.machinaTracker.drawnTraces); + } + }); +}; + +window.plugin.machinaTracker.handleData = function (data) { + if (window.map.getZoom() < window.MACHINA_TRACKER_MIN_ZOOM) return; + + plugin.machinaTracker.discardOldData(); + plugin.machinaTracker.processNewData(data); + + plugin.machinaTracker.drawnTraces.clearLayers(); + plugin.machinaTracker.drawData(); +}; + +var setup = plugin.machinaTracker.setup; From b81675793f8cd5daf5779e99e47bed5041488a13 Mon Sep 17 00:00:00 2001 From: McBen Date: Sun, 21 May 2023 14:50:51 +0200 Subject: [PATCH 4/8] Chat: use teamStringToId --- core/code/chat.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index 0cbe2d7da..f7e39b1dd 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -1,3 +1,5 @@ +/* global teamStringToId, TEAM_TO_CSS */ + window.chat = function() {}; //WORK IN PROGRESS - NOT YET USED!! @@ -356,13 +358,6 @@ window.chat.updateOldNewHash = function(newData, storageHash, isOlderMsgs, isAsc } }; -function team2id(team) { - if (team === 'RESISTANCE') return TEAM_RES; - if (team === 'ENLIGHTENED') return TEAM_ENL; - return TEAM_NONE; -} - - window.chat.parseMsgData = function (data) { var categories = data[2].plext.categories; var isPublic = (categories & 1) === 1; @@ -372,7 +367,7 @@ window.chat.parseMsgData = function (data) { var msgToPlayer = msgAlert && (isPublic || isSecure); var time = data[1]; - var team = team2id(data[2].plext.team); + var team = window.teamStringToId(data[2].plext.team); var auto = data[2].plext.plextType !== 'PLAYER_GENERATED'; var systemNarrowcast = data[2].plext.plextType === 'SYSTEM_NARROWCAST'; @@ -387,7 +382,7 @@ window.chat.parseMsgData = function (data) { case 'PLAYER': // automatically generated messages nick = ent[1].plain; - team = team2id(ent[1].team); + team = window.teamStringToId(ent[1].team); break; default: From 79198ec6863d1d554ff90443dc5e8e39869da2b5 Mon Sep 17 00:00:00 2001 From: McBen Date: Sun, 21 May 2023 15:00:49 +0200 Subject: [PATCH 5/8] chat: (codestyle) making eslint happy --- core/code/chat.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/code/chat.js b/core/code/chat.js index f7e39b1dd..fc9b522b9 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -1,4 +1,4 @@ -/* global teamStringToId, TEAM_TO_CSS */ +/* global TEAM_TO_CSS */ window.chat = function() {}; @@ -380,10 +380,10 @@ window.chat.parseMsgData = function (data) { nick = ent[1].plain.replace(/: $/, ''); // cut “: ” at end break; - case 'PLAYER': // automatically generated messages - nick = ent[1].plain; - team = window.teamStringToId(ent[1].team); - break; + case 'PLAYER': // automatically generated messages + nick = ent[1].plain; + team = window.teamStringToId(ent[1].team); + break; default: break; From a35907159fac52822a134ada52ced2dcbba1dd0a Mon Sep 17 00:00:00 2001 From: xscreach Date: Mon, 22 May 2023 20:34:20 +0200 Subject: [PATCH 6/8] better references --- core/code/chat.js | 21 +++--- ...ina_tracker.user.js => machina_tracker.js} | 69 ++++++++----------- plugins/player-activity-tracker.js | 6 +- 3 files changed, 42 insertions(+), 54 deletions(-) rename plugins/{machina_tracker.user.js => machina_tracker.js} (79%) diff --git a/core/code/chat.js b/core/code/chat.js index fc9b522b9..6e73cefc2 100644 --- a/core/code/chat.js +++ b/core/code/chat.js @@ -1,5 +1,3 @@ -/* global TEAM_TO_CSS */ - window.chat = function() {}; //WORK IN PROGRESS - NOT YET USED!! @@ -376,17 +374,17 @@ window.chat.parseMsgData = function (data) { var nick = ''; markup.forEach(function(ent) { switch (ent[0]) { - case 'SENDER': // user generated messages - nick = ent[1].plain.replace(/: $/, ''); // cut “: ” at end - break; + case 'SENDER': // user generated messages + nick = ent[1].plain.replace(/: $/, ''); // cut “: ” at end + break; case 'PLAYER': // automatically generated messages nick = ent[1].plain; team = window.teamStringToId(ent[1].team); break; - default: - break; + default: + break; } }); @@ -459,8 +457,9 @@ window.chat.renderPortal = function (portal) { }; window.chat.renderFactionEnt = function (faction) { - var name = faction.team === 'ENLIGHTENED' ? 'Enlightened' : 'Resistance'; - var spanClass = faction.team === 'ENLIGHTENED' ? TEAM_TO_CSS[TEAM_ENL] : TEAM_TO_CSS[TEAM_RES]; + var teamId = window.teamStringToId(faction.team); + var name = window.TEAM_NAMES[teamId]; + var spanClass = window.TEAM_TO_CSS[teamId]; return $('
').html($('') .attr('class', spanClass) .text(name)).html(); @@ -547,8 +546,8 @@ window.chat.renderMsgRow = function(data) { var timeCell = chat.renderTimeCell(data.time, timeClass); var nickClasses = ['nickname']; - if (TEAM_TO_CSS[data.player.team]) { - nickClasses.push(TEAM_TO_CSS[data.player.team]); + if (window.TEAM_TO_CSS[data.player.team]) { + nickClasses.push(window.TEAM_TO_CSS[data.player.team]); } // highlight things said/done by the player in a unique colour // (similar to @player mentions from others in the chat text itself) diff --git a/plugins/machina_tracker.user.js b/plugins/machina_tracker.js similarity index 79% rename from plugins/machina_tracker.user.js rename to plugins/machina_tracker.js index 392d1f005..6cb5c3b72 100644 --- a/plugins/machina_tracker.user.js +++ b/plugins/machina_tracker.js @@ -1,11 +1,11 @@ -// @name IITC Plugin: Machina tracker +// @name Machina tracker // @author McBen // @category Layer // @version 1.0.0 // @description Show locations of Machina activities /* exported setup --eslint */ -/* global plugin,L,addHook */ +/* global L */ // ensure plugin framework is there, even if iitc is not yet loaded if (typeof window.plugin !== 'function') window.plugin = function () {}; @@ -22,16 +22,16 @@ window.plugin.machinaTracker.setup = function () { var iconImage = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAgCAYAAAAIXrg4AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAABoZJREFUSImtlX1sVXcZxz+/837f39vevkALlBUaGLJNkBLniBrnmIt/EBNNFnTrKKImi1myxGT8oc7EZGoYhbbMLBIljsQ4kwW3xJGxBbIwgYn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icon = L.icon({ + window.plugin.machinaTracker.icon = L.icon({ iconUrl: iconImage, iconSize: [26, 32], iconAnchor: [12, 32], }); - plugin.machinaTracker.drawnTraces = new L.LayerGroup(); - window.addLayerGroup('Machina Tracker', plugin.machinaTracker.drawnTraces, true); + window.plugin.machinaTracker.drawnTraces = new L.LayerGroup(); + window.addLayerGroup('Machina Tracker', window.plugin.machinaTracker.drawnTraces, true); - addHook('publicChatDataAvailable', window.plugin.machinaTracker.handleData); + window.addHook('publicChatDataAvailable', window.plugin.machinaTracker.handleData); window.map.on('zoomend', function () { window.plugin.machinaTracker.zoomListener(); @@ -44,7 +44,7 @@ window.plugin.machinaTracker.stored = {}; window.plugin.machinaTracker.zoomListener = function () { var ctrl = $('.leaflet-control-layers-selector + span:contains("Machina Tracker")').parent(); if (window.map.getZoom() < window.MACHINA_TRACKER_MIN_ZOOM) { - plugin.machinaTracker.drawnTraces.clearLayers(); + window.plugin.machinaTracker.drawnTraces.clearLayers(); ctrl.addClass('disabled').attr('title', 'Zoom in to show those.'); // note: zoomListener is also called at init time to set up things, so we only need to do this in here window.chat.backgroundChannelData('plugin.machinaTracker', 'all', false); // disable this plugin's interest in 'all' COMM @@ -60,16 +60,16 @@ window.plugin.machinaTracker.getLimit = function () { }; window.plugin.machinaTracker.discardOldData = function () { - var limit = plugin.machinaTracker.getLimit(); - $.each(plugin.machinaTracker.stored, function (plrname, player) { + var limit = window.plugin.machinaTracker.getLimit(); + $.each(window.plugin.machinaTracker.stored, function (plrname, player) { var i; var ev = player.events; for (i = 0; i < ev.length; i++) { if (ev[i].time >= limit) break; } if (i === 0) return true; - if (i === ev.length) return delete plugin.machinaTracker.stored[plrname]; - plugin.machinaTracker.stored[plrname].events.splice(0, i); + if (i === ev.length) return delete window.plugin.machinaTracker.stored[plrname]; + window.plugin.machinaTracker.stored[plrname].events.splice(0, i); }); }; @@ -85,7 +85,7 @@ window.plugin.machinaTracker.eventHasLatLng = function (ev, lat, lng) { }; window.plugin.machinaTracker.processNewData = function (data) { - var limit = plugin.machinaTracker.getLimit(); + var limit = window.plugin.machinaTracker.getLimit(); $.each(data.result, function (ind, json) { // skip old data if (json[1] < limit) return true; @@ -100,19 +100,6 @@ window.plugin.machinaTracker.processNewData = function (data) { var skipThisMessage = false; $.each(json[2].plext.markup, function (ind, markup) { switch (markup[0]) { - case 'TEXT': - // Destroy link and field messages depend on where the link or - // field was originally created. Therefore it’s not clear which - // portal the player is at, so ignore it. - if ( - markup[1].plain.indexOf('destroyed the Link') !== -1 || - markup[1].plain.indexOf('destroyed a Control Field') !== -1 || - markup[1].plain.indexOf('Your Link') !== -1 - ) { - skipThisMessage = true; - return false; - } - break; case 'PLAYER': plrname = markup[1].plain; break; @@ -132,7 +119,7 @@ window.plugin.machinaTracker.processNewData = function (data) { }); // skip unusable events - if (!plrname || !lat || !lng || !id || skipThisMessage || json[2].plext.team !== 'NEUTRAL') return true; + if (!plrname || !lat || !lng || !id || skipThisMessage || window.teamStringToId(json[2].plext.team) !== window.TEAM_NONE) return true; var newEvent = { latlngs: [[lat, lng]], @@ -146,7 +133,7 @@ window.plugin.machinaTracker.processNewData = function (data) { // short-path if this is a new player if (!playerData || playerData.events.length === 0) { - plugin.machinaTracker.stored[plrname] = { + window.plugin.machinaTracker.stored[plrname] = { nick: plrname, team: json[2].plext.team, events: [newEvent], @@ -168,7 +155,7 @@ window.plugin.machinaTracker.processNewData = function (data) { if (evts[cmp].time === json[1]) { evts[cmp].latlngs.push([lat, lng]); evts[cmp].ids.push(id); - plugin.machinaTracker.stored[plrname].events = evts; + window.plugin.machinaTracker.stored[plrname].events = evts; return true; } @@ -178,10 +165,10 @@ window.plugin.machinaTracker.processNewData = function (data) { // to look at the next item in the event list. If this event is the // newest one, there may not be a newer event so check for that. If // it really is an older event at the same location, then skip it. - if (evts[cmp + 1] && plugin.machinaTracker.eventHasLatLng(evts[cmp + 1], lat, lng)) return true; + if (evts[cmp + 1] && window.plugin.machinaTracker.eventHasLatLng(evts[cmp + 1], lat, lng)) return true; // if this event is newer, need to look at the previous one - var sameLocation = plugin.machinaTracker.eventHasLatLng(evts[cmp], lat, lng); + var sameLocation = window.plugin.machinaTracker.eventHasLatLng(evts[cmp], lat, lng); // if it’s the same location, just update the timestamp. Otherwise // push as new event. @@ -192,7 +179,7 @@ window.plugin.machinaTracker.processNewData = function (data) { } // update player data - plugin.machinaTracker.stored[plrname].events = evts; + window.plugin.machinaTracker.stored[plrname].events = evts; }); }; @@ -221,12 +208,12 @@ window.plugin.machinaTracker.ago = function (time, now) { window.plugin.machinaTracker.drawData = function () { var isTouchDev = window.isTouchDevice(); - var gllfe = plugin.machinaTracker.getLatLngFromEvent; + var gllfe = window.plugin.machinaTracker.getLatLngFromEvent; var split = window.MACHINA_TRACKER_MAX_TIME / 4; var now = new Date().getTime(); - $.each(plugin.machinaTracker.stored, function (plrname, playerData) { + $.each(window.plugin.machinaTracker.stored, function (plrname, playerData) { if (!playerData || playerData.events.length === 0) { console.error('broken player data for plrname=' + plrname); return true; @@ -237,15 +224,15 @@ window.plugin.machinaTracker.drawData = function () { var ageBucket = Math.min(parseInt((now - p.time) / split), 4 - 1); var position = gllfe(p); - var title = isTouchDev ? '' : plugin.machinaTracker.ago(p.time, now) + ' ago'; - var icon = plugin.machinaTracker.icon; + var title = isTouchDev ? '' : window.plugin.machinaTracker.ago(p.time, now) + ' ago'; + var icon = window.plugin.machinaTracker.icon; var opacity = 1 - 0.2 * ageBucket; var m = L.marker(position, { icon, opacity, title }); // m.on('mouseout', function() { $(this._icon).tooltip('close'); }); window.registerMarkerForOMS(m); - m.addTo(plugin.machinaTracker.drawnTraces); + m.addTo(window.plugin.machinaTracker.drawnTraces); } }); }; @@ -253,11 +240,11 @@ window.plugin.machinaTracker.drawData = function () { window.plugin.machinaTracker.handleData = function (data) { if (window.map.getZoom() < window.MACHINA_TRACKER_MIN_ZOOM) return; - plugin.machinaTracker.discardOldData(); - plugin.machinaTracker.processNewData(data); + window.plugin.machinaTracker.discardOldData(); + window.plugin.machinaTracker.processNewData(data); - plugin.machinaTracker.drawnTraces.clearLayers(); - plugin.machinaTracker.drawData(); + window.plugin.machinaTracker.drawnTraces.clearLayers(); + window.plugin.machinaTracker.drawData(); }; -var setup = plugin.machinaTracker.setup; +var setup = window.plugin.machinaTracker.setup; diff --git a/plugins/player-activity-tracker.js b/plugins/player-activity-tracker.js index 912885128..dc74c1641 100644 --- a/plugins/player-activity-tracker.js +++ b/plugins/player-activity-tracker.js @@ -57,7 +57,7 @@ window.plugin.playerTracker.setup = function() { window.plugin.playerTracker.zoomListener(); }); window.plugin.playerTracker.zoomListener(); - + plugin.playerTracker.setupUserSearch(); } @@ -169,7 +169,9 @@ window.plugin.playerTracker.processNewData = function(data) { }); // skip unusable events - if (!plrname || !lat || !lng || !id || skipThisMessage || json[2].plext.team === 'NEUTRAL') return true; + if (!plrname || !lat || !lng || !id || skipThisMessage || ![window.TEAM_RES, window.TEAM_ENL].includes(window.teamStringToId(json[2].plext.team))) { + return true; + } var newEvent = { latlngs: [[lat, lng]], From 42a6806111534c212fe7beeaa782db8ccdccfab0 Mon Sep 17 00:00:00 2001 From: xscreach Date: Thu, 25 May 2023 23:16:51 +0200 Subject: [PATCH 7/8] simpler single entity tracking --- plugins/images/marker-machina.png | Bin 0 -> 1785 bytes ...{machina_tracker.js => machina-tracker.js} | 75 +++++++----------- 2 files changed, 29 insertions(+), 46 deletions(-) create mode 100644 plugins/images/marker-machina.png rename plugins/{machina_tracker.js => machina-tracker.js} (60%) diff --git a/plugins/images/marker-machina.png b/plugins/images/marker-machina.png new file mode 100644 index 0000000000000000000000000000000000000000..27d80ffa24150f3fe61888b42ac2d76f79039f93 GIT binary patch literal 1785 zcmVpF8FWQhbW?9;ba!ELWdL_~cP?peYja~^aAhuUa%Y?FJQ@H128KyQ zK~zYIt(ARjRd*T3Kfm*S-{0HbzCa6<6&e__O^_1jh#KdZi+>OkO%`VsEd~f7_VoAv zJXbDnKXKzm(zI<eNx+16BPG_@AvTv{OxhK~rofK6E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|Ad#8ib#dKocWMZZ1`R*;;q zxDqH+P#rR=4@;G~;IH#YS6jxAq!(Ba(#^@EM~;|UK>yjwRHA&*U*k~o1fx-lfGv@( zt7LT(zpM}t3YYzLejm+nDo`dG@Oge+dFPqo;g1&rl!b*vKL5(9Wb(P!^ZB6TdMK`7 z(r`HMnVb%lY4!|qlEt*%V8SpFp5U=1E3zS<@41Cui#h<!e+K|| z3=RFMD;m9KD2uiU00BIhPG^%o-|pLa+z|i}(6k?{Z*IQj>N+Elh9*e|zqM!2-2V*d z-?#5rdpLYGpsMrg0$AVDk~L)c#XITm3IOm+(#{9c>DlrWj*g*w(cLouAgn0gdvwK$nyRWl*}Z$W{iy@C4-JiJvizfbI{lk_ b)d2hx+GwBzRRPz=00000NkvXXu0mjfa)WO> literal 0 HcmV?d00001 diff --git a/plugins/machina_tracker.js b/plugins/machina-tracker.js similarity index 60% rename from plugins/machina_tracker.js rename to plugins/machina-tracker.js index 6cb5c3b72..de14f896d 100644 --- a/plugins/machina_tracker.js +++ b/plugins/machina-tracker.js @@ -19,8 +19,7 @@ window.MACHINA_TRACKER_MIN_OPACITY = 0.3; window.plugin.machinaTracker = function () {}; window.plugin.machinaTracker.setup = function () { - var iconImage = - 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAgCAYAAAAIXrg4AAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAABoZJREFUSImtlX1sVXcZxz+/837f39vevkALlBUaGLJNkBLniBrnmIt/EBNNFnTrKKImi1myxGT8oc7EZGoYhbbMLBIljsQ4kwW3xJGxBbIwgYnAGiovHXBv29vb3tv7es49L/7hjLTlTd2TnOQ8T/L9fn7P+f2e8xOe53GneHVgYHXZdZ+0HecBICWgJGAsoGm/jeTzx7YdPuzcSS9uBxgeGPhczbb3T1Qq6bF8vmm2Xsd0HFRJIqxpdEajha5otKApyk93jYz8mtsYLQYIIfb09/88Vy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+Nr1hlXT3EB00m51urlukXw7ec5Kf27z+T9gem1tVD9FkJ1joxChev4hiClV/oY+NXv0I8HCHR3kF7Xx9OwMfM6BVSFVhuG7RZGr2p1GSrrh+45SQD6EL6pZYM7HtNm9S7qgabSgmOnj6GnrtAb6qTpOcwlbvBhTdOMTM1yeeJclavcTKaw4lo6IpydNuCP+o8wNLM9d+NLWt54eilj5dussPEVIVLehkxW0W/Pg1WkJywuBIoU1AdMqoPS5W54K/zSFdbxpCkF1gQ0s3Jo0eOmFpA/9nKVKJ80V/jUPMEo1GLgC2RrqtkdRO/rBAQCpf9dX4fzXAqUCYa8Hl+XXnnmeHhjxcClIWFRD7/yqpk8rnX8/mg43oormDScDjvmZwOlWn2DHKSxbTeYMIwEZ7gsSUrsiGf77mFXos6ANh2+LBjSNLu1alU0cWjIbmMBmu8FS8wZtQ54SswalSwhIsLpEIBV1eUI995+eXMPQEABg4cONQdi2U1WcYDKpLDlGphSi41ycUS/7kFN7S23ogbxvO38rktAM/z/Kr6/NqmplkA75NnYXSEw7auKH94cu/e/H8HAHYMDf2pKxq9ZiiLtgkAATyYTmeTPt/u23ncEQAQ0LQfrG9uvuXqOiORhiZJB7+1Z8/c/wzo37fvWHs4fDWgqvPqAljf0pI1ZPnFO+nvCgDwS9LOB9Lp3M217ni8rkjS0DPDw9X/G9A/MvJBSyBwMaRp/xIIwZpUakL4/b+4m/aeAABBVR34bFvbBMB98XhVlaSXvr9nj/mpAZ7av/9c0jDOJnw+elOpiZmOjqF70d0zACCsKN97dMWKmqqqP9m9e7f9qQO2Dw2NabL8o3w6/Zt71QD8E9pooARVAdfGAAAAAElFTkSuQmCC'; + var iconImage = '@include_img:images/marker-machina.png@'; window.plugin.machinaTracker.icon = L.icon({ iconUrl: iconImage, @@ -39,7 +38,7 @@ window.plugin.machinaTracker.setup = function () { window.plugin.machinaTracker.zoomListener(); }; -window.plugin.machinaTracker.stored = {}; +window.plugin.machinaTracker.events = []; window.plugin.machinaTracker.zoomListener = function () { var ctrl = $('.leaflet-control-layers-selector + span:contains("Machina Tracker")').parent(); @@ -61,16 +60,16 @@ window.plugin.machinaTracker.getLimit = function () { window.plugin.machinaTracker.discardOldData = function () { var limit = window.plugin.machinaTracker.getLimit(); - $.each(window.plugin.machinaTracker.stored, function (plrname, player) { - var i; - var ev = player.events; - for (i = 0; i < ev.length; i++) { - if (ev[i].time >= limit) break; - } - if (i === 0) return true; - if (i === ev.length) return delete window.plugin.machinaTracker.stored[plrname]; - window.plugin.machinaTracker.stored[plrname].events.splice(0, i); - }); + var i; + var ev = window.plugin.machinaTracker.events; + for (i = 0; i < ev.length; i++) { + if (ev[i].time >= limit) break; + } + if (i === ev.length) { + window.plugin.machinaTracker.events = []; + } else if (i > 0) { + window.plugin.machinaTracker.events.splice(0, i); + } }; window.plugin.machinaTracker.eventHasLatLng = function (ev, lat, lng) { @@ -129,19 +128,13 @@ window.plugin.machinaTracker.processNewData = function (data) { address: address, }; - var playerData = window.plugin.machinaTracker.stored[plrname]; - // short-path if this is a new player - if (!playerData || playerData.events.length === 0) { - window.plugin.machinaTracker.stored[plrname] = { - nick: plrname, - team: json[2].plext.team, - events: [newEvent], - }; + if (window.plugin.machinaTracker.events.length === 0) { + window.plugin.machinaTracker.events = [newEvent]; return true; } - var evts = playerData.events; + var evts = window.plugin.machinaTracker.events; // there’s some data already. Need to find correct place to insert. var i; for (i = 0; i < evts.length; i++) { @@ -155,7 +148,7 @@ window.plugin.machinaTracker.processNewData = function (data) { if (evts[cmp].time === json[1]) { evts[cmp].latlngs.push([lat, lng]); evts[cmp].ids.push(id); - window.plugin.machinaTracker.stored[plrname].events = evts; + window.plugin.machinaTracker.events = evts; return true; } @@ -179,7 +172,7 @@ window.plugin.machinaTracker.processNewData = function (data) { } // update player data - window.plugin.machinaTracker.stored[plrname].events = evts; + window.plugin.machinaTracker.events = evts; }); }; @@ -206,35 +199,25 @@ window.plugin.machinaTracker.ago = function (time, now) { }; window.plugin.machinaTracker.drawData = function () { - var isTouchDev = window.isTouchDevice(); - var gllfe = window.plugin.machinaTracker.getLatLngFromEvent; - var split = window.MACHINA_TRACKER_MAX_TIME / 4; var now = new Date().getTime(); - $.each(window.plugin.machinaTracker.stored, function (plrname, playerData) { - if (!playerData || playerData.events.length === 0) { - console.error('broken player data for plrname=' + plrname); - return true; - } - - for (var i = 0; i < playerData.events.length; i++) { - var p = playerData.events[i]; - var ageBucket = Math.min(parseInt((now - p.time) / split), 4 - 1); - var position = gllfe(p); + for (var i = 0; i < window.plugin.machinaTracker.events.length; i++) { + var p = window.plugin.machinaTracker.events[i]; + var ageBucket = Math.min(parseInt((now - p.time) / split), 4 - 1); + var position = gllfe(p); - var title = isTouchDev ? '' : window.plugin.machinaTracker.ago(p.time, now) + ' ago'; - var icon = window.plugin.machinaTracker.icon; - var opacity = 1 - 0.2 * ageBucket; + var title = window.plugin.machinaTracker.ago(p.time, now) + ' ago'; + var icon = window.plugin.machinaTracker.icon; + var opacity = 1 - 0.2 * ageBucket; - var m = L.marker(position, { icon, opacity, title }); - // m.on('mouseout', function() { $(this._icon).tooltip('close'); }); - window.registerMarkerForOMS(m); + var m = L.marker(position, { icon, opacity, title }); + // m.on('mouseout', function() { $(this._icon).tooltip('close'); }); + window.registerMarkerForOMS(m); - m.addTo(window.plugin.machinaTracker.drawnTraces); - } - }); + m.addTo(window.plugin.machinaTracker.drawnTraces); + } }; window.plugin.machinaTracker.handleData = function (data) { From 3f83eadc697c40359d904f99dbcfa89122b313f5 Mon Sep 17 00:00:00 2001 From: xscreach Date: Fri, 26 May 2023 03:59:11 +0200 Subject: [PATCH 8/8] machina tracker with nice popup --- plugins/machina-tracker.css | 33 ++++ plugins/machina-tracker.js | 301 +++++++++++++++++------------------- 2 files changed, 173 insertions(+), 161 deletions(-) create mode 100644 plugins/machina-tracker.css diff --git a/plugins/machina-tracker.css b/plugins/machina-tracker.css new file mode 100644 index 000000000..25f1e8b4b --- /dev/null +++ b/plugins/machina-tracker.css @@ -0,0 +1,33 @@ +.plugin-machina-tracker-popup a { + color: inherit; + text-decoration: underline; + text-decoration-style: dashed; + -moz-text-decoration-style: dashed; + -webkit-text-decoration-style: dashed; +} + +.plugin-machina-tracker-popup-header { + white-space: nowrap; +} + +ul.plugin-machina-tracker-link-list { + list-style: none; + padding-left: 1em; +} + +ul.plugin-machina-tracker-link-list li { + position: relative; + display: flex; + justify-content: space-between; + white-space: nowrap; +} + +ul.plugin-machina-tracker-link-list li a { + margin-right: 3px; +} + +ul.plugin-machina-tracker-link-list li::before { + content: '↴'; + position: absolute; + left: -1em; +} diff --git a/plugins/machina-tracker.js b/plugins/machina-tracker.js index de14f896d..7ba51ac4f 100644 --- a/plugins/machina-tracker.js +++ b/plugins/machina-tracker.js @@ -11,39 +11,50 @@ if (typeof window.plugin !== 'function') window.plugin = function () {}; // PLUGIN START //////////////////////////////////////////////////////// -window.MACHINA_TRACKER_MAX_TIME = 8 * 60 * 60 * 1000; -window.MACHINA_TRACKER_MIN_ZOOM = 9; -window.MACHINA_TRACKER_MIN_OPACITY = 0.3; - // use own namespace for plugin window.plugin.machinaTracker = function () {}; +var machinaTracker = window.plugin.machinaTracker; + +machinaTracker.MACHINA_TRACKER_MAX_TIME = 8 * 60 * 60 * 1000; +machinaTracker.MACHINA_TRACKER_MIN_ZOOM = 9; + +machinaTracker.events = []; + +machinaTracker.setup = () => { + $('