diff --git a/core/code/map_data_render.js b/core/code/map_data_render.js index 048fde7e7..12836962a 100644 --- a/core/code/map_data_render.js +++ b/core/code/map_data_render.js @@ -233,23 +233,26 @@ window.Render.prototype.deleteFieldEntity = function(guid) { } -window.Render.prototype.createPlaceholderPortalEntity = function(guid,latE6,lngE6,team) { +window.Render.prototype.createPlaceholderPortalEntity = function (guid, latE6, lngE6, team, timestamp) { // intel no longer returns portals at anything but the closest zoom // stock intel creates 'placeholder' portals from the data in links/fields - IITC needs to do the same // we only have the portal guid, lat/lng coords, and the faction - no other data // having the guid, at least, allows the portal details to be loaded once it's selected. however, // no highlighters, portal level numbers, portal names, useful counts of portals, etc are possible + // zero will mean any other source of portal data will have a higher timestamp + timestamp = timestamp || 0; var ent = [ - guid, //ent[0] = guid - 0, //ent[1] = timestamp - zero will mean any other source of portal data will have a higher timestamp - //ent[2] = an array with the entity data - [ 'p', //0 - a portal - team, //1 - team - latE6, //2 - lat - lngE6 //3 - lng - ] + guid, // ent[0] = guid + timestamp, // ent[1] = timestamp - zero will mean any other source of portal data will have a higher timestamp + // ent[2] = an array with the entity data + [ + 'p', // 0 - a portal + team, // 1 - team + latE6, // 2 - lat + lngE6, // 3 - lng + ], ]; // placeholder portals don't have a useful timestamp value - so the standard code that checks for updated @@ -259,7 +262,7 @@ window.Render.prototype.createPlaceholderPortalEntity = function(guid,latE6,lngE 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) { + if (team !== p.options.data.team && p.options.timestamp < timestamp) { // team - delete existing portal this.deletePortalEntity(guid); } @@ -383,6 +386,7 @@ window.Render.prototype.createFieldEntity = function(ent) { var data = { // type: ent[2][0], + timestamp: ent[1], team: ent[2][1], points: ent[2][2].map(function(arr) { return {guid: arr[0], latE6: arr[1], lngE6: arr[2] }; }) }; @@ -390,7 +394,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); + this.createPlaceholderPortalEntity(p.guid, p.latE6, p.lngE6, data.team, data.timestamp); } // check if entity already exists @@ -423,7 +427,7 @@ window.Render.prototype.createFieldEntity = function(ent) { team: team, ent: ent, // LEGACY - TO BE REMOVED AT SOME POINT! use .guid, .timestamp and .data instead guid: ent[0], - timestamp: ent[1], + timestamp: data.timestamp, data: data, }); @@ -447,6 +451,7 @@ window.Render.prototype.createLinkEntity = function (ent) { var data = { // TODO add other properties and check correction direction // type: ent[2][0], + timestamp: ent[1], team: ent[2][1], oGuid: ent[2][2], oLatE6: ent[2][3], @@ -457,8 +462,8 @@ window.Render.prototype.createLinkEntity = function (ent) { }; // 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); + this.createPlaceholderPortalEntity(data.oGuid, data.oLatE6, data.oLngE6, data.team, data.timestamp); + this.createPlaceholderPortalEntity(data.dGuid, data.dLatE6, data.dLngE6, data.team, data.timestamp); // check if entity already exists diff --git a/core/total-conversion-build.js b/core/total-conversion-build.js index c4b6e208a..d36a13cbe 100644 --- a/core/total-conversion-build.js +++ b/core/total-conversion-build.js @@ -9,7 +9,7 @@ window.script_info = plugin_info; window.script_info.changelog = [ { version: '0.36.0', - changes: ['Ability to define and display changelog'], + changes: ['Ability to define and display changelog', 'Timestamp added to link and field data'], }, ]; diff --git a/plugins/debug-raw-portal-data.js b/plugins/debug-raw-portal-data.js index 15fa51dfc..de3fcee10 100644 --- a/plugins/debug-raw-portal-data.js +++ b/plugins/debug-raw-portal-data.js @@ -1,9 +1,17 @@ // @author jonatkins // @name Debug: Raw portal JSON data // @category Portal Info -// @version 0.2.4 +// @version 0.2.5 // @description Developer debugging aid: Add a link to the portal details to show the raw data of a portal. +/* exported setup, changelog --eslint */ + +var changelog = [ + { + version: '0.2.5', + changes: ['Added human readable timestamp for portal links and fields'], + }, +]; // use own namespace for plugin window.plugin.rawdata = function() {}; @@ -28,10 +36,9 @@ window.plugin.rawdata.showPortalData = function(guid) { var title = 'Raw portal data: ' + (data.title || ''); - var body = - 'Portal GUID: '+guid+'
' + - 'Entity timestamp: '+ts+' - '+window.unixTimeToDateTimeString(ts,true)+'
' + - 'Portal map data:
'+JSON.stringify(data,null,2)+'
'; + var body = `Portal GUID: ${guid}
+ Entity timestamp: ${ts} - ${window.unixTimeToDateTimeString(ts, true)}
+ Portal map data:
${JSON.stringify(data, null, 2)}
`; var details = portalDetail.get(guid); if (details) { @@ -45,7 +52,9 @@ window.plugin.rawdata.showPortalData = function(guid) { $.each(linkGuids.in.concat(linkGuids.out), function(i,lguid) { var l = window.links[lguid]; var ld = l.options.data; - body += 'Link GUID: '+l.options.guid+'
'+JSON.stringify(ld,null,2)+'
'; + body += `Link GUID: ${l.options.guid}
+ Entity timestamp: ${ld.timestamp} - ${window.unixTimeToDateTimeString(ld.timestamp, true)}
+
${JSON.stringify(ld, null, 2)}
`; haslinks = true; }); @@ -57,7 +66,9 @@ window.plugin.rawdata.showPortalData = function(guid) { $.each(fieldGuids, function(i,fguid) { var f = window.fields[fguid]; var fd = f.options.data; - body += 'Field guid: '+f.options.guid+'
'+JSON.stringify(fd,null,2)+'
'; + body += `Field guid: ${f.options.guid}
+ Entity timestamp: ${fd.timestamp} - ${window.unixTimeToDateTimeString(fd.timestamp, true)}
+
${JSON.stringify(fd, null, 2)}
`; hasfields = true; }); if (!hasfields) body += '

No fields linked to this portal

';