fix resonator handling when less than 8 are provided - we can't work out which is in which slot any more

and silly mistake in last night's quick fix for the 8 slot case
This commit is contained in:
Jon Atkins 2014-05-25 01:11:14 +01:00
parent 4e38518e67
commit 79b3782e97
2 changed files with 57 additions and 38 deletions

View File

@ -159,27 +159,40 @@ window.getResonatorDetails = function(d) {
var resoDetails = []; var resoDetails = [];
// octant=slot: 0=E, 1=NE, 2=N, 3=NW, 4=W, 5=SW, 6=S, SE=7 // octant=slot: 0=E, 1=NE, 2=N, 3=NW, 4=W, 5=SW, 6=S, SE=7
// resos in the display should be ordered like this: // resos in the display should be ordered like this:
// N NE Since the view is displayed in columns, they // N NE Since the view is displayed in rows, they
// NW E need to be ordered like this: N, NW, W, SW, NE, // NW E need to be ordered like this: N NE NW E W SE SW S
// W SE E, SE, S, i.e. 2 3 4 5 1 0 7 6 // W SE i.e. 2 1 3 0 4 7 5 6
// SW S // SW S
// note: as of 2014-05-23 update, this is not true for portals with empty slots!
$.each([2, 1, 3, 0, 4, 7, 5, 6], function(ind, slot) { var processResonatorSlot = function(reso,slot) {
var reso = d.resonators[slot]; var lvl=0, nrg=0, owner=null;
if(!reso) {
resoDetails.push(renderResonatorDetails(slot, 0, 0, null, null)); if (reso) {
return true; lvl = parseInt(reso.level);
nrg = parseInt(reso.energy);
owner = reso.owner;
} }
var l = parseInt(reso.level); resoDetails.push(renderResonatorDetails(slot, lvl, nrg, owner));
var v = parseInt(reso.energy); };
var nick = reso.owner;
// if array order and slot order drift apart, at least the octant
// naming will still be correct. // if all 8 resonators are deployed, we know which is in which slot
slot = ind;
if (d.resonators.length == 8) {
// fully deployed - we can make assumptions about deployment slots
$.each([2, 1, 3, 0, 4, 7, 5, 6], function(ind, slot) {
processResonatorSlot(d.resonators[slot],slot);
});
} else {
// partially deployed portal - we can no longer find out which resonator is in which slot
for(var ind=0; ind<8; ind++) {
processResonatorSlot(ind < d.resonators.length ? d.resonators[ind] : null, null);
}
}
resoDetails.push(renderResonatorDetails(slot, l, v, null, nick));
});
return '<table id="resodetails">' + genFourColumnTable(resoDetails) + '</table>'; return '<table id="resodetails">' + genFourColumnTable(resoDetails) + '</table>';
} }
@ -188,33 +201,31 @@ window.getResonatorDetails = function(d) {
// not work with raw details-hash. Needs digested infos instead: // not work with raw details-hash. Needs digested infos instead:
// slot: which slot this resonator occupies. Starts with 0 (east) and // slot: which slot this resonator occupies. Starts with 0 (east) and
// rotates clockwise. So, last one is 7 (southeast). // rotates clockwise. So, last one is 7 (southeast).
window.renderResonatorDetails = function(slot, level, nrg, dist, nick) { window.renderResonatorDetails = function(slot, level, nrg, nick) {
if(OCTANTS[slot] === 'N') if(OCTANTS[slot] === 'N')
var className = 'meter north'; var className = 'meter north';
else else
var className = 'meter'; var className = 'meter';
if(level === 0) { var max = RESO_NRG[level];
var meter = '<span class="' + className + '" title="octant:\t' + OCTANTS[slot] + ' ' + OCTANTS_ARROW[slot] + '"></span>'; var fillGrade = level > 0 ? nrg/max*100 : 0;
} else {
var max = RESO_NRG[level];
var fillGrade = nrg/max*100;
var inf = 'energy:\t' + nrg + ' / ' + max + ' (' + Math.round(fillGrade) + '%)\n' var inf = (level > 0 ? 'energy:\t' + nrg + ' / ' + max + ' (' + Math.round(fillGrade) + '%)\n'
+ 'level:\t' + level + '\n' +'level:\t' + level + '\n'
+ 'owner:\t' + nick + '\n' +'owner:\t' + nick + '\n'
+ 'octant:\t' + OCTANTS[slot] + ' ' + OCTANTS_ARROW[slot]; : '')
+ (slot !== null ? 'octant:\t' + OCTANTS[slot] + ' ' + OCTANTS_ARROW[slot]:'');
var style = 'width:'+fillGrade+'%; background:'+COLORS_LVL[level]+';'; var style = fillGrade ? 'width:'+fillGrade+'%; background:'+COLORS_LVL[level]+';':'';
var color = (level < 3 ? "#9900FF" : "#FFFFFF"); var color = (level < 3 ? "#9900FF" : "#FFFFFF");
var lbar = '<span class="meter-level" style="color: ' + color + ';"> L ' + level + ' </span>'; var lbar = level > 0 ? '<span class="meter-level" style="color: ' + color + ';"> L ' + level + ' </span>' : '';
var fill = '<span style="'+style+'"></span>'; var fill = '<span style="'+style+'"></span>';
var meter = '<span class="' + className + '" title="'+inf+'">' + fill + lbar + '</span>';
var meter = '<span class="' + className + '" title="'+inf+'">' + fill + lbar + '</span>';
}
nick = nick ? '<span class="nickname">'+nick+'</span>' : null; nick = nick ? '<span class="nickname">'+nick+'</span>' : null;
return [meter, nick || '']; return [meter, nick || ''];
} }

View File

@ -90,26 +90,34 @@ window.smartphoneInfo = function(data) {
if(details) { if(details) {
var l,v,max,perc; var l,v,max,perc;
for(var i=0;i<8;i++) var eastAnticlockwiseToNorthClockwise = [2,1,0,7,6,5,4,3];
for(var ind=0;ind<8;ind++)
{ {
if (details.resonators.length == 8) {
var slot = eastAnticlockwiseToNorthClockwise[ind];
var reso = details.resonators[slot];
} else {
var slot = null;
var reso = ind < details.resonators.length ? details.resonators[ind] : null;
}
var className = TEAM_TO_CSS[getTeam(details)]; var className = TEAM_TO_CSS[getTeam(details)];
if(OCTANTS[i] === 'N') if(slot !== null && OCTANTS[slot] === 'N')
className += ' north' className += ' north'
var reso = details.resonators[i];
if(reso) { if(reso) {
l = parseInt(reso.level); l = parseInt(reso.level);
v = parseInt(reso.energy); v = parseInt(reso.energy);
max = RESO_NRG[l]; max = RESO_NRG[l];
perc = v/max*100; perc = v/max*100;
} } else {
else {
l = 0; l = 0;
v = 0; v = 0;
max = 0; max = 0;
perc = 0; perc = 0;
} }
t += '<div class="resonator '+className+'" style="border-top-color: '+COLORS_LVL[l]+';left: '+(100*i/8.0)+'%;">'; t += '<div class="resonator '+className+'" style="border-top-color: '+COLORS_LVL[l]+';left: '+(100*ind/8.0)+'%;">';
t += '<div class="filllevel" style="width:'+perc+'%;"></div>'; t += '<div class="filllevel" style="width:'+perc+'%;"></div>';
t += '</div>' t += '</div>'
} }