Code restructure

This commit is contained in:
Xelio 2013-02-16 01:16:20 +08:00
parent 1ed2ee8e8c
commit eab812fbf6
3 changed files with 25 additions and 40 deletions

View File

@ -339,26 +339,25 @@ window.renderResonators = function(ent, portalLayer) {
var resoGuid = portalResonatorGuid(ent[0], i);
// the resonator
var reso = L.circleMarker(Rlatlng, {
radius: ent[0] == selectedPortal ? RADIUS_SELECTED_PORTAL_RESONATOR: RADIUS_NON_SELECTED_PORTAL_RESONATOR,
// #AAAAAA outline seems easier to see the fill opacity
color: ent[0] == selectedPortal ? COLOR_SELECTED_PORTAL_RESONATOR : COLOR_NON_SELECTED_PORTAL_RESONATOR,
var resoProperty = $.extend({
opacity: 1,
weight: ent[0] == selectedPortal ? WEIGHT_SELECTED_PORTAL_RESONATOR : WEIGHT_NON_SELECTED_PORTAL_RESONATOR,
fillColor: COLORS_LVL[rdata.level],
fillOpacity: rdata.energyTotal/RESO_NRG[rdata.level],
clickable: false,
guid: resoGuid // need this here as well for add/remove events
});
guid: resoGuid
}, ent[0] == selectedPortal ? OPTIONS_RESONATOR_SELECTED : OPTIONS_RESONATOR_NON_SELECTED);
var reso = L.circleMarker(Rlatlng, resoProperty);
// line connecting reso to portal
var conn = L.polyline([portalLatLng, Rlatlng], {
weight: ent[0] == selectedPortal ? WEIGHT_SELECTED_PORTAL_RESONATOR_LINE : WEIGHT_NON_SELECTED_PORTAL_RESONATOR_LINE,
var connProperty = $.extend({
color: '#FFA000',
opacity: ent[0] == selectedPortal ? OPACITY_SELECTED_PORTAL_RESONATOR_LINE : OPACITY_NON_SELECTED_PORTAL_RESONATOR_LINE,
dashArray: '0,10,8,4,8,4,8,4,8,4,8,4,8,4,8,4,8,4,8,4',
fill: false,
clickable: false});
clickable: false
}, ent[0] == selectedPortal ? OPTIONS_RESONATOR_LINE_SELECTED : OPTIONS_RESONATOR_LINE_NON_SELECTED);
var conn = L.polyline([portalLatLng, Rlatlng], connProperty);
// put both in one group, so they can be handled by the same logic.
@ -413,16 +412,14 @@ window.portalResetColor = function(portal) {
window.resonatorsResetStyle = function(portalGuid) {
for(var i = 0; i < 8; i++) {
resonatorLayerGroup = resonators[portalResonatorGuid(portalGuid, i)];
//console.log('reset:'+i+','+resonatorLayerGroup);
if(!resonatorLayerGroup) continue;
resonatorLayerGroup.eachLayer(function(layer) {
if (layer.options.guid) {
layer.setStyle({color: COLOR_NON_SELECTED_PORTAL_RESONATOR,
radius: RADIUS_NON_SELECTED_PORTAL_RESONATOR,
weight: WEIGHT_NON_SELECTED_PORTAL_RESONATOR});
// Resonator
layer.setStyle(OPTIONS_RESONATOR_NON_SELECTED);
} else {
layer.setStyle({opacity: OPACITY_NON_SELECTED_PORTAL_RESONATOR_LINE,
weight: WEIGHT_NON_SELECTED_PORTAL_RESONATOR_LINE});
// Resonator line
layer.setStyle(OPTIONS_RESONATOR_LINE_NON_SELECTED);
}
});
}
@ -434,12 +431,11 @@ window.resonatorsSetSelectStyle = function(portalGuid) {
if(!resonatorLayerGroup) continue;
resonatorLayerGroup.eachLayer(function(layer) {
if (layer.options.guid) {
layer.bringToFront().setStyle({color: COLOR_SELECTED_PORTAL_RESONATOR,
radius: RADIUS_SELECTED_PORTAL_RESONATOR,
weight: WEIGHT_SELECTED_PORTAL_RESONATOR});
// Resonator
layer.bringToFront().setStyle(OPTIONS_RESONATOR_SELECTED);
} else {
layer.bringToFront().setStyle({opacity: OPACITY_SELECTED_PORTAL_RESONATOR_LINE,
weight: WEIGHT_SELECTED_PORTAL_RESONATOR_LINE});
// Resonator line
layer.bringToFront().setStyle(OPTIONS_RESONATOR_LINE_SELECTED);
}
});
}

View File

@ -109,10 +109,7 @@ window.setPortalIndicators = function(d) {
window.selectPortal = function(guid) {
var update = selectedPortal === guid;
var oldPortal = portals[selectedPortal];
if(!update && oldPortal) {
resonatorsResetStyle(oldPortal.options.guid);
portalResetColor(oldPortal);
}
if(!update && oldPortal) portalResetColor(oldPortal);
selectedPortal = guid;
@ -127,10 +124,7 @@ window.selectPortal = function(guid) {
window.unselectOldPortal = function() {
var oldPortal = portals[selectedPortal];
if(oldPortal) {
resonatorsResetStyle(oldPortal.options.guid);
oldPortal.setStyle({color: oldPortal.options.fillColor});
}
if(oldPortal) portalResetColor(oldPortal);
selectedPortal = null;
$('#portaldetails').html('');
}

15
main.js
View File

@ -146,16 +146,11 @@ window.COLORS = ['#FFCE00', '#0088FF', '#03FE03']; // none, res, enl
window.COLORS_LVL = ['#000', '#FECE5A', '#FFA630', '#FF7315', '#E40000', '#FD2992', '#EB26CD', '#C124E0', '#9627F4'];
window.COLORS_MOD = {VERY_RARE: '#F78AF6', RARE: '#AD8AFF', COMMON: '#84FBBD'};
window.COLOR_SELECTED_PORTAL_RESONATOR = '#FFFFFF';
window.COLOR_NON_SELECTED_PORTAL_RESONATOR = '#AAAAAA';
window.OPACITY_SELECTED_PORTAL_RESONATOR_LINE = 0.7;
window.OPACITY_NON_SELECTED_PORTAL_RESONATOR_LINE = 0.25;
window.RADIUS_SELECTED_PORTAL_RESONATOR = 4;
window.RADIUS_NON_SELECTED_PORTAL_RESONATOR = 3;
window.WEIGHT_SELECTED_PORTAL_RESONATOR_LINE = 3;
window.WEIGHT_NON_SELECTED_PORTAL_RESONATOR_LINE = 2;
window.WEIGHT_SELECTED_PORTAL_RESONATOR = 2;
window.WEIGHT_NON_SELECTED_PORTAL_RESONATOR = 1;
window.OPTIONS_RESONATOR_SELECTED = { color: '#fff', weight: 2, radius: 4};
window.OPTIONS_RESONATOR_NON_SELECTED = { color: '#aaa', weight: 1, radius: 3};
window.OPTIONS_RESONATOR_LINE_SELECTED = {opacity: 0.7, weight: 3};
window.OPTIONS_RESONATOR_LINE_NON_SELECTED = {opacity: 0.25, weight: 2};
// circles around a selected portal that show from where you can hack
// it and how far the portal reaches (i.e. how far links may be made