From 322009944911d08187954d66a3968b9e5757fc5b Mon Sep 17 00:00:00 2001 From: Xelio Date: Mon, 25 Mar 2013 01:58:38 +0800 Subject: [PATCH] Plugin AP List: Add comments and reordering code --- plugins/ap-list.user.js | 74 +++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/plugins/ap-list.user.js b/plugins/ap-list.user.js index 52cf1dd7..1caeafbd 100644 --- a/plugins/ap-list.user.js +++ b/plugins/ap-list.user.js @@ -44,13 +44,15 @@ window.plugin.apList.destroyPortalsGuid = new Array(); window.plugin.apList.portalLocationIndicator; window.plugin.apList.animTimeout; - +// ENTRY POINT /////////////////////////////////////////////////////////////////// window.plugin.apList.handleUpdate = function() { if(!requests.isLastRequest('getThinnedEntitiesV2')) return; plugin.apList.updateSortedPortals(); plugin.apList.updatePortalTable(plugin.apList.displaySide); } +// CONTENT GENERATION //////////////////////////////////////////////////////////// + // Generate html table from top portals window.plugin.apList.updatePortalTable = function(side) { var table = '' @@ -116,25 +118,7 @@ window.plugin.apList.getPortalDestroyCheckbox = function(portal) { return div; } -window.plugin.apList.destroyPortal = function(guid) { - // Add to destroyPortalsGuid if not yet added, remove if already added - var portalIndex = plugin.apList.destroyPortalIndex(guid); - if(portalIndex >= 0) { - plugin.apList.destroyPortalsGuid.splice(portalIndex, 1); - } else { - plugin.apList.destroyPortalsGuid.push(guid); - } - - plugin.apList.updateSortedPortals(); - plugin.apList.updatePortalTable(plugin.apList.displaySide); -} - -// Return the index of portal in destroyPortalsGuid -window.plugin.apList.destroyPortalIndex = function(guid) { - return $.inArray(guid, plugin.apList.destroyPortalsGuid); -} - -// Combine title and test +// Combine ap title and test window.plugin.apList.getPortalApText = function(portal) { var title = plugin.apList.getPortalApTitle(portal); return '
' + digits(portal.playerApGain.totalAp) + '
'; @@ -210,6 +194,8 @@ window.plugin.apList.getPortalLink = function(portal) { return div; } +// MAIN LOGIC FUNCTIONS ////////////////////////////////////////////////////////// + // Loop through portals and get playerApGain, then put in sortedPortals by side and sort them by AP. window.plugin.apList.updateSortedPortals = function() { plugin.apList.sortedPortals[plugin.apList.SIDE_FRIENDLY] = new Array(); @@ -331,19 +317,6 @@ window.plugin.apList.handleDestroyPortal = function() { }); } -window.plugin.apList.enableCache = function() { - plugin.apList.useCachedPortals = true; - plugin.apList.updateSortedPortals(); - plugin.apList.updatePortalTable(plugin.apList.displaySide); -} - -window.plugin.apList.disableCache = function() { - plugin.apList.useCachedPortals = false; - plugin.apList.cachedPortals = {}; - plugin.apList.updateSortedPortals(); - plugin.apList.updatePortalTable(plugin.apList.displaySide); -} - window.plugin.apList.isSamePortal = function(a,b) { if(!a || !b) return false; if(a.team !== b.team) return false; @@ -548,6 +521,21 @@ window.plugin.apList.getShieldsMitigation = function(portal) { return shieldsMitigation; } +// FEATURE TOGGLES AND INTERACTION HANDLER /////////////////////////////////////// + +window.plugin.apList.enableCache = function() { + plugin.apList.useCachedPortals = true; + plugin.apList.updateSortedPortals(); + plugin.apList.updatePortalTable(plugin.apList.displaySide); +} + +window.plugin.apList.disableCache = function() { + plugin.apList.useCachedPortals = false; + plugin.apList.cachedPortals = {}; + plugin.apList.updateSortedPortals(); + plugin.apList.updatePortalTable(plugin.apList.displaySide); +} + window.plugin.apList.selectPortal = function(guid) { renderPortalDetails(guid); plugin.apList.setPortalLocationIndicator(guid); @@ -592,6 +580,24 @@ window.plugin.apList.animPortalLocationIndicator = function() { } } +window.plugin.apList.destroyPortal = function(guid) { + // Add to destroyPortalsGuid if not yet added, remove if already added + var portalIndex = plugin.apList.destroyPortalIndex(guid); + if(portalIndex >= 0) { + plugin.apList.destroyPortalsGuid.splice(portalIndex, 1); + } else { + plugin.apList.destroyPortalsGuid.push(guid); + } + + plugin.apList.updateSortedPortals(); + plugin.apList.updatePortalTable(plugin.apList.displaySide); +} + +// Return the index of portal in destroyPortalsGuid +window.plugin.apList.destroyPortalIndex = function(guid) { + return $.inArray(guid, plugin.apList.destroyPortalsGuid); +} + // Change display table to friendly portals window.plugin.apList.displayFriendly = function() { plugin.apList.changeDisplaySide(plugin.apList.SIDE_FRIENDLY); @@ -631,6 +637,8 @@ window.plugin.apList.showReloadLabel = function() { $('#ap-list-reload').show(); } +// SETUP ///////////////////////////////////////////////////////////////////////// + window.plugin.apList.setupVar = function() { plugin.apList.sides[plugin.apList.SIDE_FRIENDLY] = plugin.apList.SIDE_FRIENDLY; plugin.apList.sides[plugin.apList.SIDE_ENEMY] = plugin.apList.SIDE_ENEMY;