Skip to content

Commit

Permalink
fix jumpy portals on ghostlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
xscreach committed Jul 12, 2023
1 parent 3134b59 commit 7954251
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
33 changes: 19 additions & 14 deletions core/code/map_data_render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down Expand Up @@ -383,14 +386,15 @@ 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] }; })
};

//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
Expand Down Expand Up @@ -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,
});

Expand All @@ -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],
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/total-conversion-build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
];

Expand Down
25 changes: 18 additions & 7 deletions plugins/debug-raw-portal-data.js
Original file line number Diff line number Diff line change
@@ -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() {};
Expand All @@ -28,10 +36,9 @@ window.plugin.rawdata.showPortalData = function(guid) {

var title = 'Raw portal data: ' + (data.title || '<no title>');

var body =
'<b>Portal GUID</b>: <code>'+guid+'</code><br />' +
'<b>Entity timestamp</b>: <code>'+ts+'</code> - '+window.unixTimeToDateTimeString(ts,true)+'<br />' +
'<b>Portal map data:</b><pre>'+JSON.stringify(data,null,2)+'</pre>';
var body = `<b>Portal GUID</b>: <code>${guid}</code><br />
<b>Entity timestamp</b>: <code>${ts}</code> - ${window.unixTimeToDateTimeString(ts, true)}<br />
<b>Portal map data</b>: <pre>${JSON.stringify(data, null, 2)}</pre>`;

var details = portalDetail.get(guid);
if (details) {
Expand All @@ -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 += '<b>Link GUID</b>: <code>'+l.options.guid+'</code><br /><pre>'+JSON.stringify(ld,null,2)+'</pre>';
body += `<b>Link GUID</b>: <code>${l.options.guid}</code><br />
<b>Entity timestamp</b>: <code>${ld.timestamp}</code> - ${window.unixTimeToDateTimeString(ld.timestamp, true)}<br />
<pre>${JSON.stringify(ld, null, 2)}</pre>`;
haslinks = true;
});

Expand All @@ -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 += '<b>Field guid</b>: <code>'+f.options.guid+'</code><br /><pre>'+JSON.stringify(fd,null,2)+'</pre>';
body += `<b>Field guid</b>: <code>${f.options.guid}</code><br />
<b>Entity timestamp</b>: <code>${fd.timestamp}</code> - ${window.unixTimeToDateTimeString(fd.timestamp, true)}<br />
<pre>${JSON.stringify(fd, null, 2)}</pre>`;
hasfields = true;
});
if (!hasfields) body += '<p>No fields linked to this portal</p>';
Expand Down

0 comments on commit 7954251

Please sign in to comment.