Merge branch 'highlighter' of https://github.com/vita10gy/ingress-intel-total-conversion into highlighter
This commit is contained in:
commit
317bc236c8
@ -5,12 +5,17 @@
|
|||||||
window._highlighters = null;
|
window._highlighters = null;
|
||||||
window._current_highlighter = localStorage.portal_highlighter;
|
window._current_highlighter = localStorage.portal_highlighter;
|
||||||
window.changing_highlighters = false;
|
window.changing_highlighters = false;
|
||||||
|
window._no_highlighter = 'No Highlights';
|
||||||
|
|
||||||
window.addPortalHighlighter = function(name, callback) {
|
window.addPortalHighlighter = function(name, callback) {
|
||||||
if(_highlighters === null) {
|
if(_highlighters === null) {
|
||||||
_highlighters = {};
|
_highlighters = {};
|
||||||
}
|
}
|
||||||
_highlighters[name] = callback;
|
_highlighters[name] = callback;
|
||||||
|
if(localStorage.portal_highlighter === undefined) {
|
||||||
|
_current_highlighter = name;
|
||||||
|
localStorage.portal_highlighter = name;
|
||||||
|
}
|
||||||
portalHighlighterControl();
|
portalHighlighterControl();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,12 +25,16 @@ window.portalHighlighterControl = function() {
|
|||||||
$("body").append("<select id='portal_highlight_select'></select>");
|
$("body").append("<select id='portal_highlight_select'></select>");
|
||||||
}
|
}
|
||||||
$("#portal_highlight_select").html('');
|
$("#portal_highlight_select").html('');
|
||||||
$("#portal_highlight_select").append($("<option>").attr('value','No Highlights').text('No Highlights'));
|
$("#portal_highlight_select").append($("<option>").attr('value',_no_highlighter).text(_no_highlighter));
|
||||||
$.each(_highlighters, function(name, callback) {
|
var h_names = Object.keys(_highlighters).sort();
|
||||||
|
|
||||||
|
$.each(h_names, function(i, name) {
|
||||||
$("#portal_highlight_select").append($("<option>").attr('value',name).text(name));
|
$("#portal_highlight_select").append($("<option>").attr('value',name).text(name));
|
||||||
});
|
});
|
||||||
$("#portal_highlight_select").val(localStorage.portal_highlighter);
|
$("#portal_highlight_select").val(_current_highlighter);
|
||||||
$("#portal_highlight_select").change(function(){ changePortalHighlights($(this).val());});
|
$("#portal_highlight_select").change(function(){ changePortalHighlights($(this).val());});
|
||||||
|
$(".leaflet-top.leaflet-left").css('padding-top','25px');
|
||||||
|
$(".leaflet-control-scale-line").css('margin-top','25px');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,6 +47,7 @@ window.changePortalHighlights = function(name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.highlightPortal = function(p) {
|
window.highlightPortal = function(p) {
|
||||||
|
|
||||||
if(_highlighters !== null && _highlighters[_current_highlighter] !== undefined) {
|
if(_highlighters !== null && _highlighters[_current_highlighter] !== undefined) {
|
||||||
p.options.highligher = _current_highlighter;
|
p.options.highligher = _current_highlighter;
|
||||||
_highlighters[_current_highlighter]({portal: p});
|
_highlighters[_current_highlighter]({portal: p});
|
||||||
|
@ -117,3 +117,43 @@ window.getAttackApGain = function(d) {
|
|||||||
captureAp: captureAp
|
captureAp: captureAp
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//This function will return the potential level a player can upgrade it to
|
||||||
|
window.potentialPortalLevel = function(d) {
|
||||||
|
var current_level = getPortalLevel(d);
|
||||||
|
var potential_level = current_level;
|
||||||
|
|
||||||
|
if(PLAYER.team === d.controllingTeam.team) {
|
||||||
|
var resonators_on_portal = d.resonatorArray.resonators;
|
||||||
|
var resonator_levels = new Array();
|
||||||
|
// figure out how many of each of these resonators can be placed by the player
|
||||||
|
var player_resontators = new Array();
|
||||||
|
for(var i=1;i<=MAX_PORTAL_LEVEL; i++) {
|
||||||
|
player_resontators[i] = i > PLAYER.level ? 0 : MAX_RESO_PER_PLAYER[i];
|
||||||
|
}
|
||||||
|
$.each(resonators_on_portal, function(ind, reso) {
|
||||||
|
if(reso !== null && reso.ownerGuid === window.PLAYER.guid) {
|
||||||
|
player_resontators[reso.level]--;
|
||||||
|
}
|
||||||
|
resonator_levels.push(reso === null ? 0 : reso.level);
|
||||||
|
});
|
||||||
|
|
||||||
|
resonator_levels.sort(function(a, b) {
|
||||||
|
return(a - b);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Max out portal
|
||||||
|
var install_index = 0;
|
||||||
|
for(var i=MAX_PORTAL_LEVEL;i>=1; i--) {
|
||||||
|
for(var install = player_resontators[i]; install>0; install--) {
|
||||||
|
if(resonator_levels[install_index] < i) {
|
||||||
|
resonator_levels[install_index] = i;
|
||||||
|
install_index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//console.log(resonator_levels);
|
||||||
|
potential_level = resonator_levels.reduce(function(a, b) {return a + b;}) / 8;
|
||||||
|
}
|
||||||
|
return(potential_level);
|
||||||
|
}
|
||||||
|
@ -118,3 +118,15 @@ body {
|
|||||||
.leaflet-control-attribution {
|
.leaflet-control-attribution {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#portal_highlight_select{
|
||||||
|
position: absolute;
|
||||||
|
top:42px;
|
||||||
|
left:310px;
|
||||||
|
z-index: 9999;
|
||||||
|
font-size:11px;
|
||||||
|
font-family: "coda",arial,helvetica,sans-serif;
|
||||||
|
background-color:#0E3C46;
|
||||||
|
color:#ffce00;
|
||||||
|
|
||||||
|
}
|
||||||
|
92
plugins/portal-highlighter-can-make-level.user.js
Normal file
92
plugins/portal-highlighter-can-make-level.user.js
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
// ==UserScript==
|
||||||
|
// @id iitc-plugin-highlight-portals-upgrade@vita10gy
|
||||||
|
// @name IITC plugin: highlight portals you can upgrade to a specific level
|
||||||
|
// @version 0.1.0.@@DATETIMEVERSION@@
|
||||||
|
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
|
||||||
|
// @updateURL @@UPDATEURL@@
|
||||||
|
// @downloadURL @@DOWNLOADURL@@
|
||||||
|
// @description [@@BUILDNAME@@-@@BUILDDATE@@] Uses the fill color of the portals to highlight portals you can upgrade to a specific level.
|
||||||
|
// @include https://www.ingress.com/intel*
|
||||||
|
// @include http://www.ingress.com/intel*
|
||||||
|
// @match https://www.ingress.com/intel*
|
||||||
|
// @match http://www.ingress.com/intel*
|
||||||
|
// ==/UserScript==
|
||||||
|
|
||||||
|
function wrapper() {
|
||||||
|
// ensure plugin framework is there, even if iitc is not yet loaded
|
||||||
|
if(typeof window.plugin !== 'function') window.plugin = function() {};
|
||||||
|
|
||||||
|
|
||||||
|
// PLUGIN START ////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
// use own namespace for plugin
|
||||||
|
window.plugin.portalHighligherPortalsCanMakeLevel = function() {};
|
||||||
|
|
||||||
|
window.plugin.portalHighligherPortalsCanMakeLevel.highlight = function(data,highlight_level) {
|
||||||
|
var d = data.portal.options.details;
|
||||||
|
var current_level = Math.floor(getPortalLevel(d));
|
||||||
|
var potential_level = Math.floor(window.potentialPortalLevel(d));
|
||||||
|
var opacity = .7;
|
||||||
|
if( potential_level > current_level && potential_level === highlight_level) {
|
||||||
|
color = 'red';
|
||||||
|
data.portal.setStyle({fillColor: color, fillOpacity: opacity});
|
||||||
|
} else {
|
||||||
|
data.portal.setStyle({color: COLORS[getTeam(data.portal.options.details)],
|
||||||
|
fillOpacity: 0.5});
|
||||||
|
}
|
||||||
|
|
||||||
|
window.COLOR_SELECTED_PORTAL = '#f0f';
|
||||||
|
}
|
||||||
|
|
||||||
|
//determines the level of poral a user can make all on their own
|
||||||
|
window.plugin.portalHighligherPortalsCanMakeLevel.playerCanSoloLevel = function(lvl) {
|
||||||
|
var renators_total = 0;
|
||||||
|
var renators_placed = 0;
|
||||||
|
var resonator_level = PLAYER.level
|
||||||
|
while(renators_placed < 8) {
|
||||||
|
for(var i = 0; i<MAX_RESO_PER_PLAYER[resonator_level]; i++) {
|
||||||
|
if(renators_placed < 8) {
|
||||||
|
renators_total += resonator_level;
|
||||||
|
renators_placed++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resonator_level--;
|
||||||
|
}
|
||||||
|
return(Math.floor(renators_total/8));
|
||||||
|
}
|
||||||
|
window.plugin.portalHighligherPortalsCanMakeLevel.getHighlighter = function(lvl) {
|
||||||
|
return(function(data){
|
||||||
|
window.plugin.portalHighligherPortalsCanMakeLevel.highlight(data,lvl);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var setup = function() {
|
||||||
|
// This is the maximum level of a portal a user can be the "last peice of"
|
||||||
|
// yes, even a level 1 can be the difference in bumping a portal up to level 7
|
||||||
|
var max_can_complete = 7;
|
||||||
|
if(PLAYER.level === 8) {
|
||||||
|
max_can_complete = 8;
|
||||||
|
}
|
||||||
|
// The rational behind the "minimum" level below is that showing a level 7 player, for example, all the portals they can make
|
||||||
|
// a level 5 would be silly, as they can make ANY portal a level 5.
|
||||||
|
for(var ptl_lvl = window.plugin.portalHighligherPortalsCanMakeLevel.playerCanSoloLevel()+1; ptl_lvl<=max_can_complete; ptl_lvl++) {
|
||||||
|
window.addPortalHighlighter('Can Make Level ' + ptl_lvl, window.plugin.portalHighligherPortalsCanMakeLevel.getHighlighter(ptl_lvl));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// PLUGIN END //////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
if(window.iitcLoaded && typeof setup === 'function') {
|
||||||
|
setup();
|
||||||
|
} else {
|
||||||
|
if(window.bootPlugins)
|
||||||
|
window.bootPlugins.push(setup);
|
||||||
|
else
|
||||||
|
window.bootPlugins = [setup];
|
||||||
|
}
|
||||||
|
} // wrapper end
|
||||||
|
// inject code into site context
|
||||||
|
var script = document.createElement('script');
|
||||||
|
script.appendChild(document.createTextNode('('+ wrapper +')();'));
|
||||||
|
(document.body || document.head || document.documentElement).appendChild(script);
|
@ -22,59 +22,16 @@ if(typeof window.plugin !== 'function') window.plugin = function() {};
|
|||||||
// use own namespace for plugin
|
// use own namespace for plugin
|
||||||
window.plugin.portalHighligherPortalsUpgrade = function() {};
|
window.plugin.portalHighligherPortalsUpgrade = function() {};
|
||||||
|
|
||||||
// Make this return 0 if portal can't be upgraded at all
|
|
||||||
// mildly hacky, but then there need not be both "can upgrade period" AND a "ok, to what level?" checks
|
|
||||||
window.plugin.portalHighligherPortalsUpgrade.potentialPortalLevel = function(d) {
|
|
||||||
var potential_level = 0;
|
|
||||||
|
|
||||||
if(PLAYER.team === d.controllingTeam.team) {
|
|
||||||
var current_level = getPortalLevel(d);
|
|
||||||
var resonators_on_portal = d.resonatorArray.resonators;
|
|
||||||
var resonator_levels = new Array();
|
|
||||||
// figure out how many of each of these resonators can be placed by the player
|
|
||||||
var player_resontators = new Array();
|
|
||||||
for(var i=1;i<=MAX_PORTAL_LEVEL; i++) {
|
|
||||||
player_resontators[i] = i > PLAYER.level ? 0 : MAX_RESO_PER_PLAYER[i];
|
|
||||||
}
|
|
||||||
$.each(resonators_on_portal, function(ind, reso) {
|
|
||||||
if(reso !== null && reso.ownerGuid === window.PLAYER.guid) {
|
|
||||||
player_resontators[reso.level]--;
|
|
||||||
}
|
|
||||||
resonator_levels.push(reso === null ? 0 : reso.level);
|
|
||||||
});
|
|
||||||
|
|
||||||
resonator_levels.sort(function(a, b) {
|
|
||||||
return(a - b);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Max out portal
|
|
||||||
var install_index = 0;
|
|
||||||
for(var i=MAX_PORTAL_LEVEL;i>=1; i--) {
|
|
||||||
for(var install = player_resontators[i]; install>0; install--) {
|
|
||||||
if(resonator_levels[install_index] < i) {
|
|
||||||
resonator_levels[install_index] = i;
|
|
||||||
install_index++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//console.log(resonator_levels);
|
|
||||||
var new_level = resonator_levels.reduce(function(a, b) {return a + b;}) / 8;
|
|
||||||
if(new_level != current_level) {
|
|
||||||
potential_level = Math.floor(new_level);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return(potential_level);
|
|
||||||
}
|
|
||||||
|
|
||||||
window.plugin.portalHighligherPortalsUpgrade.highlight = function(data) {
|
window.plugin.portalHighligherPortalsUpgrade.highlight = function(data) {
|
||||||
var d = data.portal.options.details;
|
var d = data.portal.options.details;
|
||||||
var current_level = Math.floor(getPortalLevel(d));
|
var current_level = getPortalLevel(d);
|
||||||
var potential_level = window.plugin.portalHighligherPortalsUpgrade.potentialPortalLevel(d);
|
var potential_level = window.potentialPortalLevel(d);
|
||||||
var player_level = PLAYER.level;
|
var player_level = PLAYER.level;
|
||||||
var opacity = .7;
|
var opacity = .7;
|
||||||
|
|
||||||
if( potential_level > 0) {
|
if( potential_level > current_level) {
|
||||||
|
potential_level = Math.floor(potential_level);
|
||||||
|
current_level = Math.floor(current_level);
|
||||||
//console.log(potential_level + '>' + current_level);
|
//console.log(potential_level + '>' + current_level);
|
||||||
var color = 'yellow';
|
var color = 'yellow';
|
||||||
if(potential_level > current_level) {
|
if(potential_level > current_level) {
|
||||||
|
@ -827,8 +827,8 @@ td + td {
|
|||||||
|
|
||||||
#portal_highlight_select{
|
#portal_highlight_select{
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top:10px;
|
top:5px;
|
||||||
left:70px;
|
left:10px;
|
||||||
z-index: 9999;
|
z-index: 9999;
|
||||||
font-size:11px;
|
font-size:11px;
|
||||||
font-family: "coda",arial,helvetica,sans-serif;
|
font-family: "coda",arial,helvetica,sans-serif;
|
||||||
@ -836,3 +836,5 @@ td + td {
|
|||||||
color:#ffce00;
|
color:#ffce00;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user