Skip to content

Commit

Permalink
better placeholder handling
Browse files Browse the repository at this point in the history
  • Loading branch information
le-jeu committed Feb 17, 2021
1 parent 9323128 commit c4560ee
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions core/code/portal_marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,15 @@ L.PortalMarker = L.CircleMarker.extend({
this.on('contextmenu', handler_portal_contextmenu);
},
willUpdate: function (details) {
// portal location edit
if (this._details.latE6 !== details.latE6 || this._details.lngE6 !== details.lngE6)
// core portal data change
if (this._details.team !== details.team || this._details.latE6 !== details.latE6 || this._details.lngE6 !== details.lngE6)
return true;
// new data
if (this._details.timestamp < details.timestamp)
return true;
// current marker is a placeholder, and details is real data
if (this.isPlaceholder() && details.level !== undefined)
return true;
// even if we get history that was missing ? is it even possible ?
if (this._details.timestamp > details.timestamp)
return false;
Expand All @@ -67,13 +70,23 @@ L.PortalMarker = L.CircleMarker.extend({
return false;
},
updateDetails: function(details) {
// portal has been moved
if (this._details) {
// portal has been moved
if (this._details.latE6 !== details.latE6 || this._details.lngE6 !== details.lngE6)
this.setLatLng(L.latLng(details.latE6/1E6, details.lngE6/1E6));

// we got more details
if (this._details.timestamp == details.timestamp) {
// core data from a placeholder
if (details.level === undefined) {
// if core data changes, all previous details are dropped
if (this._details.team !== details.team) {
// keep history, title, image
details.title = this._details.title;
details.image = this._details.image;
details.history = this._details.history;
this._details = details;
}
} else if (this._details.timestamp == details.timestamp) {
// we got more details
var localThis = this;
["mods", "resonators", "owner", "artifactDetail", "history"].forEach(function (prop) {
if (details[prop]) localThis._details[prop] = details[prop];
Expand Down Expand Up @@ -121,6 +134,9 @@ L.PortalMarker = L.CircleMarker.extend({
getDetails: function () {
return this._details;
},
isPlaceholder: function () {
return this._details.level === undefined;
},
hasFullDetails: function () {
return !!this._details.mods
},
Expand Down

0 comments on commit c4560ee

Please sign in to comment.