From 904be9b5b123074d889ea1f99c826362ea5d56b6 Mon Sep 17 00:00:00 2001 From: Pavol Babincak Date: Sat, 9 Feb 2013 17:30:32 +0100 Subject: [PATCH] Display current energy for whole portal --- README.md | 1 + code/portal_detail_display_tools.js | 8 ++++++-- code/portal_info.js | 16 +++++++++++++++- code/utils_misc.js | 4 ++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 62752ef5..023e8b99 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ Contributors [OshiHidra](https://github.com/OshiHidra), [Xelio](https://github.com/Xelio), [ZauberNerd](https://github.com/ZauberNerd) +[Scrool](https://github.com/Scrool) Hacking diff --git a/code/portal_detail_display_tools.js b/code/portal_detail_display_tools.js index c3443d72..1c9df052 100644 --- a/code/portal_detail_display_tools.js +++ b/code/portal_detail_display_tools.js @@ -65,8 +65,12 @@ window.getModDetails = function(d) { } window.getEnergyText = function(d) { - var nrg = getPortalEnergy(d); - return 'energy: ' + (nrg > 1000 ? Math.round(nrg/1000) +' k': nrg); + var currentNrg = getCurrentPortalEnergy(d); + var totalNrg = getTotalPortalEnergy(d); + var inf = currentNrg + ' / ' + totalNrg; + var fill = prettyEnergy(currentNrg) + ' / ' + prettyEnergy(totalNrg) + var meter = 'energy: ' + fill + ''; + return meter; } window.getAvgResoDistText = function(d) { diff --git a/code/portal_info.js b/code/portal_info.js index c75d748d..edf8298d 100644 --- a/code/portal_info.js +++ b/code/portal_info.js @@ -17,7 +17,21 @@ window.getPortalLevel = function(d) { return hasReso ? Math.max(1, lvl/8) : 0; } -window.getPortalEnergy = function(d) { +window.getTotalPortalEnergy = function(d) { + var nrg = 0; + $.each(d.resonatorArray.resonators, function(ind, reso) { + if(!reso) return true; + var level = parseInt(reso.level); + var max = RESO_NRG[level]; + nrg += max; + }); + return nrg; +} + +// For backwards compatibility +window.getPortalEnergy = window.getTotalPortalEnergy; + +window.getCurrentPortalEnergy = function(d) { var nrg = 0; $.each(d.resonatorArray.resonators, function(ind, reso) { if(!reso) return true; diff --git a/code/utils_misc.js b/code/utils_misc.js index 3fca9f17..d74d3bdd 100644 --- a/code/utils_misc.js +++ b/code/utils_misc.js @@ -148,3 +148,7 @@ if (typeof String.prototype.startsWith !== 'function') { return this.slice(0, str.length) === str; }; } + +window.prettyEnergy = function(nrg) { + return nrg> 1000 ? Math.round(nrg/1000) + ' k': nrg; +}