From aef532bdb8c84d9989a2120acb673a1d65b23474 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sat, 6 Feb 2021 16:59:49 +0100 Subject: [PATCH 01/38] update portal marker instead of delete/create --- core/code/map_data_render.js | 80 +++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 34 deletions(-) diff --git a/core/code/map_data_render.js b/core/code/map_data_render.js index 62a5f79ba..8cc5d54c7 100644 --- a/core/code/map_data_render.js +++ b/core/code/map_data_render.js @@ -364,7 +364,9 @@ window.Render.prototype.createPortalEntity = function (ent, details) { var data = window.decodeArray.portal(ent[2], details); // check if entity already exists - if (ent[0] in window.portals) { + const oldPortal = ent[0] in window.portals; + + if (oldPortal) { // yes. now check to see if the entity data we have is newer than that in place var p = window.portals[ent[0]]; @@ -375,18 +377,14 @@ window.Render.prototype.createPortalEntity = function (ent, details) { // the data we have is newer. many data changes require re-rendering of the portal // (e.g. level changed, so size is different, or stats changed so highlighter is different) - // so to keep things simple we'll always re-create the entity in this case // remember the old details, for the callback - previousData = p.options.data; // preserve history if (!data.history) { data.history = previousData.history; } - - this.deletePortalEntity(ent[0]); } var portalLevel = parseInt(data.level) || 0; @@ -407,47 +405,61 @@ window.Render.prototype.createPortalEntity = function (ent, details) { window.pushPortalGuidPositionCache(ent[0], data.latE6, data.lngE6); - var marker = window.createMarker(latlng, dataOptions); - - function handler_portal_click(e) { - window.renderPortalDetails(e.target.options.guid); - } - function handler_portal_dblclick(e) { - window.renderPortalDetails(e.target.options.guid); - window.map.setView(e.target.getLatLng(), window.DEFAULT_ZOOM); - } - function handler_portal_contextmenu(e) { - window.renderPortalDetails(e.target.options.guid); - if (window.isSmartphone()) { - window.show('info'); - } else if (!$('#scrollwrapper').is(':visible')) { - $('#sidebartoggle').click(); - } - } - - marker.on('click', handler_portal_click); - marker.on('dblclick', handler_portal_dblclick); - marker.on('contextmenu', handler_portal_contextmenu); - - window.runHooks('portalAdded', { portal: marker, previousData: previousData }); - - window.portals[ent[0]] = marker; - // check for URL links to portal, and select it if this is the one - if (window.urlPortalLL && window.urlPortalLL[0] === marker.getLatLng().lat && window.urlPortalLL[1] === marker.getLatLng().lng) { + if (window.urlPortalLL && window.urlPortalLL[0] === latlng.lat && window.urlPortalLL[1] === latlng.lng) { // URL-passed portal found via pll parameter - set the guid-based parameter - log.log('urlPortalLL ' + window.urlPortalLL[0] + ',' + window.urlPortalLL[1] + ' matches portal GUID ' + ent[0]); + log.log('urlPortalLL ' + window.urlPortalLL[0] + ',' + urlPortalLL[1] + ' matches portal GUID ' + ent[0]); window.urlPortal = ent[0]; window.urlPortalLL = undefined; // clear the URL parameter so it's not matched again } if (window.urlPortal === ent[0]) { // URL-passed portal found via guid parameter - set it as the selected portal - log.log('urlPortal GUID ' + window.urlPortal + ' found - selecting...'); + log.log('urlPortal GUID ' + urlPortal + ' found - selecting...'); window.selectedPortal = ent[0]; window.urlPortal = undefined; // clear the URL parameter so it's not matched again } + let marker = undefined; + if (oldPortal) { + // update marker style/highlight and layer + marker = window.portals[ent[0]]; + // remove portal from its faction/level specific layer + this.removePortalFromMapLayer(marker); + + $.extend(marker.options, dataOptions); + + setMarkerStyle(marker, ent[0] === selectedPortal); + + window.runHooks('portalAdded', {portal: marker, previousData: previousData}); + } else { + marker = createMarker(latlng, dataOptions); + + function handler_portal_click(e) { + window.renderPortalDetails(e.target.options.guid); + } + function handler_portal_dblclick(e) { + window.renderPortalDetails(e.target.options.guid); + window.map.setView(e.target.getLatLng(), window.DEFAULT_ZOOM); + } + function handler_portal_contextmenu(e) { + window.renderPortalDetails(e.target.options.guid); + if (window.isSmartphone()) { + window.show('info'); + } else if (!$('#scrollwrapper').is(':visible')) { + $('#sidebartoggle').click(); + } + } + + marker.on('click', handler_portal_click); + marker.on('dblclick', handler_portal_dblclick); + marker.on('contextmenu', handler_portal_contextmenu); + + window.runHooks('portalAdded', { portal: marker }); + + window.portals[ent[0]] = marker; + } + // (re-)select the portal, to refresh the sidebar on any changes if (ent[0] === window.selectedPortal) { log.log('portal guid ' + ent[0] + ' is the selected portal - re-rendering portal details'); From 71003a0a8ba435080010650239d4479296cc6e0b Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sat, 6 Feb 2021 23:49:15 +0100 Subject: [PATCH 02/38] add PortalMarker class --- core/code/portal_marker.js | 60 +++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index 0ad3f5192..5b431418d 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -5,6 +5,36 @@ * @module portal_marker */ +L.PortalMarker = L.CircleMarker.extend({ + options: {}, + + initialize: function(latlng, data) { + var styleOptions = window.getMarkerStyleOptions(data); + var options = L.extend({}, data, styleOptions, { interactive: true }); + + L.CircleMarker.prototype.initialize.call(this, latlng, options); + + highlightPortal(this) + }, + updateData: function(data) { + var styleOptions = window.getMarkerStyleOptions(data); + var options = L.extend({}, data, styleOptions, { interactive: true }); + L.setOptions(this, options); + + this.setStyle(styleOptions); + }, + select: function (selected) { + var styleOptions = window.getMarkerStyleOptions(this.options); + this.setStyle(styleOptions); + + highlightPortal(this); + + if (selected) { + this.setStyle ({color: COLOR_SELECTED_PORTAL}); + } + }, +}); + /** * Calculates the scale of portal markers based on the current zoom level of the map. * @@ -25,17 +55,9 @@ window.portalMarkerScale = function () { * @param {Object} data - The IITC-specific entity data to be stored in the marker options. * @returns {L.circleMarker} A Leaflet circle marker representing the portal. */ -window.createMarker = function (latlng, data) { - var styleOptions = window.getMarkerStyleOptions(data); - - var options = L.extend({}, data, styleOptions, { interactive: true }); - - var marker = L.circleMarker(latlng, options); - - window.highlightPortal(marker); - - return marker; -}; +window.createMarker = function(latlng, data) { + return new L.PortalMarker(latlng, data); +} /** * Sets the style of a portal marker, including options for when the portal is selected. @@ -44,19 +66,9 @@ window.createMarker = function (latlng, data) { * @param {L.circleMarker} marker - The portal marker whose style will be set. * @param {boolean} selected - Indicates if the portal is selected. */ -window.setMarkerStyle = function (marker, selected) { - var styleOptions = window.getMarkerStyleOptions(marker.options); - - marker.setStyle(styleOptions); - - // FIXME? it's inefficient to set the marker style (above), then do it again inside the highlighter - // the highlighter API would need to be changed for this to be improved though. will it be too slow? - window.highlightPortal(marker); - - if (selected) { - marker.setStyle({ color: window.COLOR_SELECTED_PORTAL }); - } -}; +window.setMarkerStyle = function(marker, selected) { + marker.select(selected); +} /** * Determines the style options for a portal marker based on its details. From c615f660cd56164ec54adcab3ca1d1ad463d3ef2 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sun, 7 Feb 2021 00:58:01 +0100 Subject: [PATCH 03/38] small factor --- core/code/portal_marker.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index 5b431418d..2e65d3525 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -14,7 +14,7 @@ L.PortalMarker = L.CircleMarker.extend({ L.CircleMarker.prototype.initialize.call(this, latlng, options); - highlightPortal(this) + highlightPortal(this); }, updateData: function(data) { var styleOptions = window.getMarkerStyleOptions(data); @@ -22,8 +22,9 @@ L.PortalMarker = L.CircleMarker.extend({ L.setOptions(this, options); this.setStyle(styleOptions); + thighlightPortal(this); }, - select: function (selected) { + reset: function (selected) { var styleOptions = window.getMarkerStyleOptions(this.options); this.setStyle(styleOptions); @@ -67,7 +68,7 @@ window.createMarker = function(latlng, data) { * @param {boolean} selected - Indicates if the portal is selected. */ window.setMarkerStyle = function(marker, selected) { - marker.select(selected); + marker.reset(selected); } /** From 5e930a2154a4a2d9c1c382eda017ea611418ecd2 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sun, 7 Feb 2021 01:31:00 +0100 Subject: [PATCH 04/38] handle style inside portal class --- core/code/map_data_render.js | 4 +-- core/code/portal_marker.js | 68 +++++++++++++++++++++++++++++------- 2 files changed, 57 insertions(+), 15 deletions(-) diff --git a/core/code/map_data_render.js b/core/code/map_data_render.js index 8cc5d54c7..87d5353bb 100644 --- a/core/code/map_data_render.js +++ b/core/code/map_data_render.js @@ -427,9 +427,7 @@ window.Render.prototype.createPortalEntity = function (ent, details) { // remove portal from its faction/level specific layer this.removePortalFromMapLayer(marker); - $.extend(marker.options, dataOptions); - - setMarkerStyle(marker, ent[0] === selectedPortal); + marker.updateData(dataOptions, ent[0] === selectedPortal); window.runHooks('portalAdded', {portal: marker, previousData: previousData}); } else { diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index 2e65d3525..e2a8675ff 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -5,27 +5,38 @@ * @module portal_marker */ +var portalBaseStyle = { + stroke: true, + opacity: 1, + fill: true, + fillOpacity: 0.5, + interactive: true, +}; + L.PortalMarker = L.CircleMarker.extend({ - options: {}, + options: { + guid: null, + level: 0, + team: 0, + timestamp: 0, + data: null, + ent: null, // LEGACY - TO BE REMOVED AT SOME POINT! use .guid, .timestamp and .data instead + }, initialize: function(latlng, data) { - var styleOptions = window.getMarkerStyleOptions(data); - var options = L.extend({}, data, styleOptions, { interactive: true }); - - L.CircleMarker.prototype.initialize.call(this, latlng, options); + L.CircleMarker.prototype.initialize.call(this, latlng, data); + var styleOptions = this._style(); + this.setStyle(styleOptions); highlightPortal(this); }, - updateData: function(data) { - var styleOptions = window.getMarkerStyleOptions(data); - var options = L.extend({}, data, styleOptions, { interactive: true }); - L.setOptions(this, options); + updateData: function(data, selected) { + L.setOptions(this, data); - this.setStyle(styleOptions); - thighlightPortal(this); + this.reset(selected); }, reset: function (selected) { - var styleOptions = window.getMarkerStyleOptions(this.options); + var styleOptions = this._style(); this.setStyle(styleOptions); highlightPortal(this); @@ -34,6 +45,39 @@ L.PortalMarker = L.CircleMarker.extend({ this.setStyle ({color: COLOR_SELECTED_PORTAL}); } }, + _style: function () { + var dashArray = null; + // dashed outline for placeholder portals + if (this.options.team != TEAM_NONE && this.options.level==0) dashArray = '1,2'; + + return L.extend(this._scale(), portalBaseStyle, { + color: COLORS[this.options.team], + fillColor: COLORS[this.options.team], + dashArray: dashArray + }); + }, + _scale: function () { + var scale = window.portalMarkerScale(); + + // portal level 0 1 2 3 4 5 6 7 8 + var LEVEL_TO_WEIGHT = [2, 2, 2, 2, 2, 3, 3, 4, 4]; + var LEVEL_TO_RADIUS = [7, 7, 7, 7, 8, 8, 9,10,11]; + + var level = Math.floor(this.options.level||0); + + var lvlWeight = LEVEL_TO_WEIGHT[level] * Math.sqrt(scale); + var lvlRadius = LEVEL_TO_RADIUS[level] * scale; + + // thinner outline for placeholder portals + if (this.options.team != TEAM_NONE && level==0) { + lvlWeight = 1; + } + + return { + radius: lvlRadius, + weight: lvlWeight, + }; + }, }); /** From 4b57fa082c5253679135718e12889c14907c314a Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Wed, 10 Feb 2021 14:24:27 +0100 Subject: [PATCH 05/38] test if portal has details --- core/code/portal_marker.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index e2a8675ff..f9b101684 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -35,6 +35,9 @@ L.PortalMarker = L.CircleMarker.extend({ this.reset(selected); }, + hasDetails: function () { + return !!this.options.data.mods + }, reset: function (selected) { var styleOptions = this._style(); this.setStyle(styleOptions); From eb46b7a2f8dfe29c5666e09743b1f9234b4b39d4 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Wed, 10 Feb 2021 14:25:11 +0100 Subject: [PATCH 06/38] use portal entity marker to get details --- core/code/map_data_render.js | 12 +++++++++--- core/code/map_data_request.js | 8 -------- core/code/portal_detail.js | 11 +++++------ 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/core/code/map_data_render.js b/core/code/map_data_render.js index 87d5353bb..b3ab67adc 100644 --- a/core/code/map_data_render.js +++ b/core/code/map_data_render.js @@ -370,11 +370,15 @@ window.Render.prototype.createPortalEntity = function (ent, details) { // yes. now check to see if the entity data we have is newer than that in place var p = window.portals[ent[0]]; - if (!data.history || p.options.data.history === data.history) - if (p.options.timestamp >= ent[1]) { - return; // this data is identical or older - abort processing + if (!data.history || p.options.data.history === data.history) { + if (p.options.timestamp > ent[1]) { + return p; // this data is older - abort processing } + if (p.options.timestamp == ent[1] && p.hasDetails()) // this data is identical - abort processing + return p; + } + // the data we have is newer. many data changes require re-rendering of the portal // (e.g. level changed, so size is different, or stats changed so highlighter is different) @@ -468,6 +472,8 @@ window.Render.prototype.createPortalEntity = function (ent, details) { // TODO? postpone adding to the map layer this.addPortalToMapLayer(marker); + + return marker; }; /** diff --git a/core/code/map_data_request.js b/core/code/map_data_request.js index 1402c4235..91a1073c1 100644 --- a/core/code/map_data_request.js +++ b/core/code/map_data_request.js @@ -65,14 +65,6 @@ window.MapDataRequest = function () { // ensure we have some initial map status this.setStatus('startup', undefined, -1); - - // add a portalDetailLoaded hook, so we can use the extended details to update portals on the map - var _this = this; - window.addHook('portalDetailLoaded', function (data) { - if (data.success) { - _this.render.createPortalEntity(data.ent, 'detailed'); - } - }); }; /** diff --git a/core/code/portal_detail.js b/core/code/portal_detail.js index 39f25db6e..2730ea514 100644 --- a/core/code/portal_detail.js +++ b/core/code/portal_detail.js @@ -60,12 +60,11 @@ var handleResponse = function (deferred, guid, data, success) { } if (success) { - var dict = window.decodeArray.portal(data.result, 'detailed'); - // entity format, as used in map data - var ent = [guid, dict.timestamp, data.result]; + var ent = [guid, data.result[13], data.result]; + var portal = window.mapDataRequest.render.createPortalEntity(ent, 'detailed'); - cache.store(guid, dict); + cache.store(guid, portal.options.data); // FIXME..? better way of handling sidebar refreshing... @@ -73,8 +72,8 @@ var handleResponse = function (deferred, guid, data, success) { window.renderPortalDetails(guid); } - deferred.resolve(dict); - window.runHooks('portalDetailLoaded', { guid: guid, success: success, details: dict, ent: ent }); + deferred.resolve(portal.options.data); + window.runHooks('portalDetailLoaded', { guid: guid, success: success, details: portal.options.data, ent: ent }); } else { if (data && data.error === 'RETRY') { // server asked us to try again From 5a7e40ee3c97106f1e885c16e2b4a0e785d940c9 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Wed, 10 Feb 2021 14:55:01 +0100 Subject: [PATCH 07/38] add details getter --- core/code/portal_marker.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index f9b101684..abb16e8a5 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -35,7 +35,10 @@ L.PortalMarker = L.CircleMarker.extend({ this.reset(selected); }, - hasDetails: function () { + getDetails: function () { + return this.options.data; + }, + hasFullDetails: function () { return !!this.options.data.mods }, reset: function (selected) { From 5d558e1db089a4f8d02857345f1798375d17ebbd Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Wed, 10 Feb 2021 19:04:51 +0100 Subject: [PATCH 08/38] merge data/details in a single object keep parsed level/team in seperate fields and back compability --- core/code/map_data_render.js | 51 +++++++++++++++------------------- core/code/portal_marker.js | 54 +++++++++++++++++++++--------------- 2 files changed, 54 insertions(+), 51 deletions(-) diff --git a/core/code/map_data_render.js b/core/code/map_data_render.js index b3ab67adc..cdabfac85 100644 --- a/core/code/map_data_render.js +++ b/core/code/map_data_render.js @@ -362,20 +362,21 @@ window.Render.prototype.createPortalEntity = function (ent, details) { var previousData = undefined; var data = window.decodeArray.portal(ent[2], details); + var guid = ent[0]; // check if entity already exists - const oldPortal = ent[0] in window.portals; + const oldPortal = guid in window.portals; if (oldPortal) { // yes. now check to see if the entity data we have is newer than that in place - var p = window.portals[ent[0]]; + var p = window.portals[guid]; if (!data.history || p.options.data.history === data.history) { if (p.options.timestamp > ent[1]) { return p; // this data is older - abort processing } - if (p.options.timestamp == ent[1] && p.hasDetails()) // this data is identical - abort processing + if (p.options.timestamp == ent[1] && p.hasFullDetails()) // this data is identical - abort processing return p; } @@ -383,7 +384,7 @@ window.Render.prototype.createPortalEntity = function (ent, details) { // (e.g. level changed, so size is different, or stats changed so highlighter is different) // remember the old details, for the callback - previousData = p.options.data; + previousData = p.getDetails(); // preserve history if (!data.history) { @@ -391,51 +392,45 @@ window.Render.prototype.createPortalEntity = function (ent, details) { } } - var portalLevel = parseInt(data.level) || 0; - var team = window.teamStringToId(data.team); - // the data returns unclaimed portals as level 1 - but IITC wants them treated as level 0 - if (team === window.TEAM_NONE) portalLevel = 0; + // add missing fields + data.guid = guid; + if (!data.timestamp) + data.timestamp = ent[1]; - var latlng = L.latLng(data.latE6 / 1e6, data.lngE6 / 1e6); + // LEGACY - TO BE REMOVED AT SOME POINT! use .guid, .timestamp and .data instead + data.ent = ent; - var dataOptions = { - level: portalLevel, - team: team, - ent: ent, // LEGACY - TO BE REMOVED AT SOME POINT! use .guid, .timestamp and .data instead - guid: ent[0], - timestamp: ent[1], - data: data, - }; + var latlng = L.latLng(data.latE6 / 1e6, data.lngE6 / 1e6); - window.pushPortalGuidPositionCache(ent[0], data.latE6, data.lngE6); + window.pushPortalGuidPositionCache(data.guid, data.latE6, data.lngE6); // check for URL links to portal, and select it if this is the one if (window.urlPortalLL && window.urlPortalLL[0] === latlng.lat && window.urlPortalLL[1] === latlng.lng) { // URL-passed portal found via pll parameter - set the guid-based parameter - log.log('urlPortalLL ' + window.urlPortalLL[0] + ',' + urlPortalLL[1] + ' matches portal GUID ' + ent[0]); + log.log('urlPortalLL ' + window.urlPortalLL[0] + ',' + urlPortalLL[1] + ' matches portal GUID ' + data.guid); - window.urlPortal = ent[0]; + window.urlPortal = data.guid; window.urlPortalLL = undefined; // clear the URL parameter so it's not matched again } - if (window.urlPortal === ent[0]) { + if (window.urlPortal === data.guid) { // URL-passed portal found via guid parameter - set it as the selected portal log.log('urlPortal GUID ' + urlPortal + ' found - selecting...'); - window.selectedPortal = ent[0]; + window.selectedPortal = data.guid; window.urlPortal = undefined; // clear the URL parameter so it's not matched again } let marker = undefined; if (oldPortal) { // update marker style/highlight and layer - marker = window.portals[ent[0]]; + marker = window.portals[data.guid]; // remove portal from its faction/level specific layer this.removePortalFromMapLayer(marker); - marker.updateData(dataOptions, ent[0] === selectedPortal); + marker.updateDetails(data); window.runHooks('portalAdded', {portal: marker, previousData: previousData}); } else { - marker = createMarker(latlng, dataOptions); + marker = createMarker(latlng, data); function handler_portal_click(e) { window.renderPortalDetails(e.target.options.guid); @@ -459,12 +454,12 @@ window.Render.prototype.createPortalEntity = function (ent, details) { window.runHooks('portalAdded', { portal: marker }); - window.portals[ent[0]] = marker; + window.portals[data.guid] = marker; } // (re-)select the portal, to refresh the sidebar on any changes - if (ent[0] === window.selectedPortal) { - log.log('portal guid ' + ent[0] + ' is the selected portal - re-rendering portal details'); + if (data.guid === window.selectedPortal) { + log.log('portal guid ' + data.guid + ' is the selected portal - re-rendering portal details'); window.renderPortalDetails(window.selectedPortal); } diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index abb16e8a5..c87578906 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -14,32 +14,40 @@ var portalBaseStyle = { }; L.PortalMarker = L.CircleMarker.extend({ - options: { - guid: null, - level: 0, - team: 0, - timestamp: 0, - data: null, - ent: null, // LEGACY - TO BE REMOVED AT SOME POINT! use .guid, .timestamp and .data instead - }, + options: {}, initialize: function(latlng, data) { - L.CircleMarker.prototype.initialize.call(this, latlng, data); - - var styleOptions = this._style(); - this.setStyle(styleOptions); - highlightPortal(this); + L.CircleMarker.prototype.initialize.call(this, latlng); + this.updateDetails(data); }, - updateData: function(data, selected) { - L.setOptions(this, data); + updateDetails: function(details) { + // xxx: handle permanent data + this._details = details; + + this._level = parseInt(details.level) || 0; + this._team = window.teamStringToId(details.team); + + // the data returns unclaimed portals as level 1 - but IITC wants them treated as level 0 + if (this._team === TEAM_NONE) this._level = 0; + + // compatibility + var dataOptions = { + guid: this._details.guid, + level: this._level, + team: this._team, + ent: this._details.ent, // LEGACY - TO BE REMOVED AT SOME POINT! use .guid, .timestamp and .data instead + timestamp: this._details.timestamp, + data: this._details + }; + L.setOptions(this, dataOptions); - this.reset(selected); + this.reset(); }, getDetails: function () { - return this.options.data; + return this._details; }, hasFullDetails: function () { - return !!this.options.data.mods + return !!this._details.mods }, reset: function (selected) { var styleOptions = this._style(); @@ -54,11 +62,11 @@ L.PortalMarker = L.CircleMarker.extend({ _style: function () { var dashArray = null; // dashed outline for placeholder portals - if (this.options.team != TEAM_NONE && this.options.level==0) dashArray = '1,2'; + if (this._team !== TEAM_NONE && this._level === 0) dashArray = '1,2'; return L.extend(this._scale(), portalBaseStyle, { - color: COLORS[this.options.team], - fillColor: COLORS[this.options.team], + color: COLORS[this._team], + fillColor: COLORS[this._team], dashArray: dashArray }); }, @@ -69,13 +77,13 @@ L.PortalMarker = L.CircleMarker.extend({ var LEVEL_TO_WEIGHT = [2, 2, 2, 2, 2, 3, 3, 4, 4]; var LEVEL_TO_RADIUS = [7, 7, 7, 7, 8, 8, 9,10,11]; - var level = Math.floor(this.options.level||0); + var level = Math.floor(this._level || 0); var lvlWeight = LEVEL_TO_WEIGHT[level] * Math.sqrt(scale); var lvlRadius = LEVEL_TO_RADIUS[level] * scale; // thinner outline for placeholder portals - if (this.options.team != TEAM_NONE && level==0) { + if (this._team !== TEAM_NONE && level === 0) { lvlWeight = 1; } From 49309512dd0d61721a873840790f30a10e954611 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Wed, 10 Feb 2021 19:11:30 +0100 Subject: [PATCH 09/38] move portal marker hook --- core/code/map_data_render.js | 20 -------------------- core/code/portal_marker.js | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/core/code/map_data_render.js b/core/code/map_data_render.js index cdabfac85..835229068 100644 --- a/core/code/map_data_render.js +++ b/core/code/map_data_render.js @@ -432,26 +432,6 @@ window.Render.prototype.createPortalEntity = function (ent, details) { } else { marker = createMarker(latlng, data); - function handler_portal_click(e) { - window.renderPortalDetails(e.target.options.guid); - } - function handler_portal_dblclick(e) { - window.renderPortalDetails(e.target.options.guid); - window.map.setView(e.target.getLatLng(), window.DEFAULT_ZOOM); - } - function handler_portal_contextmenu(e) { - window.renderPortalDetails(e.target.options.guid); - if (window.isSmartphone()) { - window.show('info'); - } else if (!$('#scrollwrapper').is(':visible')) { - $('#sidebartoggle').click(); - } - } - - marker.on('click', handler_portal_click); - marker.on('dblclick', handler_portal_dblclick); - marker.on('contextmenu', handler_portal_contextmenu); - window.runHooks('portalAdded', { portal: marker }); window.portals[data.guid] = marker; diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index c87578906..fa951b627 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -13,12 +13,33 @@ var portalBaseStyle = { interactive: true, }; +// portal hooks +function handler_portal_click (e) { + window.renderPortalDetails(e.target.options.guid); +} +function handler_portal_dblclick (e) { + window.renderPortalDetails(e.target.options.guid); + window.map.setView(e.target.getLatLng(), DEFAULT_ZOOM); +} +function handler_portal_contextmenu (e) { + window.renderPortalDetails(e.target.options.guid); + if (window.isSmartphone()) { + window.show('info'); + } else if (!$('#scrollwrapper').is(':visible')) { + $('#sidebartoggle').click(); + } +} + L.PortalMarker = L.CircleMarker.extend({ options: {}, initialize: function(latlng, data) { L.CircleMarker.prototype.initialize.call(this, latlng); this.updateDetails(data); + + this.on('click', handler_portal_click); + this.on('dblclick', handler_portal_dblclick); + this.on('contextmenu', handler_portal_contextmenu); }, updateDetails: function(details) { // xxx: handle permanent data From 253ea8bf096334b54f154807668f73340bf39316 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Wed, 10 Feb 2021 19:23:35 +0100 Subject: [PATCH 10/38] marker store selected --- core/code/portal_marker.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index fa951b627..9019c9802 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -76,9 +76,13 @@ L.PortalMarker = L.CircleMarker.extend({ highlightPortal(this); - if (selected) { + if (selected === false) + this._selected = false; + else + this._selected = this._selected || selected; + + if (this._selected) this.setStyle ({color: COLOR_SELECTED_PORTAL}); - } }, _style: function () { var dashArray = null; From 7d5ca542dcb2a3d71611730fb5d4b06b48721d65 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Fri, 12 Feb 2021 23:35:30 +0100 Subject: [PATCH 11/38] handle portal location edit --- core/code/portal_marker.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index 9019c9802..587243200 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -42,6 +42,10 @@ L.PortalMarker = L.CircleMarker.extend({ this.on('contextmenu', handler_portal_contextmenu); }, updateDetails: function(details) { + // portal has been moved + if (this._details.latE6 !== details.latE6 || this._details.lngE6 !== details.lngE6) + this.setLatLng(L.latLng(details.latE6/1E6, details.lngE6/1E6)); + // xxx: handle permanent data this._details = details; From fa3dddd66914537b9db748bec480bbb4cfd9d225 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sat, 13 Feb 2021 01:12:24 +0100 Subject: [PATCH 12/38] move renderPortalDetails call to marker mechanism --- core/code/map_data_render.js | 11 +---------- core/code/portal_detail.js | 6 ------ core/code/portal_detail_display.js | 2 +- core/code/portal_marker.js | 30 ++++++++++++++++++++++++------ 4 files changed, 26 insertions(+), 23 deletions(-) diff --git a/core/code/map_data_render.js b/core/code/map_data_render.js index 835229068..8025970db 100644 --- a/core/code/map_data_render.js +++ b/core/code/map_data_render.js @@ -208,10 +208,7 @@ window.Render.prototype.endRenderPass = function () { // reorder portals to be after links/fields this.bringPortalsToFront(); - // re-select the selected portal, to re-render the side-bar. ensures that any data calculated from the map data is up to date - if (window.selectedPortal) { - window.renderPortalDetails(window.selectedPortal); - } + this.isRendering = false; }; /** @@ -437,12 +434,6 @@ window.Render.prototype.createPortalEntity = function (ent, details) { window.portals[data.guid] = marker; } - // (re-)select the portal, to refresh the sidebar on any changes - if (data.guid === window.selectedPortal) { - log.log('portal guid ' + data.guid + ' is the selected portal - re-rendering portal details'); - window.renderPortalDetails(window.selectedPortal); - } - window.ornaments.addPortal(marker); // TODO? postpone adding to the map layer diff --git a/core/code/portal_detail.js b/core/code/portal_detail.js index 2730ea514..14db523d1 100644 --- a/core/code/portal_detail.js +++ b/core/code/portal_detail.js @@ -66,12 +66,6 @@ var handleResponse = function (deferred, guid, data, success) { cache.store(guid, portal.options.data); - // FIXME..? better way of handling sidebar refreshing... - - if (guid === window.selectedPortal) { - window.renderPortalDetails(guid); - } - deferred.resolve(portal.options.data); window.runHooks('portalDetailLoaded', { guid: guid, success: success, details: portal.options.data, ent: ent }); } else { diff --git a/core/code/portal_detail_display.js b/core/code/portal_detail_display.js index d58662943..aa5df288f 100644 --- a/core/code/portal_detail_display.js +++ b/core/code/portal_detail_display.js @@ -96,7 +96,7 @@ window.renderPortalDetails = function (guid) { var portal = window.portals[guid]; var data = portal.options.data; - var details = window.portalDetail.get(guid); + var details = portal.hasFullDetails() ? portal.getDetails() : null; var historyDetails = window.getPortalHistoryDetails(data); // details and data can get out of sync. if we have details, construct a matching 'data' diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index 587243200..11102b3df 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -15,14 +15,14 @@ var portalBaseStyle = { // portal hooks function handler_portal_click (e) { - window.renderPortalDetails(e.target.options.guid); + e.target.select(true); } function handler_portal_dblclick (e) { - window.renderPortalDetails(e.target.options.guid); + e.target.select(true); window.map.setView(e.target.getLatLng(), DEFAULT_ZOOM); } function handler_portal_contextmenu (e) { - window.renderPortalDetails(e.target.options.guid); + e.target.select(true); if (window.isSmartphone()) { window.show('info'); } else if (!$('#scrollwrapper').is(':visible')) { @@ -43,8 +43,9 @@ L.PortalMarker = L.CircleMarker.extend({ }, updateDetails: function(details) { // portal has been moved - if (this._details.latE6 !== details.latE6 || this._details.lngE6 !== details.lngE6) - this.setLatLng(L.latLng(details.latE6/1E6, details.lngE6/1E6)); + if (this.details) + if (this._details.latE6 !== details.latE6 || this._details.lngE6 !== details.lngE6) + this.setLatLng(L.latLng(details.latE6/1E6, details.lngE6/1E6)); // xxx: handle permanent data this._details = details; @@ -66,14 +67,31 @@ L.PortalMarker = L.CircleMarker.extend({ }; L.setOptions(this, dataOptions); + if (this._selected) { + this.renderDetails(); + } + this.reset(); }, + renderDetails() { + if (!this._rendering) { + this._rendering = true; + renderPortalDetails(this._details.guid); + this._rendering = false; + } + }, getDetails: function () { return this._details; }, hasFullDetails: function () { return !!this._details.mods }, + select: function (selected) { + if (selected) { + this.renderDetails(); + } + return this.reset(selected); + }, reset: function (selected) { var styleOptions = this._style(); this.setStyle(styleOptions); @@ -155,7 +173,7 @@ window.createMarker = function(latlng, data) { * @param {boolean} selected - Indicates if the portal is selected. */ window.setMarkerStyle = function(marker, selected) { - marker.reset(selected); + marker.select(selected); } /** From 6ceab8ff6a548af491b1d9a204c7764d10e820b2 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sun, 14 Feb 2021 16:05:43 +0100 Subject: [PATCH 13/38] implement new portal data check in marker --- core/code/map_data_render.js | 33 ++++++++++---------------- core/code/portal_marker.js | 45 +++++++++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 24 deletions(-) diff --git a/core/code/map_data_render.js b/core/code/map_data_render.js index 8025970db..992a180f2 100644 --- a/core/code/map_data_render.js +++ b/core/code/map_data_render.js @@ -361,6 +361,14 @@ window.Render.prototype.createPortalEntity = function (ent, details) { var data = window.decodeArray.portal(ent[2], details); var guid = ent[0]; + // add missing fields + data.guid = guid; + if (!data.timestamp) + data.timestamp = ent[1]; + + // LEGACY - TO BE REMOVED AT SOME POINT! use .guid, .timestamp and .data instead + data.ent = ent; + // check if entity already exists const oldPortal = guid in window.portals; @@ -368,35 +376,18 @@ window.Render.prototype.createPortalEntity = function (ent, details) { // yes. now check to see if the entity data we have is newer than that in place var p = window.portals[guid]; - if (!data.history || p.options.data.history === data.history) { - if (p.options.timestamp > ent[1]) { - return p; // this data is older - abort processing - } - - if (p.options.timestamp == ent[1] && p.hasFullDetails()) // this data is identical - abort processing - return p; + if (!p.willUpdate(data)) { + // this data doesn't bring new detail - abort processing + return p; } // the data we have is newer. many data changes require re-rendering of the portal // (e.g. level changed, so size is different, or stats changed so highlighter is different) // remember the old details, for the callback - previousData = p.getDetails(); - - // preserve history - if (!data.history) { - data.history = previousData.history; - } + previousData = $.extend(true, {}, p.getDetails()); } - // add missing fields - data.guid = guid; - if (!data.timestamp) - data.timestamp = ent[1]; - - // LEGACY - TO BE REMOVED AT SOME POINT! use .guid, .timestamp and .data instead - data.ent = ent; - var latlng = L.latLng(data.latE6 / 1e6, data.lngE6 / 1e6); window.pushPortalGuidPositionCache(data.guid, data.latE6, data.lngE6); diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index 11102b3df..de712beaf 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -41,14 +41,53 @@ L.PortalMarker = L.CircleMarker.extend({ this.on('dblclick', handler_portal_dblclick); this.on('contextmenu', handler_portal_contextmenu); }, + willUpdate: function (details) { + // portal location edit + if (this._details.latE6 !== details.latE6 || this._details.lngE6 !== details.lngE6) + return true; + // new data + if (this._details.timestamp < details.timestamp) + return true; + // even if we get history that was missing ? is it even possible ? + if (this._details.timestamp > details.timestamp) + return false; + + // get new history + if (details.history) { + if (!this._details.history) + return true; + if (this._details.history._raw !== details.history._raw) + return true; + } + + // get details portal data + if (!this._details.mods && details.mods) + return true; + + // does portal picture/name/location modfication update the timestamp ? + return false; + }, updateDetails: function(details) { // portal has been moved - if (this.details) + if (this._details) { if (this._details.latE6 !== details.latE6 || this._details.lngE6 !== details.lngE6) this.setLatLng(L.latLng(details.latE6/1E6, details.lngE6/1E6)); - // xxx: handle permanent data - this._details = details; + // we got more details + if (this._details.timestamp == details.timestamp) { + var localThis = this; + ["mods", "resonators", "owner", "artifactDetail", "history"].forEach(function (prop) { + if (details[prop]) localThis._details[prop] = details[prop]; + }); + // LEGACY - TO BE REMOVED AT SOME POINT! use .guid, .timestamp and .data instead + this._details.ent = details.ent; + } else { + // permanent data (history only) + if (!details.history) details.history = this._details.history; + + this._details = details; + } + } else this._details = details; this._level = parseInt(details.level) || 0; this._team = window.teamStringToId(details.team); From 71f2b37e40fd0db9e836c69c43cf734ceaa9e53f Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sun, 14 Feb 2021 19:30:57 +0100 Subject: [PATCH 14/38] set marker style once apply/adapt set(Marker)Style PR #251 by johnd0e commit 6201837d94c87345d80086503b3623127276adca --- core/code/portal_marker.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index de712beaf..e23c5b650 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -125,6 +125,22 @@ L.PortalMarker = L.CircleMarker.extend({ hasFullDetails: function () { return !!this._details.mods }, + setStyle: function (style) { // stub for highlighters + L.Util.setOptions(this, style); + return this; + }, + setMarkerStyle: function (style) { + var styleOptions = L.Util.extend(this._style(), style); + L.Util.setOptions(this, styleOptions); + + L.Util.setOptions(this, highlightPortal(this)); + + var selected = L.extend( + { radius: this.options.radius }, + this._selected && { color: COLOR_SELECTED_PORTAL } + ); + return L.CircleMarker.prototype.setStyle.call(this, selected); + }, select: function (selected) { if (selected) { this.renderDetails(); @@ -132,18 +148,12 @@ L.PortalMarker = L.CircleMarker.extend({ return this.reset(selected); }, reset: function (selected) { - var styleOptions = this._style(); - this.setStyle(styleOptions); - - highlightPortal(this); - if (selected === false) this._selected = false; else this._selected = this._selected || selected; - if (this._selected) - this.setStyle ({color: COLOR_SELECTED_PORTAL}); + return this.setMarkerStyle(); }, _style: function () { var dashArray = null; From a0ee641f5677c247f6c2159e08fda61801f2a691 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sun, 14 Feb 2021 19:52:52 +0100 Subject: [PATCH 15/38] highlighter may return the applied style --- core/code/portal_highlighter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/code/portal_highlighter.js b/core/code/portal_highlighter.js index a55b1b138..c40f6c8bb 100644 --- a/core/code/portal_highlighter.js +++ b/core/code/portal_highlighter.js @@ -113,7 +113,7 @@ window.changePortalHighlights = function (name) { */ window.highlightPortal = function (p) { if (window._highlighters !== null && window._highlighters[window._current_highlighter] !== undefined) { - window._highlighters[window._current_highlighter].highlight({ portal: p }); + return window._highlighters[window._current_highlighter].highlight({ portal: p }); } }; From e796f81e3af4286e3acb08cee53852a2ef9c100a Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Tue, 16 Feb 2021 22:22:26 +0100 Subject: [PATCH 16/38] add event name to portalSelected hook --- core/code/portal_detail_display.js | 18 ++++++------------ core/code/portal_marker.js | 27 +++++++++++++++------------ 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/core/code/portal_detail_display.js b/core/code/portal_detail_display.js index aa5df288f..90dee369f 100644 --- a/core/code/portal_detail_display.js +++ b/core/code/portal_detail_display.js @@ -70,8 +70,8 @@ window.renderPortalUrl = function (lat, lng, title, guid) { * @function renderPortalDetails * @param {string|null} guid - The globally unique identifier of the portal to display details for. */ -window.renderPortalDetails = function (guid) { - window.selectPortal(window.portals[guid] ? guid : null); +window.renderPortalDetails = function (guid, dontSelect) { + if (!dontSelect) window.selectPortal(window.portals[guid] ? guid : null, 'renderPortalDetails'); if ($('#sidebar').is(':visible')) { window.resetScrollOnNewPortal(); window.renderPortalDetails.lastVisible = guid; @@ -337,7 +337,7 @@ window.setPortalIndicators = function (p) { * @param {string} guid - The GUID of the portal to select. * @returns {boolean} True if the same portal is re-selected (just an update), false if a different portal is selected. */ -window.selectPortal = function (guid) { +window.selectPortal = function (guid, event) { var update = window.selectedPortal === guid; var oldPortalGuid = window.selectedPortal; window.selectedPortal = guid; @@ -346,20 +346,14 @@ window.selectPortal = function (guid) { var newPortal = window.portals[guid]; // Restore style of unselected portal - if (!update && oldPortal) window.setMarkerStyle(oldPortal, false); + if (!update && oldPortal) oldPortal.setSelected(false); // Change style of selected portal - if (newPortal) { - window.setMarkerStyle(newPortal, true); - - if (window.map.hasLayer(newPortal)) { - newPortal.bringToFront(); - } - } + if(newPortal) newPortal.setSelected(true); window.setPortalIndicators(newPortal); - window.runHooks('portalSelected', { selectedPortalGuid: guid, unselectedPortalGuid: oldPortalGuid }); + window.runHooks('portalSelected', { selectedPortalGuid: guid, unselectedPortalGuid: oldPortalGuid, event: event }); return update; }; diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index e23c5b650..efa33f881 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -15,14 +15,17 @@ var portalBaseStyle = { // portal hooks function handler_portal_click (e) { - e.target.select(true); + window.selectPortal(e.target.options.guid, e.type); + window.renderPortalDetails(e.target.options.guid, true) } function handler_portal_dblclick (e) { - e.target.select(true); + window.selectPortal(e.target.options.guid, e.type); + window.renderPortalDetails(e.target.options.guid, true) window.map.setView(e.target.getLatLng(), DEFAULT_ZOOM); } function handler_portal_contextmenu (e) { - e.target.select(true); + window.selectPortal(e.target.options.guid, e.type); + window.renderPortalDetails(e.target.options.guid, true) if (window.isSmartphone()) { window.show('info'); } else if (!$('#scrollwrapper').is(':visible')) { @@ -107,15 +110,15 @@ L.PortalMarker = L.CircleMarker.extend({ L.setOptions(this, dataOptions); if (this._selected) { - this.renderDetails(); + this._renderDetails(); } this.reset(); }, - renderDetails() { + _renderDetails() { if (!this._rendering) { this._rendering = true; - renderPortalDetails(this._details.guid); + renderPortalDetails(this._details.guid, true); this._rendering = false; } }, @@ -141,10 +144,7 @@ L.PortalMarker = L.CircleMarker.extend({ ); return L.CircleMarker.prototype.setStyle.call(this, selected); }, - select: function (selected) { - if (selected) { - this.renderDetails(); - } + setSelected: function (selected) { return this.reset(selected); }, reset: function (selected) { @@ -153,7 +153,10 @@ L.PortalMarker = L.CircleMarker.extend({ else this._selected = this._selected || selected; - return this.setMarkerStyle(); + this.setMarkerStyle(); + + if (this._selected && window.map.hasLayer(this)) + this.bringToFront(); }, _style: function () { var dashArray = null; @@ -222,7 +225,7 @@ window.createMarker = function(latlng, data) { * @param {boolean} selected - Indicates if the portal is selected. */ window.setMarkerStyle = function(marker, selected) { - marker.select(selected); + marker.setSelected(selected); } /** From a4711127fdb013a3729a5847023c73ccd0b925ee Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Tue, 16 Feb 2021 22:33:47 +0100 Subject: [PATCH 17/38] remove portalMarker.reset --- core/code/portal_marker.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index efa33f881..aa383a878 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -113,7 +113,7 @@ L.PortalMarker = L.CircleMarker.extend({ this._renderDetails(); } - this.reset(); + this.setSelected(); }, _renderDetails() { if (!this._rendering) { @@ -145,9 +145,6 @@ L.PortalMarker = L.CircleMarker.extend({ return L.CircleMarker.prototype.setStyle.call(this, selected); }, setSelected: function (selected) { - return this.reset(selected); - }, - reset: function (selected) { if (selected === false) this._selected = false; else From 685e3d3021d8c16f20b755f443ad896deaefd30f Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Tue, 16 Feb 2021 23:05:07 +0100 Subject: [PATCH 18/38] render portal base on portal marker details --- core/code/portal_detail_display.js | 40 ++++++++++++++---------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/core/code/portal_detail_display.js b/core/code/portal_detail_display.js index 90dee369f..6a3aa4aa1 100644 --- a/core/code/portal_detail_display.js +++ b/core/code/portal_detail_display.js @@ -95,34 +95,29 @@ window.renderPortalDetails = function (guid, dontSelect) { } var portal = window.portals[guid]; - var data = portal.options.data; - var details = portal.hasFullDetails() ? portal.getDetails() : null; - var historyDetails = window.getPortalHistoryDetails(data); + var details = portal.getDetails(); + var hasFullDetails = portal.hasFullDetails(); + var historyDetails = window.getPortalHistoryDetails(details); - // details and data can get out of sync. if we have details, construct a matching 'data' - if (details) { - data = window.getPortalSummaryData(details); - } - - var modDetails = details ? '
' + window.getModDetails(details) + '
' : ''; - var miscDetails = details ? window.getPortalMiscDetails(guid, details) : ''; - var resoDetails = details ? window.getResonatorDetails(details) : ''; + var modDetails = hasFullDetails ? '
' + window.getModDetails(details) + '
' : ''; + var miscDetails = hasFullDetails ? window.getPortalMiscDetails(guid, details) : ''; + var resoDetails = hasFullDetails ? window.getResonatorDetails(details) : ''; // TODO? other status details... - var statusDetails = details ? '' : '
Loading details...
'; + var statusDetails = hasFullDetails ? '' : '
Loading details...
'; - var img = window.fixPortalImageUrl(details ? details.image : data.image); - var title = (details && details.title) || (data && data.title) || 'null'; + var img = window.fixPortalImageUrl(details.image); + var title = details.title || 'null'; - var lat = data.latE6 / 1e6; - var lng = data.lngE6 / 1e6; + var lat = details.latE6 / 1e6; + var lng = details.lngE6 / 1e6; var imgTitle = title + '\n\nClick to show full image.'; // portal level. start with basic data - then extend with fractional info in tooltip if available - var levelInt = window.teamStringToId(data.team) === window.TEAM_NONE ? 0 : data.level; + var levelInt = portal.options.level; var levelDetails = levelInt; - if (details) { + if (hasFullDetails) { levelDetails = window.getPortalLevel(details); if (levelDetails !== 8) { if (levelDetails === Math.ceil(levelDetails)) levelDetails += '\n8'; @@ -136,7 +131,7 @@ window.renderPortalDetails = function (guid, dontSelect) { $('#portaldetails') .html('') // to ensure it's clear - .attr('class', window.TEAM_TO_CSS[window.teamStringToId(data.team)]) + .attr('class', window.TEAM_TO_CSS[window.teamStringToId(details.team)]) .append( $('

', { class: 'title' }) .text(title) @@ -147,7 +142,7 @@ window.renderPortalDetails = function (guid, dontSelect) { style: 'float: left', }) .click(function () { - window.zoomToAndShowPortal(guid, [data.latE6 / 1e6, data.lngE6 / 1e6]); + window.zoomToAndShowPortal(guid, [details.latE6 / 1e6, details.lngE6 / 1e6]); if (window.isSmartphone()) { window.show('map'); } @@ -187,9 +182,12 @@ window.renderPortalDetails = function (guid, dontSelect) { window.renderPortalUrl(lat, lng, title, guid); + // compatibility + var data = hasFullDetails ? getPortalSummaryData(details) : details; + // only run the hooks when we have a portalDetails object - most plugins rely on the extended data // TODO? another hook to call always, for any plugins that can work with less data? - if (details) { + if (hasFullDetails) { window.runHooks('portalDetailsUpdated', { guid: guid, portal: portal, portalDetails: details, portalData: data }); } }; From 42e19190b4761797a2dff9945696eccc4acf958c Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Tue, 16 Feb 2021 23:06:12 +0100 Subject: [PATCH 19/38] add portal health function --- core/code/portal_info.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/code/portal_info.js b/core/code/portal_info.js index 6cd62b16b..436ee0665 100644 --- a/core/code/portal_info.js +++ b/core/code/portal_info.js @@ -59,6 +59,13 @@ window.getCurrentPortalEnergy = function (d) { return nrg; }; +window.getPortalHealth = function(d) { + var max = getTotalPortalEnergy(d); + var cur = getCurrentPortalEnergy(d); + + return max>0 ? Math.floor(cur/max*100) : 0; +} + /** * Calculates the range of a portal for creating links. The range depends on portal level and any installed Link Amps. * @@ -68,7 +75,7 @@ window.getCurrentPortalEnergy = function (d) { * total range after applying the boost (`range`), * and a boolean indicating if the portal is linkable (`isLinkable`). */ -window.getPortalRange = function (d) { +window.getPortalRange = function(d) { // formula by the great gals and guys at // http://decodeingress.me/2012/11/18/ingress-portal-levels-and-link-range/ var range = { From 334521e0fcc5d948d894802a71d69588b50c9d45 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Tue, 16 Feb 2021 23:11:55 +0100 Subject: [PATCH 20/38] use portal detail cache on new portal entities --- core/code/map_data_render.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/code/map_data_render.js b/core/code/map_data_render.js index 992a180f2..6b83f4e0b 100644 --- a/core/code/map_data_render.js +++ b/core/code/map_data_render.js @@ -420,6 +420,13 @@ window.Render.prototype.createPortalEntity = function (ent, details) { } else { marker = createMarker(latlng, data); + // in case of incomplete data while having fresh details in cache, update the portal with those details + if (portalDetail.isFresh(guid)) { + var oldDetails = portalDetail.get(guid); + if (marker.willUpdate(oldDetails)) + marker.updateDetails(oldDetails); + } + window.runHooks('portalAdded', { portal: marker }); window.portals[data.guid] = marker; From d00ca7ea37de082c891d5d22541b3df9fd2144d0 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Wed, 17 Feb 2021 00:32:41 +0100 Subject: [PATCH 21/38] remove obsolete data from portal details cache avoid missing details when getEntities replies that the portal has changed while portal details is still fresh (3min) in cache --- core/code/map_data_render.js | 5 ++++- core/code/portal_detail.js | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/code/map_data_render.js b/core/code/map_data_render.js index 6b83f4e0b..bc9061b35 100644 --- a/core/code/map_data_render.js +++ b/core/code/map_data_render.js @@ -423,7 +423,10 @@ window.Render.prototype.createPortalEntity = function (ent, details) { // in case of incomplete data while having fresh details in cache, update the portal with those details if (portalDetail.isFresh(guid)) { var oldDetails = portalDetail.get(guid); - if (marker.willUpdate(oldDetails)) + if (data.timestamp > oldDetails.timestamp) { + // data is more recent than the cached details so we remove them from the cache + portalDetail.remove(guid); + } else if (marker.willUpdate(oldDetails)) marker.updateDetails(oldDetails); } diff --git a/core/code/portal_detail.js b/core/code/portal_detail.js index 14db523d1..f9eabe80e 100644 --- a/core/code/portal_detail.js +++ b/core/code/portal_detail.js @@ -54,6 +54,10 @@ window.portalDetail.isFresh = function (guid) { return cache.isFresh(guid); }; +window.portalDetail.remove = function(guid) { + return cache.remove(guid); +}; + var handleResponse = function (deferred, guid, data, success) { if (!data || data.error || !data.result) { success = false; From 1b0a2b4b63d423d4e851dcb8626f402f6c49d67f Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Tue, 16 Feb 2021 23:40:25 +0100 Subject: [PATCH 22/38] placeholder: use timestamp from link/field --- core/code/map_data_render.js | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/core/code/map_data_render.js b/core/code/map_data_render.js index bc9061b35..d06b40e74 100644 --- a/core/code/map_data_render.js +++ b/core/code/map_data_render.js @@ -302,6 +302,7 @@ window.Render.prototype.deleteFieldEntity = function (guid) { * @param {number} latE6 - The latitude of the portal in E6 format. * @param {number} lngE6 - The longitude of the portal in E6 format. * @param {string} team - The team faction of the portal. + * @param {number} [timestamp=0] - Timestamp of the portal data. Defaults to 0 to allow newer data sources to override * @param {number} [timestamp] - The timestamp of the portal data. */ window.Render.prototype.createPlaceholderPortalEntity = function (guid, latE6, lngE6, team, timestamp) { @@ -316,7 +317,7 @@ window.Render.prototype.createPlaceholderPortalEntity = function (guid, latE6, l var ent = [ guid, // ent[0] = guid - -1, // ent[1] = timestamp - zero will mean any other source of portal data will have a higher timestamp + timestamp, // ent[1] = timestamp // ent[2] = an array with the entity data [ 'p', // 0 - a portal @@ -326,23 +327,8 @@ window.Render.prototype.createPlaceholderPortalEntity = function (guid, latE6, l ], ]; - // placeholder portals don't have a useful timestamp value - so the standard code that checks for updated - // portal details doesn't apply - // so, check that the basic details are valid and delete the existing portal if out of date - var portalMoved = false; - if (guid in window.portals) { - var p = window.portals[guid]; - portalMoved = latE6 !== p.options.data.latE6 || lngE6 !== p.options.data.lngE6; - if (team !== p.options.data.team && p.options.timestamp < timestamp) { - // team - delete existing portal - this.deletePortalEntity(guid); - } - } - - if (!portalMoved) { - this.createPortalEntity(ent, 'core'); // placeholder - } -}; + this.createPortalEntity(ent, 'core'); // placeholder +} /** * Creates a portal entity from the provided game entity data. From 64fc59182499b0e994c5b412ea96f5cefbc64a69 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Wed, 17 Feb 2021 14:16:45 +0100 Subject: [PATCH 23/38] portalmarker: init select state --- core/code/portal_marker.js | 1 + 1 file changed, 1 insertion(+) diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index aa383a878..6b9720793 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -38,6 +38,7 @@ L.PortalMarker = L.CircleMarker.extend({ initialize: function(latlng, data) { L.CircleMarker.prototype.initialize.call(this, latlng); + this._selected = data.guid === selectedPortal; this.updateDetails(data); this.on('click', handler_portal_click); From b565376d768045c97dfc876dbcea9624baa1677e Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Wed, 17 Feb 2021 14:27:55 +0100 Subject: [PATCH 24/38] render details on new selected portal entity --- core/code/map_data_render.js | 3 +++ core/code/portal_marker.js | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/core/code/map_data_render.js b/core/code/map_data_render.js index d06b40e74..40934f276 100644 --- a/core/code/map_data_render.js +++ b/core/code/map_data_render.js @@ -419,6 +419,9 @@ window.Render.prototype.createPortalEntity = function (ent, details) { window.runHooks('portalAdded', { portal: marker }); window.portals[data.guid] = marker; + + if (selectedPortal === data.guid) + marker.renderDetails(); } window.ornaments.addPortal(marker); diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index 6b9720793..4988f070e 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -111,12 +111,12 @@ L.PortalMarker = L.CircleMarker.extend({ L.setOptions(this, dataOptions); if (this._selected) { - this._renderDetails(); + this.renderDetails(); } this.setSelected(); }, - _renderDetails() { + renderDetails() { if (!this._rendering) { this._rendering = true; renderPortalDetails(this._details.guid, true); From 2e8728c71d23c77fa46b2e3b069a7deb07ec6cee Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Wed, 17 Feb 2021 19:04:00 +0100 Subject: [PATCH 25/38] fix: use this._details --- core/code/portal_marker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index 4988f070e..a6fcec5ae 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -93,8 +93,8 @@ L.PortalMarker = L.CircleMarker.extend({ } } else this._details = details; - this._level = parseInt(details.level) || 0; - this._team = window.teamStringToId(details.team); + this._level = parseInt(this._details.level) || 0; + this._team = window.teamStringToId(this._details.team); // the data returns unclaimed portals as level 1 - but IITC wants them treated as level 0 if (this._team === TEAM_NONE) this._level = 0; From 9c1e6ad377267bfeda36dfab86a7f25899f278ae Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Wed, 17 Feb 2021 19:05:25 +0100 Subject: [PATCH 26/38] better placeholder handling --- core/code/portal_marker.js | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index a6fcec5ae..f50825a01 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -49,9 +49,20 @@ L.PortalMarker = L.CircleMarker.extend({ // portal location edit if (this._details.latE6 !== details.latE6 || this._details.lngE6 !== details.lngE6) return true; + // placeholder + if (details.level === undefined) { + // if team differs and corresponding link/field is more recent + if (this._details.timestamp < details.timestamp && this._details.team !== details.team) + return true; + // in any other case + return false; + } // new data if (this._details.timestamp < details.timestamp) return true; + // current marker is a placeholder, and details is real data + if (this.isPlaceholder()) + return true; // even if we get history that was missing ? is it even possible ? if (this._details.timestamp > details.timestamp) return false; @@ -72,13 +83,23 @@ L.PortalMarker = L.CircleMarker.extend({ return false; }, updateDetails: function(details) { - // portal has been moved if (this._details) { + // portal has been moved if (this._details.latE6 !== details.latE6 || this._details.lngE6 !== details.lngE6) this.setLatLng(L.latLng(details.latE6/1E6, details.lngE6/1E6)); - // we got more details - if (this._details.timestamp == details.timestamp) { + // core data from a placeholder + if (details.level === undefined) { + // if team has changed + if (this._details.timestamp < details.timestamp && this._details.team !== details.team) { + // keep history, title, image + details.title = this._details.title; + details.image = this._details.image; + details.history = this._details.history; + this._details = details; + } + } else if (this._details.timestamp == details.timestamp) { + // we got more details var localThis = this; ["mods", "resonators", "owner", "artifactDetail", "history"].forEach(function (prop) { if (details[prop]) localThis._details[prop] = details[prop]; @@ -126,6 +147,9 @@ L.PortalMarker = L.CircleMarker.extend({ getDetails: function () { return this._details; }, + isPlaceholder: function () { + return this._details.level === undefined; + }, hasFullDetails: function () { return !!this._details.mods }, From 1aff25436c03093c08aa090ea35872d42f1bb64c Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Fri, 19 Feb 2021 18:27:23 +0100 Subject: [PATCH 27/38] render details: select if forced or not selected --- core/code/portal_detail_display.js | 5 +++-- core/code/portal_marker.js | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/core/code/portal_detail_display.js b/core/code/portal_detail_display.js index 6a3aa4aa1..ff1735709 100644 --- a/core/code/portal_detail_display.js +++ b/core/code/portal_detail_display.js @@ -70,8 +70,9 @@ window.renderPortalUrl = function (lat, lng, title, guid) { * @function renderPortalDetails * @param {string|null} guid - The globally unique identifier of the portal to display details for. */ -window.renderPortalDetails = function (guid, dontSelect) { - if (!dontSelect) window.selectPortal(window.portals[guid] ? guid : null, 'renderPortalDetails'); +window.renderPortalDetails = function(guid, forceSelect) { + if (forceSelect || window.selectedPortal !== guid) + window.selectPortal(window.portals[guid] ? guid : null, 'renderPortalDetails'); if ($('#sidebar').is(':visible')) { window.resetScrollOnNewPortal(); window.renderPortalDetails.lastVisible = guid; diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index f50825a01..314db5278 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -16,16 +16,16 @@ var portalBaseStyle = { // portal hooks function handler_portal_click (e) { window.selectPortal(e.target.options.guid, e.type); - window.renderPortalDetails(e.target.options.guid, true) + window.renderPortalDetails(e.target.options.guid) } function handler_portal_dblclick (e) { window.selectPortal(e.target.options.guid, e.type); - window.renderPortalDetails(e.target.options.guid, true) + window.renderPortalDetails(e.target.options.guid) window.map.setView(e.target.getLatLng(), DEFAULT_ZOOM); } function handler_portal_contextmenu (e) { window.selectPortal(e.target.options.guid, e.type); - window.renderPortalDetails(e.target.options.guid, true) + window.renderPortalDetails(e.target.options.guid) if (window.isSmartphone()) { window.show('info'); } else if (!$('#scrollwrapper').is(':visible')) { @@ -61,7 +61,7 @@ L.PortalMarker = L.CircleMarker.extend({ if (this._details.timestamp < details.timestamp) return true; // current marker is a placeholder, and details is real data - if (this.isPlaceholder()) + if (this.isPlaceholder() && this._details.team === details.team) return true; // even if we get history that was missing ? is it even possible ? if (this._details.timestamp > details.timestamp) @@ -140,7 +140,7 @@ L.PortalMarker = L.CircleMarker.extend({ renderDetails() { if (!this._rendering) { this._rendering = true; - renderPortalDetails(this._details.guid, true); + renderPortalDetails(this._details.guid); this._rendering = false; } }, From cbb97a15c4d82fa8cc20b3b3390431725232f5d7 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Mon, 22 Feb 2021 21:11:42 +0100 Subject: [PATCH 28/38] handle missing history --- core/code/portal_marker.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index 314db5278..4ba3d64ff 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -101,9 +101,21 @@ L.PortalMarker = L.CircleMarker.extend({ } else if (this._details.timestamp == details.timestamp) { // we got more details var localThis = this; - ["mods", "resonators", "owner", "artifactDetail", "history"].forEach(function (prop) { + ["mods", "resonators", "owner", "artifactDetail"].forEach(function (prop) { if (details[prop]) localThis._details[prop] = details[prop]; }); + // smarter update for history (cause it's missing sometimes) + if (details.history) { + if (!this._details.history) this._details.history = details.history; + else { + if (this._details.history._raw & details.history._raw != this._details.history._raw) + log.warn("new portal data has lost some history"); + this._details.history._raw |= details.history._raw; + ['visited', 'captured', 'scoutControlled'].forEach(function (prop) { + localThis._details.history[prop] ||= details.history[prop]; + }); + } + } // LEGACY - TO BE REMOVED AT SOME POINT! use .guid, .timestamp and .data instead this._details.ent = details.ent; } else { From a955536c18691393f0b7c50086eb8489f937fd78 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Tue, 23 Feb 2021 23:12:23 +0100 Subject: [PATCH 29/38] dont recreate markers when outside view --- core/code/map_data_render.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/core/code/map_data_render.js b/core/code/map_data_render.js index 40934f276..4ce9edca7 100644 --- a/core/code/map_data_render.js +++ b/core/code/map_data_render.js @@ -46,7 +46,9 @@ window.Render.prototype.clearPortalsOutsideBounds = function (bounds) { var p = window.portals[guid]; // clear portals outside visible bounds - unless it's the selected portal, or it's relevant to artifacts if (!bounds.contains(p.getLatLng()) && guid !== window.selectedPortal && !window.artifact.isInterestingPortal(guid)) { - this.deletePortalEntity(guid); + // remove the marker as a layer first + // deletion will be done at endRenderPass + p.remove(); } } }; @@ -364,6 +366,9 @@ window.Render.prototype.createPortalEntity = function (ent, details) { if (!p.willUpdate(data)) { // this data doesn't bring new detail - abort processing + // re-add the portal to the relevant layer (does nothing if already in the correct layer) + // useful for portals outside the view + this.addPortalToMapLayer(p); return p; } @@ -397,8 +402,6 @@ window.Render.prototype.createPortalEntity = function (ent, details) { if (oldPortal) { // update marker style/highlight and layer marker = window.portals[data.guid]; - // remove portal from its faction/level specific layer - this.removePortalFromMapLayer(marker); marker.updateDetails(data); From 7ff93ecdf4861049366e22514c8964bb7bed36fb Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Thu, 6 May 2021 23:13:10 +0200 Subject: [PATCH 30/38] marker: update all data available --- core/code/portal_marker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index 4ba3d64ff..b796169ec 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -99,9 +99,9 @@ L.PortalMarker = L.CircleMarker.extend({ this._details = details; } } else if (this._details.timestamp == details.timestamp) { - // we got more details + // we got more details (core/summary -> summary/detailed/extended) var localThis = this; - ["mods", "resonators", "owner", "artifactDetail"].forEach(function (prop) { + ["level", "health", "resCount", "image", "title", "ornaments", "mission", "mission50plus", "artifactBrief", "mods", "resonators", "owner", "artifactDetail"].forEach(function (prop) { if (details[prop]) localThis._details[prop] = details[prop]; }); // smarter update for history (cause it's missing sometimes) From 16cce2ecb6a662d0f0b3d3a801f923bd175a4a1a Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sun, 23 May 2021 00:04:44 +0200 Subject: [PATCH 31/38] portal edits change the timestamp photo/title --- core/code/portal_marker.js | 1 - 1 file changed, 1 deletion(-) diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index b796169ec..bbfbfd81e 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -79,7 +79,6 @@ L.PortalMarker = L.CircleMarker.extend({ if (!this._details.mods && details.mods) return true; - // does portal picture/name/location modfication update the timestamp ? return false; }, updateDetails: function(details) { From 5f86ba6b284cf6b28adb18610fa13c3c6e2ea26b Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Mon, 5 Jul 2021 16:00:43 +0200 Subject: [PATCH 32/38] apply to all placeholders --- core/code/portal_marker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index bbfbfd81e..63a56e508 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -194,7 +194,7 @@ L.PortalMarker = L.CircleMarker.extend({ _style: function () { var dashArray = null; // dashed outline for placeholder portals - if (this._team !== TEAM_NONE && this._level === 0) dashArray = '1,2'; + if (this.isPlaceholder()) dashArray = '1,2'; return L.extend(this._scale(), portalBaseStyle, { color: COLORS[this._team], @@ -215,7 +215,7 @@ L.PortalMarker = L.CircleMarker.extend({ var lvlRadius = LEVEL_TO_RADIUS[level] * scale; // thinner outline for placeholder portals - if (this._team !== TEAM_NONE && level === 0) { + if (this.isPlaceholder()) { lvlWeight = 1; } From fe6b0e338e90db2dc51b0f87363d034bb248051e Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Mon, 5 Jul 2021 16:55:14 +0200 Subject: [PATCH 33/38] move portal style as statics of L.PortalMarker --- core/code/portal_marker.js | 68 ++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index 63a56e508..18206b28d 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -36,6 +36,25 @@ function handler_portal_contextmenu (e) { L.PortalMarker = L.CircleMarker.extend({ options: {}, + statics: { + // base style + portalBaseStyle: { + stroke: true, + opacity: 1, + fill: true, + fillOpacity: 0.5, + interactive: true, + }, + // placeholder style + placeholderStyle: { + dashArray: '1,2', + weight: 1, + }, + // portal level 0 1 2 3 4 5 6 7 8 + LEVEL_TO_WEIGHT: [2, 2, 2, 2, 2, 3, 3, 4, 4], + LEVEL_TO_RADIUS: [7, 7, 7, 7, 8, 8, 9, 10, 11], + }, + initialize: function(latlng, data) { L.CircleMarker.prototype.initialize.call(this, latlng); this._selected = data.guid === selectedPortal; @@ -194,9 +213,9 @@ L.PortalMarker = L.CircleMarker.extend({ _style: function () { var dashArray = null; // dashed outline for placeholder portals - if (this.isPlaceholder()) dashArray = '1,2'; + if (this.isPlaceholder()) dashArray = L.PortalMarker.placeholderStyle.dashArray; - return L.extend(this._scale(), portalBaseStyle, { + return L.extend(this._scale(), L.PortalMarker.portalBaseStyle, { color: COLORS[this._team], fillColor: COLORS[this._team], dashArray: dashArray @@ -205,18 +224,14 @@ L.PortalMarker = L.CircleMarker.extend({ _scale: function () { var scale = window.portalMarkerScale(); - // portal level 0 1 2 3 4 5 6 7 8 - var LEVEL_TO_WEIGHT = [2, 2, 2, 2, 2, 3, 3, 4, 4]; - var LEVEL_TO_RADIUS = [7, 7, 7, 7, 8, 8, 9,10,11]; - var level = Math.floor(this._level || 0); - var lvlWeight = LEVEL_TO_WEIGHT[level] * Math.sqrt(scale); - var lvlRadius = LEVEL_TO_RADIUS[level] * scale; + var lvlWeight = L.PortalMarker.LEVEL_TO_WEIGHT[level] * Math.sqrt(scale); + var lvlRadius = L.PortalMarker.LEVEL_TO_RADIUS[level] * scale; // thinner outline for placeholder portals if (this.isPlaceholder()) { - lvlWeight = 1; + lvlWeight = L.PortalMarker.placeholderStyle.weight; } return { @@ -271,33 +286,30 @@ window.setMarkerStyle = function(marker, selected) { window.getMarkerStyleOptions = function (details) { var scale = window.portalMarkerScale(); - // portal level 0 1 2 3 4 5 6 7 8 - var LEVEL_TO_WEIGHT = [2, 2, 2, 2, 2, 3, 3, 4, 4]; - var LEVEL_TO_RADIUS = [7, 7, 7, 7, 8, 8, 9, 10, 11]; - var level = Math.floor(details.level || 0); - var lvlWeight = LEVEL_TO_WEIGHT[level] * Math.sqrt(scale); - var lvlRadius = LEVEL_TO_RADIUS[level] * scale; + var lvlWeight = L.PortalMarker.LEVEL_TO_WEIGHT[level] * Math.sqrt(scale); + var lvlRadius = L.PortalMarker.LEVEL_TO_RADIUS[level] * scale; var dashArray = null; // thinner and dashed outline for placeholder portals if (details.team !== window.TEAM_NONE && level === 0) { - lvlWeight = 1; - dashArray = '1,2'; + lvlWeight = L.PortalMarker.placeholderStyle.weight; + dashArray = L.PortalMarker.placeholderStyle.dashArray; } - var options = { - radius: lvlRadius, - stroke: true, - color: window.COLORS[details.team], - weight: lvlWeight, - opacity: 1, - fill: true, - fillColor: window.COLORS[details.team], - fillOpacity: 0.5, - dashArray: dashArray, - }; + var options = L.extend( + { + radius: lvlRadius, + weight: lvlWeight, + }, + L.PortalMarker.portalBaseStyle, + { + color: window.COLORS[details.team], + fillColor: window.COLORS[details.team], + dashArray: dashArray, + } + ); return options; }; From 78b9a112b799b94aefe64d9808499355b1708b46 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Tue, 6 Jul 2021 11:21:22 +0200 Subject: [PATCH 34/38] portal location edit changes the timestamp --- core/code/portal_marker.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index 18206b28d..d578ff330 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -65,10 +65,7 @@ L.PortalMarker = L.CircleMarker.extend({ this.on('contextmenu', handler_portal_contextmenu); }, willUpdate: function (details) { - // portal location edit - if (this._details.latE6 !== details.latE6 || this._details.lngE6 !== details.lngE6) - return true; - // placeholder + // details are from a placeholder if (details.level === undefined) { // if team differs and corresponding link/field is more recent if (this._details.timestamp < details.timestamp && this._details.team !== details.team) From db2415968ec4cd6e2e499256388b778e3bee0451 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Mon, 7 Jun 2021 11:30:45 +0200 Subject: [PATCH 35/38] add comment #1 --- core/code/portal_marker.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index d578ff330..647e91a85 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -73,7 +73,11 @@ L.PortalMarker = L.CircleMarker.extend({ // in any other case return false; } - // new data + // more recent timestamp, this occurs when the data has changed because of: + // - resonator deploy/upgrade + // - mod deploy + // - recharge/damage/decay + // - portal edit (title, location, portal main picture) if (this._details.timestamp < details.timestamp) return true; // current marker is a placeholder, and details is real data @@ -83,6 +87,8 @@ L.PortalMarker = L.CircleMarker.extend({ if (this._details.timestamp > details.timestamp) return false; + // this._details.timestamp === details.timestamp + // get new history if (details.history) { if (!this._details.history) From f314b48b38e09b241e0a896b802f7e9ecad0e0c9 Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Mon, 7 Jun 2021 15:14:24 +0200 Subject: [PATCH 36/38] placeholder: don't use use timestamp from field use only the link timestamp for reliable timestamp --- core/code/map_data_render.js | 2 +- core/code/portal_marker.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/code/map_data_render.js b/core/code/map_data_render.js index 4ce9edca7..330164535 100644 --- a/core/code/map_data_render.js +++ b/core/code/map_data_render.js @@ -457,7 +457,7 @@ window.Render.prototype.createFieldEntity = function (ent) { // create placeholder portals for field corners. we already do links, but there are the odd case where this is useful for (var i = 0; i < 3; i++) { var p = data.points[i]; - this.createPlaceholderPortalEntity(p.guid, p.latE6, p.lngE6, data.team, data.timestamp); + this.createPlaceholderPortalEntity(p.guid, p.latE6, p.lngE6, data.team, 0); } // check if entity already exists diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index 647e91a85..59ade0bd5 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -67,7 +67,7 @@ L.PortalMarker = L.CircleMarker.extend({ willUpdate: function (details) { // details are from a placeholder if (details.level === undefined) { - // if team differs and corresponding link/field is more recent + // if team differs and corresponding link is more recent (ignore field) if (this._details.timestamp < details.timestamp && this._details.team !== details.team) return true; // in any other case From 8f82f4f83a14253af27b99c9e379856ee312b7af Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sat, 8 Jan 2022 14:57:01 +0100 Subject: [PATCH 37/38] lint --- core/code/map_data_render.js | 25 +++-- core/code/portal_detail.js | 2 +- core/code/portal_detail_display.js | 16 ++- core/code/portal_info.js | 20 ++-- core/code/portal_marker.js | 157 +++++++++++++++++------------ 5 files changed, 135 insertions(+), 85 deletions(-) diff --git a/core/code/map_data_render.js b/core/code/map_data_render.js index 330164535..fc1c423d9 100644 --- a/core/code/map_data_render.js +++ b/core/code/map_data_render.js @@ -330,7 +330,7 @@ window.Render.prototype.createPlaceholderPortalEntity = function (guid, latE6, l ]; this.createPortalEntity(ent, 'core'); // placeholder -} +}; /** * Creates a portal entity from the provided game entity data. @@ -351,8 +351,9 @@ window.Render.prototype.createPortalEntity = function (ent, details) { // add missing fields data.guid = guid; - if (!data.timestamp) + if (!data.timestamp) { data.timestamp = ent[1]; + } // LEGACY - TO BE REMOVED AT SOME POINT! use .guid, .timestamp and .data instead data.ent = ent; @@ -386,14 +387,14 @@ window.Render.prototype.createPortalEntity = function (ent, details) { // check for URL links to portal, and select it if this is the one if (window.urlPortalLL && window.urlPortalLL[0] === latlng.lat && window.urlPortalLL[1] === latlng.lng) { // URL-passed portal found via pll parameter - set the guid-based parameter - log.log('urlPortalLL ' + window.urlPortalLL[0] + ',' + urlPortalLL[1] + ' matches portal GUID ' + data.guid); + log.log('urlPortalLL ' + window.urlPortalLL[0] + ',' + window.urlPortalLL[1] + ' matches portal GUID ' + data.guid); window.urlPortal = data.guid; window.urlPortalLL = undefined; // clear the URL parameter so it's not matched again } if (window.urlPortal === data.guid) { // URL-passed portal found via guid parameter - set it as the selected portal - log.log('urlPortal GUID ' + urlPortal + ' found - selecting...'); + log.log('urlPortal GUID ' + window.urlPortal + ' found - selecting...'); window.selectedPortal = data.guid; window.urlPortal = undefined; // clear the URL parameter so it's not matched again } @@ -405,26 +406,28 @@ window.Render.prototype.createPortalEntity = function (ent, details) { marker.updateDetails(data); - window.runHooks('portalAdded', {portal: marker, previousData: previousData}); + window.runHooks('portalAdded', { portal: marker, previousData: previousData }); } else { - marker = createMarker(latlng, data); + marker = window.createMarker(latlng, data); // in case of incomplete data while having fresh details in cache, update the portal with those details - if (portalDetail.isFresh(guid)) { - var oldDetails = portalDetail.get(guid); + if (window.portalDetail.isFresh(guid)) { + var oldDetails = window.portalDetail.get(guid); if (data.timestamp > oldDetails.timestamp) { // data is more recent than the cached details so we remove them from the cache - portalDetail.remove(guid); - } else if (marker.willUpdate(oldDetails)) + window.portalDetail.remove(guid); + } else if (marker.willUpdate(oldDetails)) { marker.updateDetails(oldDetails); + } } window.runHooks('portalAdded', { portal: marker }); window.portals[data.guid] = marker; - if (selectedPortal === data.guid) + if (window.selectedPortal === data.guid) { marker.renderDetails(); + } } window.ornaments.addPortal(marker); diff --git a/core/code/portal_detail.js b/core/code/portal_detail.js index f9eabe80e..aa38386ef 100644 --- a/core/code/portal_detail.js +++ b/core/code/portal_detail.js @@ -54,7 +54,7 @@ window.portalDetail.isFresh = function (guid) { return cache.isFresh(guid); }; -window.portalDetail.remove = function(guid) { +window.portalDetail.remove = function (guid) { return cache.remove(guid); }; diff --git a/core/code/portal_detail_display.js b/core/code/portal_detail_display.js index ff1735709..9c2489b7e 100644 --- a/core/code/portal_detail_display.js +++ b/core/code/portal_detail_display.js @@ -69,10 +69,12 @@ window.renderPortalUrl = function (lat, lng, title, guid) { * * @function renderPortalDetails * @param {string|null} guid - The globally unique identifier of the portal to display details for. + * @param {boolean} [forceSelect=false] - If true, forces the portal to be selected even if it's already the current portal. */ -window.renderPortalDetails = function(guid, forceSelect) { - if (forceSelect || window.selectedPortal !== guid) +window.renderPortalDetails = function (guid, forceSelect) { + if (forceSelect || window.selectedPortal !== guid) { window.selectPortal(window.portals[guid] ? guid : null, 'renderPortalDetails'); + } if ($('#sidebar').is(':visible')) { window.resetScrollOnNewPortal(); window.renderPortalDetails.lastVisible = guid; @@ -184,7 +186,7 @@ window.renderPortalDetails = function(guid, forceSelect) { window.renderPortalUrl(lat, lng, title, guid); // compatibility - var data = hasFullDetails ? getPortalSummaryData(details) : details; + var data = hasFullDetails ? window.getPortalSummaryData(details) : details; // only run the hooks when we have a portalDetails object - most plugins rely on the extended data // TODO? another hook to call always, for any plugins that can work with less data? @@ -348,11 +350,15 @@ window.selectPortal = function (guid, event) { if (!update && oldPortal) oldPortal.setSelected(false); // Change style of selected portal - if(newPortal) newPortal.setSelected(true); + if (newPortal) newPortal.setSelected(true); window.setPortalIndicators(newPortal); - window.runHooks('portalSelected', { selectedPortalGuid: guid, unselectedPortalGuid: oldPortalGuid, event: event }); + window.runHooks('portalSelected', { + selectedPortalGuid: guid, + unselectedPortalGuid: oldPortalGuid, + event: event, + }); return update; }; diff --git a/core/code/portal_info.js b/core/code/portal_info.js index 436ee0665..9a210901f 100644 --- a/core/code/portal_info.js +++ b/core/code/portal_info.js @@ -59,12 +59,20 @@ window.getCurrentPortalEnergy = function (d) { return nrg; }; -window.getPortalHealth = function(d) { - var max = getTotalPortalEnergy(d); - var cur = getCurrentPortalEnergy(d); +/** + * Calculates the health percentage of a portal based on its current and total energy. + * + * @function getPortalHealth + * @param {Object} d - The portal detail object containing resonator information. + * @returns {number} The portal health as a percentage (0-100). + * Returns 0 if the portal has no total energy. + */ +window.getPortalHealth = function (d) { + var max = window.getTotalPortalEnergy(d); + var cur = window.getCurrentPortalEnergy(d); - return max>0 ? Math.floor(cur/max*100) : 0; -} + return max > 0 ? Math.floor((cur / max) * 100) : 0; +}; /** * Calculates the range of a portal for creating links. The range depends on portal level and any installed Link Amps. @@ -75,7 +83,7 @@ window.getPortalHealth = function(d) { * total range after applying the boost (`range`), * and a boolean indicating if the portal is linkable (`isLinkable`). */ -window.getPortalRange = function(d) { +window.getPortalRange = function (d) { // formula by the great gals and guys at // http://decodeingress.me/2012/11/18/ingress-portal-levels-and-link-range/ var range = { diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index 59ade0bd5..e00bf597f 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -1,31 +1,25 @@ -/* global L -- eslint */ +/* global L, log -- eslint */ /** * @file This file contains the code related to creating and updating portal markers on the map. * @module portal_marker */ -var portalBaseStyle = { - stroke: true, - opacity: 1, - fill: true, - fillOpacity: 0.5, - interactive: true, -}; - // portal hooks -function handler_portal_click (e) { +function handler_portal_click(e) { window.selectPortal(e.target.options.guid, e.type); - window.renderPortalDetails(e.target.options.guid) + window.renderPortalDetails(e.target.options.guid); } -function handler_portal_dblclick (e) { + +function handler_portal_dblclick(e) { window.selectPortal(e.target.options.guid, e.type); - window.renderPortalDetails(e.target.options.guid) - window.map.setView(e.target.getLatLng(), DEFAULT_ZOOM); + window.renderPortalDetails(e.target.options.guid); + window.map.setView(e.target.getLatLng(), window.DEFAULT_ZOOM); } -function handler_portal_contextmenu (e) { + +function handler_portal_contextmenu(e) { window.selectPortal(e.target.options.guid, e.type); - window.renderPortalDetails(e.target.options.guid) + window.renderPortalDetails(e.target.options.guid); if (window.isSmartphone()) { window.show('info'); } else if (!$('#scrollwrapper').is(':visible')) { @@ -55,59 +49,65 @@ L.PortalMarker = L.CircleMarker.extend({ LEVEL_TO_RADIUS: [7, 7, 7, 7, 8, 8, 9, 10, 11], }, - initialize: function(latlng, data) { + initialize: function (latlng, data) { L.CircleMarker.prototype.initialize.call(this, latlng); - this._selected = data.guid === selectedPortal; + this._selected = data.guid === window.selectedPortal; this.updateDetails(data); this.on('click', handler_portal_click); this.on('dblclick', handler_portal_dblclick); this.on('contextmenu', handler_portal_contextmenu); }, + willUpdate: function (details) { // details are from a placeholder if (details.level === undefined) { // if team differs and corresponding link is more recent (ignore field) - if (this._details.timestamp < details.timestamp && this._details.team !== details.team) - return true; - // in any other case - return false; + return this._details.timestamp < details.timestamp && this._details.team !== details.team; } // more recent timestamp, this occurs when the data has changed because of: // - resonator deploy/upgrade // - mod deploy // - recharge/damage/decay // - portal edit (title, location, portal main picture) - if (this._details.timestamp < details.timestamp) + if (this._details.timestamp < details.timestamp) { return true; + } // current marker is a placeholder, and details is real data - if (this.isPlaceholder() && this._details.team === details.team) + if (this.isPlaceholder() && this._details.team === details.team) { return true; + } // even if we get history that was missing ? is it even possible ? - if (this._details.timestamp > details.timestamp) + if (this._details.timestamp > details.timestamp) { return false; + } // this._details.timestamp === details.timestamp // get new history if (details.history) { - if (!this._details.history) + if (!this._details.history) { return true; - if (this._details.history._raw !== details.history._raw) + } + if (this._details.history._raw !== details.history._raw) { return true; + } } // get details portal data - if (!this._details.mods && details.mods) + if (!this._details.mods && details.mods) { return true; + } return false; }, - updateDetails: function(details) { + + updateDetails: function (details) { if (this._details) { // portal has been moved - if (this._details.latE6 !== details.latE6 || this._details.lngE6 !== details.lngE6) - this.setLatLng(L.latLng(details.latE6/1E6, details.lngE6/1E6)); + if (this._details.latE6 !== details.latE6 || this._details.lngE6 !== details.lngE6) { + this.setLatLng(L.latLng(details.latE6 / 1e6, details.lngE6 / 1e6)); + } // core data from a placeholder if (details.level === undefined) { @@ -119,18 +119,34 @@ L.PortalMarker = L.CircleMarker.extend({ details.history = this._details.history; this._details = details; } - } else if (this._details.timestamp == details.timestamp) { + } else if (this._details.timestamp === details.timestamp) { // we got more details (core/summary -> summary/detailed/extended) var localThis = this; - ["level", "health", "resCount", "image", "title", "ornaments", "mission", "mission50plus", "artifactBrief", "mods", "resonators", "owner", "artifactDetail"].forEach(function (prop) { + [ + 'level', + 'health', + 'resCount', + 'image', + 'title', + 'ornaments', + 'mission', + 'mission50plus', + 'artifactBrief', + 'mods', + 'resonators', + 'owner', + 'artifactDetail', + ].forEach(function (prop) { if (details[prop]) localThis._details[prop] = details[prop]; }); // smarter update for history (cause it's missing sometimes) if (details.history) { - if (!this._details.history) this._details.history = details.history; - else { - if (this._details.history._raw & details.history._raw != this._details.history._raw) - log.warn("new portal data has lost some history"); + if (!this._details.history) { + this._details.history = details.history; + } else { + if (this._details.history._raw && details.history._raw !== this._details.history._raw) { + log.warn('new portal data has lost some history'); + } this._details.history._raw |= details.history._raw; ['visited', 'captured', 'scoutControlled'].forEach(function (prop) { localThis._details.history[prop] ||= details.history[prop]; @@ -141,17 +157,23 @@ L.PortalMarker = L.CircleMarker.extend({ this._details.ent = details.ent; } else { // permanent data (history only) - if (!details.history) details.history = this._details.history; + if (!details.history) { + details.history = this._details.history; + } this._details = details; } - } else this._details = details; + } else { + this._details = details; + } this._level = parseInt(this._details.level) || 0; this._team = window.teamStringToId(this._details.team); // the data returns unclaimed portals as level 1 - but IITC wants them treated as level 0 - if (this._team === TEAM_NONE) this._level = 0; + if (this._team === window.TEAM_NONE) { + this._level = 0; + } // compatibility var dataOptions = { @@ -160,7 +182,7 @@ L.PortalMarker = L.CircleMarker.extend({ team: this._team, ent: this._details.ent, // LEGACY - TO BE REMOVED AT SOME POINT! use .guid, .timestamp and .data instead timestamp: this._details.timestamp, - data: this._details + data: this._details, }; L.setOptions(this, dataOptions); @@ -170,60 +192,71 @@ L.PortalMarker = L.CircleMarker.extend({ this.setSelected(); }, + renderDetails() { if (!this._rendering) { this._rendering = true; - renderPortalDetails(this._details.guid); + window.renderPortalDetails(this._details.guid); this._rendering = false; } }, + getDetails: function () { return this._details; }, + isPlaceholder: function () { return this._details.level === undefined; }, + hasFullDetails: function () { - return !!this._details.mods + return !!this._details.mods; }, - setStyle: function (style) { // stub for highlighters + + setStyle: function (style) { + // stub for highlighters L.Util.setOptions(this, style); return this; }, + setMarkerStyle: function (style) { var styleOptions = L.Util.extend(this._style(), style); L.Util.setOptions(this, styleOptions); - L.Util.setOptions(this, highlightPortal(this)); + L.Util.setOptions(this, window.highlightPortal(this)); - var selected = L.extend( - { radius: this.options.radius }, - this._selected && { color: COLOR_SELECTED_PORTAL } - ); + var selected = L.extend({ radius: this.options.radius }, this._selected && { color: window.COLOR_SELECTED_PORTAL }); return L.CircleMarker.prototype.setStyle.call(this, selected); }, + setSelected: function (selected) { - if (selected === false) + if (selected === false) { this._selected = false; - else + } else { this._selected = this._selected || selected; + } this.setMarkerStyle(); - if (this._selected && window.map.hasLayer(this)) + if (this._selected && window.map.hasLayer(this)) { this.bringToFront(); + } }, + _style: function () { var dashArray = null; // dashed outline for placeholder portals - if (this.isPlaceholder()) dashArray = L.PortalMarker.placeholderStyle.dashArray; + if (this.isPlaceholder()) { + dashArray = L.PortalMarker.placeholderStyle.dashArray; + } return L.extend(this._scale(), L.PortalMarker.portalBaseStyle, { - color: COLORS[this._team], - fillColor: COLORS[this._team], - dashArray: dashArray + color: window.COLORS[this._team], + fillColor: window.COLORS[this._team], + dashArray: dashArray, }); }, + _scale: function () { var scale = window.portalMarkerScale(); @@ -262,22 +295,22 @@ window.portalMarkerScale = function () { * @function createMarker * @param {L.LatLng} latlng - The latitude and longitude where the marker will be placed. * @param {Object} data - The IITC-specific entity data to be stored in the marker options. - * @returns {L.circleMarker} A Leaflet circle marker representing the portal. + * @returns {L.PortalMarker} A Leaflet circle marker representing the portal. */ -window.createMarker = function(latlng, data) { +window.createMarker = function (latlng, data) { return new L.PortalMarker(latlng, data); -} +}; /** * Sets the style of a portal marker, including options for when the portal is selected. * * @function setMarkerStyle - * @param {L.circleMarker} marker - The portal marker whose style will be set. + * @param {L.PortalMarker} marker - The portal marker whose style will be set. * @param {boolean} selected - Indicates if the portal is selected. */ -window.setMarkerStyle = function(marker, selected) { +window.setMarkerStyle = function (marker, selected) { marker.setSelected(selected); -} +}; /** * Determines the style options for a portal marker based on its details. From da84f53a01b1ab3f906b930745f454f1b3a4769f Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Tue, 19 Nov 2024 14:39:16 +0100 Subject: [PATCH 38/38] use new IITC.utils API --- core/code/portal_marker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/code/portal_marker.js b/core/code/portal_marker.js index e00bf597f..4a2abf4d9 100644 --- a/core/code/portal_marker.js +++ b/core/code/portal_marker.js @@ -1,4 +1,4 @@ -/* global L, log -- eslint */ +/* global IITC, L, log -- eslint */ /** * @file This file contains the code related to creating and updating portal markers on the map. @@ -168,7 +168,7 @@ L.PortalMarker = L.CircleMarker.extend({ } this._level = parseInt(this._details.level) || 0; - this._team = window.teamStringToId(this._details.team); + this._team = IITC.utils.getTeamId(this._details.team); // the data returns unclaimed portals as level 1 - but IITC wants them treated as level 0 if (this._team === window.TEAM_NONE) {