placeholder portals created from link ends

surprisingly few issues, but i'm sure quite a few plugins break badly
This commit is contained in:
Jon Atkins 2015-06-28 19:14:17 +01:00
parent 701f09db58
commit 00b546cb98
4 changed files with 60 additions and 44 deletions

View File

@ -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 { return {
// a[0] == type (always 'p') // a[0] == type (always 'p')
team: a[1], team: a[1],
latE6: a[2], latE6: a[2],
lngE6: a[3], lngE6: a[3]
}
};
function summaryPortalData(a) {
return {
level: a[4], level: a[4],
health: a[5], health: a[5],
resCount: a[6], resCount: a[6],
@ -64,10 +70,16 @@
if (a[0] != 'p') throw 'Error: decodeArray.portalSUmmary - not a portal'; if (a[0] != 'p') throw 'Error: decodeArray.portalSUmmary - not a portal';
if (summaryArrayLength===undefined) summaryArrayLength = a.length; if (a.length == 4) {
if (summaryArrayLength!=a.length) console.warn('decodeArray.portalSUmmary: inconsistant map data portal array lengths'); 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) { window.decodeArray.portalDetail = function(a) {
@ -75,12 +87,14 @@
if (a[0] != 'p') throw 'Error: decodeArray.portalDetail - not a portal'; 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 // 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, // to allow for niantic adding new items into the array before the extended details start,
// use the length of the summary array // use the length of the summary array
return $.extend(basePortalData(a),{ return $.extend(corePortalData(a), summaryPortalData(a),{
mods: a[summaryArrayLength+0].map(parseMod), mods: a[summaryArrayLength+0].map(parseMod),
resonators:a[summaryArrayLength+1].map(parseResonator), resonators:a[summaryArrayLength+1].map(parseResonator),
owner: a[summaryArrayLength+2], owner: a[summaryArrayLength+2],

View File

@ -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]); this.deletePortalEntity(ent[0]);
} }
var portalLevel = parseInt(ent[2][4]); var portalLevel = parseInt(ent[2][4])||0;
var team = teamStringToId(ent[2][1]); var team = teamStringToId(ent[2][1]);
// the data returns unclaimed portals as level 1 - but IITC wants them treated as level 0 // the data returns unclaimed portals as level 1 - but IITC wants them treated as level 0
if (team == TEAM_NONE) portalLevel = 0; if (team == TEAM_NONE) portalLevel = 0;
@ -409,6 +409,22 @@ window.Render.prototype.createFieldEntity = function(ent) {
window.Render.prototype.createLinkEntity = function(ent,faked) { window.Render.prototype.createLinkEntity = function(ent,faked) {
this.seenLinksGuid[ent[0]] = true; // flag we've seen it 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 // check if entity already exists
if (ent[0] in window.links) { 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 // 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 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 team = teamStringToId(ent[2][1]);
var latlngs = [ var latlngs = [
L.latLng(data.oLatE6/1E6, data.oLngE6/1E6), L.latLng(data.oLatE6/1E6, data.oLngE6/1E6),
@ -457,14 +462,6 @@ window.Render.prototype.createLinkEntity = function(ent,faked) {
window.links[ent[0]] = poly; window.links[ent[0]] = poly;
linksFactionLayers[poly.options.team].addLayer(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 // add the portal to the visible map layer
window.Render.prototype.addPortalToMapLayer = function(portal) { 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) { window.Render.prototype.removePortalFromMapLayer = function(portal) {
//remove it from the portalsLevels layer //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);
} }

View File

@ -33,6 +33,7 @@ window.ornaments.addPortal = function(portal) {
var size = window.ornaments.OVERLAY_SIZE; var size = window.ornaments.OVERLAY_SIZE;
var latlng = portal.getLatLng(); var latlng = portal.getLatLng();
if (portal.options.data.ornaments) {
window.ornaments._portals[guid] = portal.options.data.ornaments.map(function(ornament) { window.ornaments._portals[guid] = portal.options.data.ornaments.map(function(ornament) {
var icon = L.icon({ var icon = L.icon({
iconUrl: "//commondatastorage.googleapis.com/ingress.com/img/map_icons/marker_images/"+ornament+".png", iconUrl: "//commondatastorage.googleapis.com/ingress.com/img/map_icons/marker_images/"+ornament+".png",
@ -44,6 +45,7 @@ window.ornaments.addPortal = function(portal) {
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) { window.ornaments.removePortal = function(portal) {
var guid = portal.options.guid; var guid = portal.options.guid;

View File

@ -30,9 +30,12 @@ window.setMarkerStyle = function(marker, selected) {
marker.setStyle(styleOptions); marker.setStyle(styleOptions);
// 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 // 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? // the highlighter API would need to be changed for this to be improved though. will it be too slow?
highlightPortal(marker); highlightPortal(marker);
}
if (selected) { if (selected) {
marker.setStyle ({color: COLOR_SELECTED_PORTAL}); 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_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_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 lvlWeight = LEVEL_TO_WEIGHT[level] * Math.sqrt(scale);
var lvlRadius = LEVEL_TO_RADIUS[level] * scale; var lvlRadius = LEVEL_TO_RADIUS[level] * scale;