Merge pull request #532 from Xelio/patch-plugin-ap-list-1
Update Plugin AP List
This commit is contained in:
commit
ba0aebde50
@ -2,7 +2,7 @@
|
|||||||
// @id iitc-plugin-ap-list@xelio
|
// @id iitc-plugin-ap-list@xelio
|
||||||
// @name IITC plugin: AP List
|
// @name IITC plugin: AP List
|
||||||
// @category Info
|
// @category Info
|
||||||
// @version 0.5.6.@@DATETIMEVERSION@@
|
// @version 0.5.7.@@DATETIMEVERSION@@
|
||||||
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
|
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
|
||||||
// @updateURL @@UPDATEURL@@
|
// @updateURL @@UPDATEURL@@
|
||||||
// @downloadURL @@DOWNLOADURL@@
|
// @downloadURL @@DOWNLOADURL@@
|
||||||
@ -252,7 +252,7 @@ window.plugin.apList.updateSortedPortals = function() {
|
|||||||
plugin.apList.sortedPortals[plugin.apList.SIDE_FRIENDLY] = new Array();
|
plugin.apList.sortedPortals[plugin.apList.SIDE_FRIENDLY] = new Array();
|
||||||
plugin.apList.sortedPortals[plugin.apList.SIDE_ENEMY] = 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
|
// If cache is not enabled, empty cachedPortals. In following
|
||||||
// "$.each" loop, the backup portal will copy back into
|
// "$.each" loop, the backup portal will copy back into
|
||||||
// cachedPortals if it exist in "window.portals"" and didn't change.'
|
// cachedPortals if it exist in "window.portals"" and didn't change.'
|
||||||
@ -265,12 +265,15 @@ window.plugin.apList.updateSortedPortals = function() {
|
|||||||
var cachedPortal = oldcachedPortal[key];
|
var cachedPortal = oldcachedPortal[key];
|
||||||
// If portal is changed, update playerApGain with latest
|
// If portal is changed, update playerApGain with latest
|
||||||
// information
|
// information
|
||||||
if(!plugin.apList.isSamePortal(portal,cachedPortal)) {
|
if(!cachedPortal
|
||||||
// Copy portal detail to cachedPortal
|
|| value.timestamp !== cachedPortal.timestamp
|
||||||
|
|| plugin.apList.isFieldsChanged(portal.portalV2.linkedFields, cachedPortal.portalV2.linkedFields)) {
|
||||||
|
// Shallow copy portal detail to cachedPortal
|
||||||
cachedPortal = $.extend({}, portal);
|
cachedPortal = $.extend({}, portal);
|
||||||
var side = plugin.apList.portalSide(portal);
|
var side = plugin.apList.portalSide(portal);
|
||||||
var getApGainFunc = plugin.apList.playerApGainFunc[side];
|
var getApGainFunc = plugin.apList.playerApGainFunc[side];
|
||||||
// Assign playerApGain and guid to cachedPortal
|
// Assign playerApGain and guid to cachedPortal
|
||||||
|
cachedPortal.timestamp = value.timestamp
|
||||||
cachedPortal.playerApGain = getApGainFunc(portal);
|
cachedPortal.playerApGain = getApGainFunc(portal);
|
||||||
cachedPortal.effectiveLevel = plugin.apList.getEffectiveLevel(portal);
|
cachedPortal.effectiveLevel = plugin.apList.getEffectiveLevel(portal);
|
||||||
cachedPortal.guid = value.options.guid;
|
cachedPortal.guid = value.options.guid;
|
||||||
@ -349,7 +352,7 @@ window.plugin.apList.handleDestroyPortal = function() {
|
|||||||
&& newLinkedFields.length === (portal.portalV2.linkedFields || []).length)
|
&& newLinkedFields.length === (portal.portalV2.linkedFields || []).length)
|
||||||
return true;
|
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);
|
var newPortal = $.extend(true, {}, portal);
|
||||||
// Assign new links and fields and calculate new playerApGain
|
// Assign new links and fields and calculate new playerApGain
|
||||||
if(portal.portalV2.linkedEdges) newPortal.portalV2.linkedEdges = newLinkedEdges;
|
if(portal.portalV2.linkedEdges) newPortal.portalV2.linkedEdges = newLinkedEdges;
|
||||||
@ -370,27 +373,9 @@ window.plugin.apList.updateTotalPages = function() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
window.plugin.apList.isSameResonator = function(oldRes, newRes) {
|
window.plugin.apList.isFieldsChanged = function(a,b) {
|
||||||
if(!oldRes && !newRes) return true;
|
// http://stackoverflow.com/questions/1773069/using-jquery-to-compare-two-arrays
|
||||||
if(!oldRes || !newRes) return false;
|
return $(a).not(b).get().length === 0 && $(b).not(a).get().length === 0;;
|
||||||
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) {
|
window.plugin.apList.portalSide = function(portal) {
|
||||||
@ -950,7 +935,7 @@ var setup = function() {
|
|||||||
window.plugin.apList.setupList();
|
window.plugin.apList.setupList();
|
||||||
window.plugin.apList.setupPagination();
|
window.plugin.apList.setupPagination();
|
||||||
window.plugin.apList.setupMapEvent();
|
window.plugin.apList.setupMapEvent();
|
||||||
window.addHook('requestFinished', window.plugin.apList.handleUpdate);
|
window.addHook('mapDataRefreshEnd', window.plugin.apList.handleUpdate);
|
||||||
}
|
}
|
||||||
// PLUGIN END //////////////////////////////////////////////////////////
|
// PLUGIN END //////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user