Skip to content

Commit

Permalink
implement new portal data check in marker
Browse files Browse the repository at this point in the history
  • Loading branch information
le-jeu committed May 6, 2021
1 parent 43eb5ba commit 8927451
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 24 deletions.
33 changes: 12 additions & 21 deletions core/code/map_data_render.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,42 +286,33 @@ window.Render.prototype.createPortalEntity = function(ent, details) { // details
var data = 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
var 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[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);
Expand Down
45 changes: 42 additions & 3 deletions core/code/portal_marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,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 = teamStringToId(details.team);
Expand Down

0 comments on commit 8927451

Please sign in to comment.