Portal Highlighter - Initial Check in

This commit is contained in:
vita10gy 2013-04-04 23:08:59 -05:00
parent e396d7df1d
commit d646f2df6b
6 changed files with 235 additions and 19 deletions

View File

@ -149,12 +149,14 @@ window.handlePortalsRender = function(portals) {
// Preserve selectedPortal because it will get lost on re-rendering
// the portal
var oldSelectedPortal = selectedPortal;
runHooks('portalDataLoaded', {portals : portals});
$.each(portals, function(ind, portal) {
//~ if(selectedPortal === portal[0]) portalUpdateAvailable = true;
if(urlPortal && portal[0] === urlPortal) portalInUrlAvailable = true;
renderPortal(portal);
if(window.portals[portal[0]]) {
highlightPortal(window.portals[portal[0]]);
}
renderPortal(portal);
});
// restore selected portal if still available
@ -256,7 +258,7 @@ window.renderPortal = function(ent) {
// do nothing if portal did not change
var layerGroup = portalsLayers[parseInt(portalLevel)];
var old = findEntityInLeaflet(layerGroup, window.portals, ent[0]);
if(old) {
if(!changing_highlighters && old) {
var oo = old.options;
// Default checks to see if a portal needs to be re-rendered
@ -304,6 +306,7 @@ window.renderPortal = function(ent) {
clickable: true,
level: portalLevel,
team: team,
ent: ent,
details: ent[2],
guid: ent[0]});
@ -341,7 +344,7 @@ window.renderPortal = function(ent) {
});
window.renderResonators(ent, null);
highlightPortal(p);
window.runHooks('portalAdded', {portal: p});
p.addTo(layerGroup);
}

View File

@ -0,0 +1,55 @@
// Portal Highlighter //////////////////////////////////////////////////////////
// these functions handle portal highlighters
window._highlighters = null;
window._current_highlighter = localStorage.portal_highlighter;
window.changing_highlighters = false;
window.addPortalHighlighter = function(name, callback) {
console.log("Regisering Portal Highlighter: " + name);
if(_highlighters === null) {
_highlighters = {};
}
_highlighters[name] = callback;
portalHighlighterControl();
}
window.portalHighlighterControl = function() {
if(_highlighters !== null) {
if($('#portal_highlight_select').length === 0) {
$("body").append("<select id='portal_highlight_select'></select>");
}
$("#portal_highlight_select").html('');
$("#portal_highlight_select").append($("<option>").attr('value','No Highlights').text('No Highlights'));
$.each(_highlighters, function(name, callback) {
$("#portal_highlight_select").append($("<option>").attr('value',name).text(name));
});
$("#portal_highlight_select").val(localStorage.portal_highlighter);
$("#portal_highlight_select").change(function(){ changePortalHighlights($(this).val());});
}
}
window.changePortalHighlights = function(name) {
changing_highlighters = true;
_current_highlighter = name;
resetHighlightedPortals();
changing_highlighters = false;
localStorage.portal_highlighter = name;
}
window.highlightPortal = function(p) {
if(_highlighters !== null && _highlighters[_current_highlighter] !== undefined) {
p.options.highligher = _current_highlighter;
_highlighters[_current_highlighter]({portal: p});
}
}
window.resetHighlightedPortals = function() {
$.each(portals, function(ind, portal) {
try {
renderPortal(portal.options.ent);
}
catch(e) {}
});
}

View File

@ -0,0 +1,77 @@
// ==UserScript==
// @id iitc-plugin-highlight-portals-missing-resonators@vita10gy
// @name IITC plugin: highlight portals missing resonators
// @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 denote if the portal is missing resonators.
// @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.portalsMissingResonators = function() {};
window.plugin.portalsMissingResonators.highlight = function(data) {
var d = data.portal.options.details;
var portal_weakness = 0;
if(getTeam(d) !== 0) {
//Ding the portal for every missing resonator.
var resCount = 0;
$.each(d.resonatorArray.resonators, function(ind, reso) {
if(reso === null) {
portal_weakness += .125;
} else {
resCount++;
}
});
if(portal_weakness > 0) {
var fill_opacity = portal_weakness*.85 + .15;
var color = 'red';
fill_opacity = Math.round(fill_opacity*100)/100;
var params = {fillColor: color, fillOpacity: fill_opacity};
if(resCount < 8) {
// Hole per missing resonator
var dash = new Array(8-resCount + 1).join("1,4,") + "100,0"
params["dashArray"] = dash;
}
data.portal.setStyle(params);
} else {
data.portal.setStyle({color: COLORS[getTeam(data.portal.options.details)],
fillOpacity: 0.5,
dashArray: null});
}
}
window.COLOR_SELECTED_PORTAL = '#f0f';
}
var setup = function() {
window.addPortalHighlighter('Portals Missing Resonators', window.plugin.portalsMissingResonators.highlight);
}
// 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);

View File

@ -0,0 +1,81 @@
// ==UserScript==
// @id iitc-plugin-highlight-portals-missing-resonators@vita10gy
// @name IITC plugin: highlight portals missing resonators
// @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 denote if the portal is missing resonators.
// @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.portalHighligherMyPortals = function() {};
window.plugin.portalHighligherMyPortals.highlight = function(data) {
console.log(PLAYER.guid);
var d = data.portal.options.details;
var portal_weakness = 0;
if(getTeam(d) !== 0) {
console.log(d);
//Ding the portal for every missing resonator.
var resCount = 0;
$.each(d.resonatorArray.resonators, function(ind, reso) {
if(reso === null) {
portal_weakness += .125;
} else {
resCount++;
}
});
if(portal_weakness > 0) {
var fill_opacity = portal_weakness*.85 + .15;
var color = 'red';
fill_opacity = Math.round(fill_opacity*100)/100;
var params = {fillColor: color, fillOpacity: fill_opacity};
if(resCount < 8) {
// Hole per missing resonator
var dash = new Array(8-resCount + 1).join("1,4,") + "100,0"
params["dashArray"] = dash;
}
data.portal.setStyle(params);
} else {
data.portal.setStyle({color: COLORS[getTeam(data.portal.options.details)],
fillOpacity: 0.5,
dashArray: null});
}
}
window.COLOR_SELECTED_PORTAL = '#f0f';
}
var setup = function() {
window.addPortalHighlighter('My Portals', window.plugin.portalHighligherMyPortals.highlight);
}
// 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);

View File

@ -22,8 +22,7 @@ if(typeof window.plugin !== 'function') window.plugin = function() {};
// use own namespace for plugin
window.plugin.portalWeakness = function() {};
window.plugin.portalWeakness.portalAdded = function(data) {
window.plugin.portalWeakness.highlightWeakness = function(data) {
var d = data.portal.options.details;
var portal_weakness = 0;
if(getTeam(d) !== 0) {
@ -82,20 +81,11 @@ window.plugin.portalWeakness.portalAdded = function(data) {
dashArray: null});
}
}
}
window.plugin.portalWeakness.portalDataLoaded = function(data) {
$.each(data.portals, function(ind, portal) {
if(window.portals[portal[0]]) {
window.plugin.portalWeakness.portalAdded({portal: window.portals[portal[0]]});
}
});
window.COLOR_SELECTED_PORTAL = '#f0f';
}
var setup = function() {
window.addHook('portalAdded', window.plugin.portalWeakness.portalAdded);
window.addHook('portalDataLoaded', window.plugin.portalWeakness.portalDataLoaded);
window.COLOR_SELECTED_PORTAL = '#f0f';
window.addPortalHighlighter('Portal Weakness', window.plugin.portalWeakness.highlightWeakness);
}
// PLUGIN END //////////////////////////////////////////////////////////

View File

@ -117,7 +117,7 @@ a:hover {
background: rgba(8, 48, 78, 0.9);
position: absolute;
left: 0;
z-index: 3001;
z-index: 99999;
height: 26px;
padding-left:1px;
}
@ -174,7 +174,7 @@ a:hover {
width: 708px;
bottom: 23px;
left: 0;
z-index: 3000;
z-index: 99999;
background: rgba(8, 48, 78, 0.9);
font-size: 12.6px;
color: #eee;
@ -815,3 +815,13 @@ td + td {
.ALIENS {
color: #28f428;
}
#portal_highlight_select{
position: absolute;
top:10px;
left:60px;
z-index: 9999;
font-size:11px;
font-family: "coda",arial,helvetica,sans-serif;
}