From a5523280ad038f30e0835d49e3eba4fcf482dfcf Mon Sep 17 00:00:00 2001 From: Xelio Date: Tue, 3 Sep 2013 21:50:28 +0800 Subject: [PATCH 1/4] Plugin AP List: use timestamp to check update of portal data. --- plugins/ap-list.user.js | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/plugins/ap-list.user.js b/plugins/ap-list.user.js index 31acd249..abc858f9 100644 --- a/plugins/ap-list.user.js +++ b/plugins/ap-list.user.js @@ -2,7 +2,7 @@ // @id iitc-plugin-ap-list@xelio // @name IITC plugin: AP List // @category Info -// @version 0.5.6.@@DATETIMEVERSION@@ +// @version 0.5.7.@@DATETIMEVERSION@@ // @namespace https://github.com/jonatkins/ingress-intel-total-conversion // @updateURL @@UPDATEURL@@ // @downloadURL @@DOWNLOADURL@@ @@ -268,12 +268,13 @@ window.plugin.apList.updateSortedPortals = function() { var cachedPortal = oldcachedPortal[key]; // If portal is changed, update playerApGain with latest // information - if(!plugin.apList.isSamePortal(portal,cachedPortal)) { + if(!cachedPortal || value.timestamp !== cachedPortal.timestamp) { // Copy portal detail to cachedPortal cachedPortal = $.extend({}, portal); var side = plugin.apList.portalSide(portal); var getApGainFunc = plugin.apList.playerApGainFunc[side]; // Assign playerApGain and guid to cachedPortal + cachedPortal.timestamp = value.timestamp cachedPortal.playerApGain = getApGainFunc(portal); cachedPortal.effectiveLevel = plugin.apList.getEffectiveLevel(portal); cachedPortal.guid = value.options.guid; @@ -373,29 +374,6 @@ window.plugin.apList.updateTotalPages = function() { }); } -window.plugin.apList.isSameResonator = function(oldRes, newRes) { - if(!oldRes && !newRes) return true; - if(!oldRes || !newRes) return false; - if(typeof oldRes !== typeof newRes) return false; - if(oldRes.level !== newRes.level) return false; - if(oldRes.energyTotal !== newRes.energyTotal) return false; - if(oldRes.distanceToPortal !== newRes.distanceToPortal) return false; - return true; -} - - -window.plugin.apList.isSamePortal = function(a,b) { - - if(!a || !b) return false; - if(a.team !== b.team) return false; - if(a.level !== b.level) return false; - for(var i = 0; i < 8; i++) { - if(!plugin.apList.isSameResonator(a.resonatorArray.resonators[i],b.resonatorArray.resonators[i])) - return false; - } - return true; -} - window.plugin.apList.portalSide = function(portal) { return (portal.controllingTeam.team === PLAYER.team || portal.controllingTeam.team === 'NEUTRAL') From 05cd054d507c00fa2b81396b9069302ad6c9eb7e Mon Sep 17 00:00:00 2001 From: Xelio Date: Tue, 3 Sep 2013 21:52:48 +0800 Subject: [PATCH 2/4] Plugin AP List: Change entry hook to mapDataRefreshEnd --- plugins/ap-list.user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/ap-list.user.js b/plugins/ap-list.user.js index abc858f9..afc1fbe2 100644 --- a/plugins/ap-list.user.js +++ b/plugins/ap-list.user.js @@ -931,7 +931,7 @@ var setup = function() { window.plugin.apList.setupList(); window.plugin.apList.setupPagination(); window.plugin.apList.setupMapEvent(); - window.addHook('requestFinished', window.plugin.apList.handleUpdate); + window.addHook('mapDataRefreshEnd', window.plugin.apList.handleUpdate); } // PLUGIN END ////////////////////////////////////////////////////////// From cf985d872e27c19926a8c3ca64a0f5b2d2338793 Mon Sep 17 00:00:00 2001 From: Xelio Date: Tue, 3 Sep 2013 22:02:06 +0800 Subject: [PATCH 3/4] Plugin AP List: add comments --- plugins/ap-list.user.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/ap-list.user.js b/plugins/ap-list.user.js index afc1fbe2..02fa580b 100644 --- a/plugins/ap-list.user.js +++ b/plugins/ap-list.user.js @@ -252,7 +252,7 @@ window.plugin.apList.updateSortedPortals = function() { plugin.apList.sortedPortals[plugin.apList.SIDE_FRIENDLY] = new Array(); plugin.apList.sortedPortals[plugin.apList.SIDE_ENEMY] = new Array(); - // Make a backup of cachedPortals + // Make a backup of cachedPortals with shallow copy // If cache is not enabled, empty cachedPortals. In following // "$.each" loop, the backup portal will copy back into // cachedPortals if it exist in "window.portals"" and didn't change.' @@ -269,7 +269,7 @@ window.plugin.apList.updateSortedPortals = function() { // If portal is changed, update playerApGain with latest // information if(!cachedPortal || value.timestamp !== cachedPortal.timestamp) { - // Copy portal detail to cachedPortal + // Shallow copy portal detail to cachedPortal cachedPortal = $.extend({}, portal); var side = plugin.apList.portalSide(portal); var getApGainFunc = plugin.apList.playerApGainFunc[side]; @@ -353,7 +353,7 @@ window.plugin.apList.handleDestroyPortal = function() { && newLinkedFields.length === (portal.portalV2.linkedFields || []).length) return true; - // Clone the portal to avoid modifying original data in cachedPortal + // Clone the portal with deep copy to avoid modifying original data in cachedPortal var newPortal = $.extend(true, {}, portal); // Assign new links and fields and calculate new playerApGain if(portal.portalV2.linkedEdges) newPortal.portalV2.linkedEdges = newLinkedEdges; From 27aa405c9c4e77416693bc35c67c569590f19161 Mon Sep 17 00:00:00 2001 From: Xelio Date: Wed, 4 Sep 2013 00:03:28 +0800 Subject: [PATCH 4/4] Plugin AP List: add checking for changing in fields --- plugins/ap-list.user.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/ap-list.user.js b/plugins/ap-list.user.js index 02fa580b..77b183af 100644 --- a/plugins/ap-list.user.js +++ b/plugins/ap-list.user.js @@ -268,7 +268,9 @@ window.plugin.apList.updateSortedPortals = function() { var cachedPortal = oldcachedPortal[key]; // If portal is changed, update playerApGain with latest // information - if(!cachedPortal || value.timestamp !== cachedPortal.timestamp) { + if(!cachedPortal + || value.timestamp !== cachedPortal.timestamp + || plugin.apList.isFieldsChanged(portal.portalV2.linkedFields, cachedPortal.portalV2.linkedFields)) { // Shallow copy portal detail to cachedPortal cachedPortal = $.extend({}, portal); var side = plugin.apList.portalSide(portal); @@ -374,6 +376,11 @@ window.plugin.apList.updateTotalPages = function() { }); } +window.plugin.apList.isFieldsChanged = function(a,b) { + // http://stackoverflow.com/questions/1773069/using-jquery-to-compare-two-arrays + return $(a).not(b).get().length === 0 && $(b).not(a).get().length === 0;; +} + window.plugin.apList.portalSide = function(portal) { return (portal.controllingTeam.team === PLAYER.team || portal.controllingTeam.team === 'NEUTRAL')