From 00b546cb9807f2033178afe0892d65caaab7ce6f Mon Sep 17 00:00:00 2001 From: Jon Atkins Date: Sun, 28 Jun 2015 19:14:17 +0100 Subject: [PATCH] placeholder portals created from link ends surprisingly few issues, but i'm sure quite a few plugins break badly --- code/entity_decode.js | 30 ++++++++++++++++++++-------- code/map_data_render.js | 43 +++++++++++++++++++---------------------- code/ornaments.js | 20 ++++++++++--------- code/portal_marker.js | 11 +++++++---- 4 files changed, 60 insertions(+), 44 deletions(-) diff --git a/code/entity_decode.js b/code/entity_decode.js index 9199d1e6..c6d6dd70 100644 --- a/code/entity_decode.js +++ b/code/entity_decode.js @@ -37,15 +37,21 @@ } - var summaryArrayLength = undefined; + var summaryArrayLength = 14; +//there's also a 'placeholder' portal - generated from the data in links/fields. only has team/lat/lng - function basePortalData(a) { + function corePortalData(a) { return { // a[0] == type (always 'p') team: a[1], latE6: a[2], - lngE6: a[3], + lngE6: a[3] + } + }; + + function summaryPortalData(a) { + return { level: a[4], health: a[5], resCount: a[6], @@ -64,10 +70,16 @@ if (a[0] != 'p') throw 'Error: decodeArray.portalSUmmary - not a portal'; - if (summaryArrayLength===undefined) summaryArrayLength = a.length; - if (summaryArrayLength!=a.length) console.warn('decodeArray.portalSUmmary: inconsistant map data portal array lengths'); + if (a.length == 4) { + return corePortalData(a); + } - return basePortalData(a); + if (a.length != summaryArrayLength) { + console.warn('Portal summary length changed - portal details likely broken!'); + debugger; + } + + return $.extend(corePortalData(a), summaryPortalData(a)); } window.decodeArray.portalDetail = function(a) { @@ -75,12 +87,14 @@ if (a[0] != 'p') throw 'Error: decodeArray.portalDetail - not a portal'; - if (summaryArrayLength===undefined) throw 'Error: decodeArray.portalDetail - not yet seen any portal summary data - cannot decode!'; + + //TODO look at the array values, make a better guess as to which index the mods start at, rather than using the hard-coded summaryArrayLength constant + // the portal details array is just an extension of the portal summary array // to allow for niantic adding new items into the array before the extended details start, // use the length of the summary array - return $.extend(basePortalData(a),{ + return $.extend(corePortalData(a), summaryPortalData(a),{ mods: a[summaryArrayLength+0].map(parseMod), resonators:a[summaryArrayLength+1].map(parseResonator), owner: a[summaryArrayLength+2], diff --git a/code/map_data_render.js b/code/map_data_render.js index e755f7c4..0d46ffc6 100644 --- a/code/map_data_render.js +++ b/code/map_data_render.js @@ -268,7 +268,7 @@ window.Render.prototype.createPlaceholderPortalEntity = function(guid,latE6,lngE ] ]; -// this.createPortalEntity(ent); + this.createPortalEntity(ent); } @@ -296,7 +296,7 @@ window.Render.prototype.createPortalEntity = function(ent) { this.deletePortalEntity(ent[0]); } - var portalLevel = parseInt(ent[2][4]); + var portalLevel = parseInt(ent[2][4])||0; var team = teamStringToId(ent[2][1]); // the data returns unclaimed portals as level 1 - but IITC wants them treated as level 0 if (team == TEAM_NONE) portalLevel = 0; @@ -409,6 +409,22 @@ window.Render.prototype.createFieldEntity = function(ent) { window.Render.prototype.createLinkEntity = function(ent,faked) { this.seenLinksGuid[ent[0]] = true; // flag we've seen it + var data = { // TODO add other properties and check correction direction +// type: ent[2][0], + team: ent[2][1], + oGuid: ent[2][2], + oLatE6: ent[2][3], + oLngE6: ent[2][4], + dGuid: ent[2][5], + dLatE6: ent[2][6], + dLngE6: ent[2][7] + }; + + // create placeholder entities for link start and end points (before checking if the link itself already exists + this.createPlaceholderPortalEntity(data.oGuid, data.oLatE6, data.oLngE6, data.team); + this.createPlaceholderPortalEntity(data.dGuid, data.dLatE6, data.dLngE6, data.team); + + // check if entity already exists if (ent[0] in window.links) { // yes. now, as sometimes links are 'faked', they have incomplete data. if the data we have is better, replace the data @@ -423,17 +439,6 @@ window.Render.prototype.createLinkEntity = function(ent,faked) { this.deleteLinkEntity(ent[0]); // option 2 - for now } - var data = { // TODO add other properties and check correction direction -// type: ent[2][0], - team: ent[2][1], - oGuid: ent[2][2], - oLatE6: ent[2][3], - oLngE6: ent[2][4], - dGuid: ent[2][5], - dLatE6: ent[2][6], - dLngE6: ent[2][7] - }; - var team = teamStringToId(ent[2][1]); var latlngs = [ L.latLng(data.oLatE6/1E6, data.oLngE6/1E6), @@ -457,14 +462,6 @@ window.Render.prototype.createLinkEntity = function(ent,faked) { window.links[ent[0]] = poly; linksFactionLayers[poly.options.team].addLayer(poly); - - - // create placeholder entities for link start and end points - this.createPlaceholderPortalEntity(data.oGuid, data.oLatE6, data.oLngE6, data.team); - this.createPlaceholderPortalEntity(data.dGuid, data.dLatE6, data.dLngE6, data.team); - - - } @@ -485,12 +482,12 @@ window.Render.prototype.rescalePortalMarkers = function() { // add the portal to the visible map layer window.Render.prototype.addPortalToMapLayer = function(portal) { - portalsFactionLayers[parseInt(portal.options.level)][portal.options.team].addLayer(portal); + portalsFactionLayers[parseInt(portal.options.level)||0][portal.options.team].addLayer(portal); } window.Render.prototype.removePortalFromMapLayer = function(portal) { //remove it from the portalsLevels layer - portalsFactionLayers[parseInt(portal.options.level)][portal.options.team].removeLayer(portal); + portalsFactionLayers[parseInt(portal.options.level)||0][portal.options.team].removeLayer(portal); } diff --git a/code/ornaments.js b/code/ornaments.js index efcbdad0..e5b35633 100644 --- a/code/ornaments.js +++ b/code/ornaments.js @@ -33,16 +33,18 @@ window.ornaments.addPortal = function(portal) { var size = window.ornaments.OVERLAY_SIZE; var latlng = portal.getLatLng(); - window.ornaments._portals[guid] = portal.options.data.ornaments.map(function(ornament) { - var icon = L.icon({ - iconUrl: "//commondatastorage.googleapis.com/ingress.com/img/map_icons/marker_images/"+ornament+".png", - iconSize: [size, size], - iconAnchor: [size/2,size/2], - className: 'no-pointer-events' // the clickable: false below still blocks events going through to the svg underneath - }); + if (portal.options.data.ornaments) { + window.ornaments._portals[guid] = portal.options.data.ornaments.map(function(ornament) { + var icon = L.icon({ + iconUrl: "//commondatastorage.googleapis.com/ingress.com/img/map_icons/marker_images/"+ornament+".png", + iconSize: [size, size], + iconAnchor: [size/2,size/2], + className: 'no-pointer-events' // the clickable: false below still blocks events going through to the svg underneath + }); - return L.marker(latlng, {icon: icon, clickable: false, keyboard: false, opacity: window.ornaments.OVERLAY_OPACITY }).addTo(window.ornaments._layer); - }); + return L.marker(latlng, {icon: icon, clickable: false, keyboard: false, opacity: window.ornaments.OVERLAY_OPACITY }).addTo(window.ornaments._layer); + }); + } } window.ornaments.removePortal = function(portal) { diff --git a/code/portal_marker.js b/code/portal_marker.js index 749d5d30..7f208078 100644 --- a/code/portal_marker.js +++ b/code/portal_marker.js @@ -30,9 +30,12 @@ window.setMarkerStyle = function(marker, selected) { 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? - highlightPortal(marker); + // don't run highlighters if we only have placeholder data + if (marker.options.data.level !== undefined) { + // 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? + highlightPortal(marker); + } if (selected) { marker.setStyle ({color: COLOR_SELECTED_PORTAL}); @@ -47,7 +50,7 @@ window.getMarkerStyleOptions = function(details) { 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); + var level = Math.floor(details.level||0); var lvlWeight = LEVEL_TO_WEIGHT[level] * Math.sqrt(scale); var lvlRadius = LEVEL_TO_RADIUS[level] * scale;