From 52306b033de33adb4dca0370789e9f932e6ace38 Mon Sep 17 00:00:00 2001 From: Stefan Breunig Date: Tue, 12 Feb 2013 09:20:08 +0100 Subject: [PATCH 01/15] fix indenting --- code/chat.js | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/code/chat.js b/code/chat.js index 77969845..11b116e9 100644 --- a/code/chat.js +++ b/code/chat.js @@ -636,27 +636,24 @@ window.chat.setupTime = function() { window.chat.setupPosting = function() { $('#chatinput input').keydown(function(event) { -try{ - - var kc = (event.keyCode ? event.keyCode : event.which); - if(kc === 13) { // enter - chat.postMsg(); - event.preventDefault(); - } else if (kc === 9) { // tab - event.preventDefault(); - window.chat.handleTabCompletion(); + try { + var kc = (event.keyCode ? event.keyCode : event.which); + if(kc === 13) { // enter + chat.postMsg(); + event.preventDefault(); + } else if (kc === 9) { // tab + event.preventDefault(); + window.chat.handleTabCompletion(); + } + } catch(error) { + console.log(error); + debug.printStackTrace(); } - - -} catch(error) { - console.log(error); - debug.printStackTrace(); -} }); $('#chatinput').submit(function(event) { - chat.postMsg(); event.preventDefault(); + chat.postMsg(); }); } From 331d9a378198881dcd8c07163be2353d41febe4c Mon Sep 17 00:00:00 2001 From: Stefan Breunig Date: Tue, 12 Feb 2013 10:01:21 +0100 Subject: [PATCH 02/15] add debugging/console capability to devices where it is not available or easily accessibile --- code/boot.js | 2 ++ code/chat.js | 16 ++++++++++-- code/debugging.js | 65 +++++++++++++++++++++++++++++++++++++++++++++++ style.css | 1 + 4 files changed, 82 insertions(+), 2 deletions(-) diff --git a/code/boot.js b/code/boot.js index f27ec694..3f90fb63 100644 --- a/code/boot.js +++ b/code/boot.js @@ -193,6 +193,8 @@ window.setupSidebarToggle = function() { // BOOTING /////////////////////////////////////////////////////////// function boot() { + window.debug.console.overwriteNativeIfRequired(); + console.log('loading done, booting'); window.setupStyles(); window.setupMap(); diff --git a/code/chat.js b/code/chat.js index 11b116e9..7b091552 100644 --- a/code/chat.js +++ b/code/chat.js @@ -496,8 +496,12 @@ window.chat.request = function() { window.chat.needMoreMessages = function() { var activeChat = $('#chat > :visible'); if(scrollBottom(activeChat) !== 0 || activeChat.scrollTop() !== 0) return; + var activeTab = $('#chatcontrols .active').text(); + if(activeTab === 'debug') return; + console.log('no scrollbar in active chat, requesting more msgs'); - if($('#chatcontrols a:last.active').length) + + if(activeTab === 'faction') chat.requestOldFaction(); else chat.requestOldPublic(); @@ -507,6 +511,7 @@ window.chat.needMoreMessages = function() { window.chat.chooser = function(event) { var t = $(event.target); var tt = t.text(); + var span = $('#chatinput span'); $('#chatcontrols .active').removeClass('active'); @@ -537,6 +542,8 @@ window.chat.chooser = function(event) { break; } + if(!elm) throw('chat button handled by chat.chooser, yet it is null'); + elm.show(); if(elm.data('needsScrollTop')) { elm.data('ignoreNextScroll', true); @@ -580,7 +587,10 @@ window.chat.setup = function() { $('#chatcontrols, #chat, #chatinput').show(); $('#chatcontrols a:first').click(window.chat.toggle); - $('#chatcontrols a:not(:first)').click(window.chat.chooser); + $('#chatcontrols a').each(function(ind, elm) { + if($.inArray($(elm).text(), ['automated', 'public', 'faction']) !== -1) + $(elm).click(window.chat.chooser); + }); $('#chatinput').click(function() { @@ -665,6 +675,8 @@ window.chat.postMsg = function() { var msg = $.trim($('#chatinput input').val()); if(!msg || msg === '') return; + if(c === 'debug') return new Function (msg)(); + var public = c === 'public'; var latlng = map.getCenter(); diff --git a/code/debugging.js b/code/debugging.js index 0a3ce734..b3f12ecc 100644 --- a/code/debugging.js +++ b/code/debugging.js @@ -42,3 +42,68 @@ window.debug.forceSync = function() { updateGameScore(); requestData(); } + +window.debug.console = function() { + $('#debugconsole').text(); +} + +window.debug.console.create = function() { + if($('#debugconsole').length) return; + $('#chatcontrols').append('debug'); + $('#chatcontrols a:last').click(function() { + $('#chatinput span').css('cssText', 'color: #bbb !important').text('debug:'); + $('#chat > div').hide(); + $('#debugconsole').show(); + $('#chatcontrols .active').removeClass('active'); + $(this).addClass('active'); + }); + $('#chat').append(''); +} + +window.debug.console.renderLine = function(text, errorType) { + debug.console.create(); + switch(errorType) { + case 'error': var color = '#FF424D'; break; + case 'warning': var color = '#FFDE42'; break; + case 'alert': var color = '#42FF90'; break; + default: var color = '#eee'; + } + if(typeof text !== 'string' && typeof text !== 'number') text = JSON.stringify(text); + var d = new Date(); + var ta = d.toLocaleTimeString(); // print line instead maybe? + var tb = d.toLocaleString(); + var t = ''; + var s = 'style="color:'+color+'"'; + var l = '

'+t+''+errorType+''+text+'

'; + $('#debugconsole').prepend(l); +} + +window.debug.console.log = function(text) { + debug.console.renderLine(text, 'notice'); +} + +window.debug.console.warn = function(text) { + debug.console.renderLine(text, 'warning'); +} + +window.debug.console.error = function(text) { + debug.console.renderLine(text, 'error'); +} + +window.debug.console.alert = function(text) { + debug.console.renderLine(text, 'alert'); +} + +window.debug.console.overwriteNative = function() { + window.debug.console.create(); + window.console = function() {} + window.console.log = window.debug.console.log; + window.console.warn = window.debug.console.warn; + window.console.error = window.debug.console.error; + window.alert = window.debug.console.alert; +} + +window.debug.console.overwriteNativeIfRequired = function() { + if(!window.console || L.Browser.mobile) + window.debug.console.overwriteNative(); +} diff --git a/style.css b/style.css index 652db7a3..03492dc4 100644 --- a/style.css +++ b/style.css @@ -224,6 +224,7 @@ time { display: inline-block; width: 44px; color: #bbb; + overflow: hidden; } mark { From 6edf2210f849969b1924423640c4c83020deb962 Mon Sep 17 00:00:00 2001 From: Stefan Breunig Date: Tue, 12 Feb 2013 11:54:58 +0100 Subject: [PATCH 03/15] add example for decay message JSON (see #137) --- json_examples/chat_public_decay_msg.js | 49 ++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 json_examples/chat_public_decay_msg.js diff --git a/json_examples/chat_public_decay_msg.js b/json_examples/chat_public_decay_msg.js new file mode 100644 index 00000000..d7366372 --- /dev/null +++ b/json_examples/chat_public_decay_msg.js @@ -0,0 +1,49 @@ +[ + "431a30b634394956a16e62954222a37d.d", + 1360634878999, + { + "plext": { + "text": "Control Field @In the fishing village ( Lomse (Oktyabr'skaya ulitsa, 1, Kaliningrad, Kaliningrad Oblast, Russia) has decayed -108 MUs", + "markup": [ + [ + "TEXT", + { + "plain": "Control Field @" + } + ], + [ + "PORTAL", + { + "name": "In the fishing village ( Lomse", + "plain": "In the fishing village ( Lomse (Oktyabr'skaya ulitsa, 1, Kaliningrad, Kaliningrad Oblast, Russia)", + "team": "ALIENS", + "latE6": 54705182, + "address": "Oktyabr'skaya ulitsa, 1, Kaliningrad, Kaliningrad Oblast, Russia", + "lngE6": 20514959, + "guid": "6af16d09fb574c989b7fa09e718585a7.12" + } + ], + [ + "TEXT", + { + "plain": " has decayed -" + } + ], + [ + "TEXT", + { + "plain": "108" + } + ], + [ + "TEXT", + { + "plain": " MUs" + } + ] + ], + "plextType": "SYSTEM_BROADCAST", + "team": "NEUTRAL" + } + } +] From 10da1dee8348160094b241fcc3f60584559971d6 Mon Sep 17 00:00:00 2001 From: saithis Date: Tue, 12 Feb 2013 19:34:16 +0100 Subject: [PATCH 04/15] Added jQuery UI tooltips --- code/boot.js | 56 +++++++++++++++++++++++++++-- code/chat.js | 6 ++-- code/debugging.js | 2 +- code/portal_detail_display.js | 4 +-- code/portal_detail_display_tools.js | 16 ++++----- code/request_handling.js | 2 +- main.js | 3 +- 7 files changed, 71 insertions(+), 18 deletions(-) diff --git a/code/boot.js b/code/boot.js index 3f90fb63..2e91471d 100644 --- a/code/boot.js +++ b/code/boot.js @@ -161,7 +161,7 @@ window.setupPlayerStat = function() { + '\n\nNote: your player stats can only be updated by a full reload (F5)'; $('#playerstat').html('' - + '

'+level+' ' + + '

'+level+' ' + ''+PLAYER.nickname+'' + '
' + 'XM: '+xmRatio+'%' @@ -189,6 +189,56 @@ window.setupSidebarToggle = function() { }); } +window.setupTooltips = function() { + $(document).tooltip({ + // enable mouse tracking + track: true, + // disable show/hide animation + show: false, + hide: false, + items: "[data-tooltip]", + content: function(){ + var type = $(this).attr('data-tooltip'); + if(type == 'title'){ + return $(this).attr('title'); + } + else if(type == 'title_render'){ + var title = $(this).attr('title'); + var data = []; + var max_columns = 0; + + // parse data + var rows = title.split('\n'); + $.each(rows, function(i, row){ + data[i] = row.replace(/\t+/g, '\t').split('\t'); + if(data[i].length > max_columns) max_columns = data[i].length; + }); + + // build table + if(max_columns > 1) { + var tooltip = ''; + $.each(data, function(i, row){ + tooltip += ''; + $.each(data[i], function(k, cell){ + var attributes = ''; + if(k == 0 && data[i].length < max_columns){ + attributes = ' colspan="'+(max_columns - data[i].length + 1)+'"'; + } + tooltip += ''+cell+''; + }); + tooltip += ''; + }); + tooltip += '
'; + return tooltip; + } + else { + return title.replace(/\n/g, '
'); + } + } + } + }); +} + // BOOTING /////////////////////////////////////////////////////////// @@ -204,6 +254,7 @@ function boot() { window.setupSidebarToggle(); window.updateGameScore(); window.setupPlayerStat(); + window.setupTooltips(); window.chat.setup(); // read here ONCE, so the URL is only evaluated one time after the // necessary data has been loaded. @@ -232,10 +283,11 @@ function asyncLoadScript(a){return function(b,c){var d=document.createElement("s // contains the default Ingress map style. var LLGMAPS = 'http://breunigs.github.com/ingress-intel-total-conversion/dist/leaflet_google.js'; var JQUERY = 'https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js'; +var JQUERYUI = 'http://code.jquery.com/ui/1.10.0/jquery-ui.js'; var LEAFLET = 'http://cdn.leafletjs.com/leaflet-0.5/leaflet.js'; var AUTOLINK = 'http://breunigs.github.com/ingress-intel-total-conversion/dist/autolink.js'; // after all scripts have loaded, boot the actual app -load(JQUERY, LEAFLET, AUTOLINK).then(LLGMAPS).onError(function (err) { +load(JQUERY, LEAFLET, AUTOLINK).then(LLGMAPS, JQUERYUI).onError(function (err) { alert('Could not all resources, the script likely won’t work.\n\nIf this happend the first time for you, it’s probably a temporary issue. Just wait a bit and try again.\n\nIf you installed the script for the first time and this happens:\n– try disabling NoScript if you have it installed\n– press CTRL+SHIFT+K in Firefox or CTRL+SHIFT+I in Chrome/Opera and reload the page. Additional info may be available in the console.\n– Open an issue at https://github.com/breunigs/ingress-intel-total-conversion/issues'); }).thenRun(boot); diff --git a/code/chat.js b/code/chat.js index 7b091552..61bd1ffd 100644 --- a/code/chat.js +++ b/code/chat.js @@ -336,7 +336,7 @@ window.chat.handlePublicAutomated = function(data) { case 'PORTAL': var latlng = [part[1].latE6/1E6, part[1].lngE6/1E6]; var js = 'window.zoomToAndShowPortal(\''+part[1].guid+'\', ['+latlng[0]+', '+latlng[1]+'])'; - tmpmsg += ''+part[1].name+''; + tmpmsg += ''+part[1].name+''; break; } }); @@ -453,9 +453,9 @@ window.chat.renderMsg = function(msg, nick, time, team) { var ta = unixTimeToHHmm(time); var tb = unixTimeToString(time, true); // help cursor via “#chat time” - var t = ''; + var t = ''; var s = 'style="color:'+COLORS[team]+'"'; - var title = nick.length >= 8 ? 'title="'+nick+'" class="help"' : ''; + var title = nick.length >= 8 ? 'title="'+nick+'" class="help" data-tooltip="title"' : ''; return '

'+t+' <'+nick+'> '+msg+'

'; } diff --git a/code/debugging.js b/code/debugging.js index b3f12ecc..7156ddda 100644 --- a/code/debugging.js +++ b/code/debugging.js @@ -72,7 +72,7 @@ window.debug.console.renderLine = function(text, errorType) { var d = new Date(); var ta = d.toLocaleTimeString(); // print line instead maybe? var tb = d.toLocaleString(); - var t = ''; + var t = ''; var s = 'style="color:'+color+'"'; var l = '

'+t+''+errorType+''+text+'

'; $('#debugconsole').prepend(l); diff --git a/code/portal_detail_display.js b/code/portal_detail_display.js index 98b33592..cec6b052 100644 --- a/code/portal_detail_display.js +++ b/code/portal_detail_display.js @@ -18,7 +18,7 @@ window.renderPortalDetails = function(guid) { if(d.portalV2.linkedEdges) $.each(d.portalV2.linkedEdges, function(ind, link) { links[link.isOrigin ? 'outgoing' : 'incoming']++; }); - function linkExpl(t) { return ''+t+''; } + function linkExpl(t) { return ''+t+''; } var linksText = [linkExpl('links'), linkExpl(' ↳ ' + links.incoming+'  •  '+links.outgoing+' ↴')]; var player = d.captured && d.captured.capturingPlayerId @@ -62,7 +62,7 @@ window.renderPortalDetails = function(guid) { .html('' + '

'+d.portalV2.descriptiveText.TITLE+'

' // help cursor via “.imgpreview img” - + '
' + + '
' + ''+Math.floor(getPortalLevel(d))+'' + '
'+getModDetails(d)+'
' + '
'+randDetails+'
' diff --git a/code/portal_detail_display_tools.js b/code/portal_detail_display_tools.js index 6bcbe96e..71d7c333 100644 --- a/code/portal_detail_display_tools.js +++ b/code/portal_detail_display_tools.js @@ -56,10 +56,10 @@ window.getModDetails = function(d) { } }); - var t = ''+mods[0]+'' - + ''+mods[1]+'' - + ''+mods[2]+'' - + ''+mods[3]+'' + var t = ''+mods[0]+'' + + ''+mods[1]+'' + + ''+mods[2]+'' + + ''+mods[3]+'' return t; } @@ -69,7 +69,7 @@ window.getEnergyText = function(d) { var totalNrg = getTotalPortalEnergy(d); var inf = currentNrg + ' / ' + totalNrg; var fill = prettyEnergy(currentNrg) + ' / ' + prettyEnergy(totalNrg) - return ['energy', '' + fill + '']; + return ['energy', '' + fill + '']; } window.getAvgResoDistText = function(d) { @@ -112,7 +112,7 @@ window.getResonatorDetails = function(d) { // rotates clockwise. So, last one is 7 (southeast). window.renderResonatorDetails = function(slot, level, nrg, dist, nick, isLeft) { if(level === 0) { - var meter = ''; + var meter = ''; } else { var max = RESO_NRG[level]; var fillGrade = nrg/max*100; @@ -131,7 +131,7 @@ window.renderResonatorDetails = function(slot, level, nrg, dist, nick, isLeft) { var fill = ''; - var meter = '' + fill + lbar + ''; + var meter = '' + fill + lbar + ''; } var cls = isLeft ? 'left' : 'right'; var text = ''+(nick||'')+''; @@ -162,7 +162,7 @@ window.getDestroyAP = function(d) { t += linkCount + '×\tLinks\t\t= ' + digits(linkAp) + '\n'; t += fieldCount + '×\tFields\t\t= ' + digits(fieldAp) + '\n'; t += 'Sum: ' + digits(sum) + ' AP'; - return '' + digits(text) + ''; + return '' + digits(text) + ''; } return [tt('AP Gain'), tt(sum)]; diff --git a/code/request_handling.js b/code/request_handling.js index 042fc397..e28f4c7e 100644 --- a/code/request_handling.js +++ b/code/request_handling.js @@ -47,7 +47,7 @@ window.renderUpdateStatus = function() { t += 'Up to date.'; if(renderLimitReached()) - t += ' RENDER LIMIT ' + t += ' RENDER LIMIT ' if(window.failedRequestCount > 0) t += ' ' + window.failedRequestCount + ' failed.' diff --git a/main.js b/main.js index 64a0967d..2d63987d 100644 --- a/main.js +++ b/main.js @@ -57,7 +57,8 @@ document.getElementsByTagName('head')[0].innerHTML = '' + 'Ingress Intel Map' + '' + '' - + ''; + + '' + + ''; document.getElementsByTagName('body')[0].innerHTML = '' + '
Loading, please wait
' From e0bb10f9897c60c4afab089abb2d8262b2c3288f Mon Sep 17 00:00:00 2001 From: saithis Date: Tue, 12 Feb 2013 19:46:04 +0100 Subject: [PATCH 05/15] Added missing space between 'span' and 'title' --- code/portal_detail_display_tools.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/code/portal_detail_display_tools.js b/code/portal_detail_display_tools.js index 71d7c333..96b92094 100644 --- a/code/portal_detail_display_tools.js +++ b/code/portal_detail_display_tools.js @@ -56,10 +56,10 @@ window.getModDetails = function(d) { } }); - var t = ''+mods[0]+'' - + ''+mods[1]+'' - + ''+mods[2]+'' - + ''+mods[3]+'' + var t = ''+mods[0]+'' + + ''+mods[1]+'' + + ''+mods[2]+'' + + ''+mods[3]+'' return t; } From 0d0bd4b26a0784f7b28fca923d272dc63379c160 Mon Sep 17 00:00:00 2001 From: Stefan Breunig Date: Tue, 12 Feb 2013 23:12:28 +0100 Subject: [PATCH 06/15] fix indenting --- code/chat.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/chat.js b/code/chat.js index 7b091552..ac3da081 100644 --- a/code/chat.js +++ b/code/chat.js @@ -304,7 +304,7 @@ window.chat.handlePublic = function(data, textStatus, jqXHR, isOldMsgs) { window.chat.handlePublicAutomated = function(data) { - $.each(data.result, function(ind, json) { // newest first! + $.each(data.result, function(ind, json) { // newest first! var time = json[1]; // ignore player messages @@ -347,7 +347,7 @@ window.chat.handlePublicAutomated = function(data) { tmpmsg = chat.renderMsg(tmpmsg, nick, time, team); window.chat._displayedPlayerActionTime[pguid] = [time, tmpmsg]; }; - }); + }); if(chat.getActive() === 'automated') window.chat.renderAutomatedMsgsTo(); From 139e06d86ca96f235a7a95a3a31e5e21a5b2f2ac Mon Sep 17 00:00:00 2001 From: Stefan Breunig Date: Tue, 12 Feb 2013 23:12:41 +0100 Subject: [PATCH 07/15] fix typo --- code/map_data.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/map_data.js b/code/map_data.js index 893ecc3a..f915de47 100644 --- a/code/map_data.js +++ b/code/map_data.js @@ -75,7 +75,7 @@ window.handleDataResponse = function(data, textStatus, jqXHR) { if(getTypeByGuid(guid) === TYPE_FIELD && window.fields[guid] !== undefined) { $.each(window.fields[guid].options.vertices, function(ind, vertex) { if(window.portals[vertex.guid] === undefined) return true; - fieldArray = window.portals[vertex.guid].options.portalV2.linkedFields; + fieldArray = window.portals[vertex.guid].options.details.portalV2.linkedFields; fieldArray.splice($.inArray(guid, fieldArray), 1); }); } From 039f9c14b5fdc2d3ac8007b91be752afc94264e0 Mon Sep 17 00:00:00 2001 From: saithis Date: Tue, 12 Feb 2013 23:16:12 +0100 Subject: [PATCH 08/15] * The jQuery UI js/css file is now taken from ajax.googleapis.com instead of code.jquery.com * Table or not is now autodetected, removed data-tooltip attributes * Empty table cells are now possible * Removed duplicated \t's on some titles * Some tooltip code cleanup --- code/boot.js | 80 +++++++++++++---------------- code/chat.js | 6 +-- code/debugging.js | 2 +- code/game_status.js | 2 +- code/portal_detail_display.js | 4 +- code/portal_detail_display_tools.js | 26 +++++----- code/request_handling.js | 2 +- main.js | 2 +- 8 files changed, 59 insertions(+), 65 deletions(-) diff --git a/code/boot.js b/code/boot.js index 2e91471d..a0c7a591 100644 --- a/code/boot.js +++ b/code/boot.js @@ -153,15 +153,15 @@ window.setupPlayerStat = function() { var cls = PLAYER.team === 'ALIENS' ? 'enl' : 'res'; - var t = 'Level:\t\t' + level + '\n' - + 'XM:\t\t\t' + PLAYER.energy + ' / ' + xmMax + '\n' - + 'AP:\t\t\t' + digits(ap) + '\n' + var t = 'Level:\t' + level + '\n' + + 'XM:\t' + PLAYER.energy + ' / ' + xmMax + '\n' + + 'AP:\t' + digits(ap) + '\n' + (level < 8 ? 'level up in:\t' + lvlUpAp + ' AP' : 'Congrats! (neeeeerd)') - + '\n\Invites:\t\t'+PLAYER.available_invites; + + '\n\Invites:\t'+PLAYER.available_invites; + '\n\nNote: your player stats can only be updated by a full reload (F5)'; $('#playerstat').html('' - + '

'+level+' ' + + '

'+level+' ' + ''+PLAYER.nickname+'' + '
' + 'XM: '+xmRatio+'%' @@ -196,45 +196,39 @@ window.setupTooltips = function() { // disable show/hide animation show: false, hide: false, - items: "[data-tooltip]", - content: function(){ - var type = $(this).attr('data-tooltip'); - if(type == 'title'){ - return $(this).attr('title'); - } - else if(type == 'title_render'){ - var title = $(this).attr('title'); - var data = []; - var max_columns = 0; + content: function() { + var title = $(this).attr('title'); - // parse data - var rows = title.split('\n'); - $.each(rows, function(i, row){ - data[i] = row.replace(/\t+/g, '\t').split('\t'); - if(data[i].length > max_columns) max_columns = data[i].length; + // check if it should be converted to a table + if(!title.match(/\t/)) { + return title.replace(/\n/g, '
'); + } + + var data = []; + var columnCount = 0; + + // parse data + var rows = title.split('\n'); + $.each(rows, function(i, row) { + data[i] = row.split('\t'); + if(data[i].length > columnCount) columnCount = data[i].length; + }); + + // build the table + var tooltip = ''; + $.each(data, function(i, row) { + tooltip += ''; + $.each(data[i], function(k, cell) { + var attributes = ''; + if(k === 0 && data[i].length < columnCount) { + attributes = ' colspan="'+(columnCount - data[i].length + 1)+'"'; + } + tooltip += ''+cell+''; }); - - // build table - if(max_columns > 1) { - var tooltip = '
'; - $.each(data, function(i, row){ - tooltip += ''; - $.each(data[i], function(k, cell){ - var attributes = ''; - if(k == 0 && data[i].length < max_columns){ - attributes = ' colspan="'+(max_columns - data[i].length + 1)+'"'; - } - tooltip += ''+cell+''; - }); - tooltip += ''; - }); - tooltip += '
'; - return tooltip; - } - else { - return title.replace(/\n/g, '
'); - } - } + tooltip += ''; + }); + tooltip += ''; + return tooltip; } }); } @@ -283,7 +277,7 @@ function asyncLoadScript(a){return function(b,c){var d=document.createElement("s // contains the default Ingress map style. var LLGMAPS = 'http://breunigs.github.com/ingress-intel-total-conversion/dist/leaflet_google.js'; var JQUERY = 'https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js'; -var JQUERYUI = 'http://code.jquery.com/ui/1.10.0/jquery-ui.js'; +var JQUERYUI = 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.0/jquery-ui.min.js'; var LEAFLET = 'http://cdn.leafletjs.com/leaflet-0.5/leaflet.js'; var AUTOLINK = 'http://breunigs.github.com/ingress-intel-total-conversion/dist/autolink.js'; diff --git a/code/chat.js b/code/chat.js index 61bd1ffd..7b091552 100644 --- a/code/chat.js +++ b/code/chat.js @@ -336,7 +336,7 @@ window.chat.handlePublicAutomated = function(data) { case 'PORTAL': var latlng = [part[1].latE6/1E6, part[1].lngE6/1E6]; var js = 'window.zoomToAndShowPortal(\''+part[1].guid+'\', ['+latlng[0]+', '+latlng[1]+'])'; - tmpmsg += ''+part[1].name+''; + tmpmsg += ''+part[1].name+''; break; } }); @@ -453,9 +453,9 @@ window.chat.renderMsg = function(msg, nick, time, team) { var ta = unixTimeToHHmm(time); var tb = unixTimeToString(time, true); // help cursor via “#chat time” - var t = ''; + var t = ''; var s = 'style="color:'+COLORS[team]+'"'; - var title = nick.length >= 8 ? 'title="'+nick+'" class="help" data-tooltip="title"' : ''; + var title = nick.length >= 8 ? 'title="'+nick+'" class="help"' : ''; return '

'+t+' <'+nick+'> '+msg+'

'; } diff --git a/code/debugging.js b/code/debugging.js index 7156ddda..b3f12ecc 100644 --- a/code/debugging.js +++ b/code/debugging.js @@ -72,7 +72,7 @@ window.debug.console.renderLine = function(text, errorType) { var d = new Date(); var ta = d.toLocaleTimeString(); // print line instead maybe? var tb = d.toLocaleString(); - var t = ''; + var t = ''; var s = 'style="color:'+color+'"'; var l = '

'+t+''+errorType+''+text+'

'; $('#debugconsole').prepend(l); diff --git a/code/game_status.js b/code/game_status.js index 6027bfe3..fe29b868 100644 --- a/code/game_status.js +++ b/code/game_status.js @@ -15,7 +15,7 @@ window.updateGameScore = function(data) { var es = ' '+Math.round(ep)+'%'; $('#gamestat').html(rs+es).one('click', function() { window.updateGameScore() }); // help cursor via “#gamestat span” - $('#gamestat').attr('title', 'Resistance:\t\t'+r+' MindUnits\nEnlightenment:\t'+e+' MindUnits'); + $('#gamestat').attr('title', 'Resistance:\t'+r+' MindUnits\nEnlightenment:\t'+e+' MindUnits'); window.setTimeout('window.updateGameScore', REFRESH_GAME_SCORE*1000); } diff --git a/code/portal_detail_display.js b/code/portal_detail_display.js index cec6b052..98b33592 100644 --- a/code/portal_detail_display.js +++ b/code/portal_detail_display.js @@ -18,7 +18,7 @@ window.renderPortalDetails = function(guid) { if(d.portalV2.linkedEdges) $.each(d.portalV2.linkedEdges, function(ind, link) { links[link.isOrigin ? 'outgoing' : 'incoming']++; }); - function linkExpl(t) { return ''+t+''; } + function linkExpl(t) { return ''+t+''; } var linksText = [linkExpl('links'), linkExpl(' ↳ ' + links.incoming+'  •  '+links.outgoing+' ↴')]; var player = d.captured && d.captured.capturingPlayerId @@ -62,7 +62,7 @@ window.renderPortalDetails = function(guid) { .html('' + '

'+d.portalV2.descriptiveText.TITLE+'

' // help cursor via “.imgpreview img” - + '
' + + '
' + ''+Math.floor(getPortalLevel(d))+'' + '
'+getModDetails(d)+'
' + '
'+randDetails+'
' diff --git a/code/portal_detail_display_tools.js b/code/portal_detail_display_tools.js index 96b92094..33571d6c 100644 --- a/code/portal_detail_display_tools.js +++ b/code/portal_detail_display_tools.js @@ -56,10 +56,10 @@ window.getModDetails = function(d) { } }); - var t = ''+mods[0]+'' - + ''+mods[1]+'' - + ''+mods[2]+'' - + ''+mods[3]+'' + var t = ''+mods[0]+'' + + ''+mods[1]+'' + + ''+mods[2]+'' + + ''+mods[3]+'' return t; } @@ -69,7 +69,7 @@ window.getEnergyText = function(d) { var totalNrg = getTotalPortalEnergy(d); var inf = currentNrg + ' / ' + totalNrg; var fill = prettyEnergy(currentNrg) + ' / ' + prettyEnergy(totalNrg) - return ['energy', '' + fill + '']; + return ['energy', '' + fill + '']; } window.getAvgResoDistText = function(d) { @@ -112,15 +112,15 @@ window.getResonatorDetails = function(d) { // rotates clockwise. So, last one is 7 (southeast). window.renderResonatorDetails = function(slot, level, nrg, dist, nick, isLeft) { if(level === 0) { - var meter = ''; + var meter = ''; } else { var max = RESO_NRG[level]; var fillGrade = nrg/max*100; - var inf = 'energy:\t\t' + nrg + ' / ' + max + ' (' + Math.round(fillGrade) + '%)\n' - + 'level:\t\t' + level + '\n' + var inf = 'energy:\t' + nrg + ' / ' + max + ' (' + Math.round(fillGrade) + '%)\n' + + 'level:\t' + level + '\n' + 'distance:\t' + dist + 'm\n' - + 'owner:\t\t' + nick + '\n' + + 'owner:\t' + nick + '\n' + 'octant:\t' + OCTANTS[slot]; var style = 'width:'+fillGrade+'%; background:'+COLORS_LVL[level]+';'; @@ -131,7 +131,7 @@ window.renderResonatorDetails = function(slot, level, nrg, dist, nick, isLeft) { var fill = ''; - var meter = '' + fill + lbar + ''; + var meter = '' + fill + lbar + ''; } var cls = isLeft ? 'left' : 'right'; var text = ''+(nick||'')+''; @@ -159,10 +159,10 @@ window.getDestroyAP = function(d) { function tt(text) { var t = 'Destroy:\n'; t += resoCount + '×\tResonators\t= ' + digits(resoAp) + '\n'; - t += linkCount + '×\tLinks\t\t= ' + digits(linkAp) + '\n'; - t += fieldCount + '×\tFields\t\t= ' + digits(fieldAp) + '\n'; + t += linkCount + '×\tLinks\t= ' + digits(linkAp) + '\n'; + t += fieldCount + '×\tFields\t= ' + digits(fieldAp) + '\n'; t += 'Sum: ' + digits(sum) + ' AP'; - return '' + digits(text) + ''; + return '' + digits(text) + ''; } return [tt('AP Gain'), tt(sum)]; diff --git a/code/request_handling.js b/code/request_handling.js index e28f4c7e..042fc397 100644 --- a/code/request_handling.js +++ b/code/request_handling.js @@ -47,7 +47,7 @@ window.renderUpdateStatus = function() { t += 'Up to date.'; if(renderLimitReached()) - t += ' RENDER LIMIT ' + t += ' RENDER LIMIT ' if(window.failedRequestCount > 0) t += ' ' + window.failedRequestCount + ' failed.' diff --git a/main.js b/main.js index 2d63987d..9d1ea3b1 100644 --- a/main.js +++ b/main.js @@ -58,7 +58,7 @@ document.getElementsByTagName('head')[0].innerHTML = '' + '' + '' + '' - + ''; + + ''; document.getElementsByTagName('body')[0].innerHTML = '' + '
Loading, please wait
' From 847a3d5fc15217d90fa91e613c31805ad8b8f920 Mon Sep 17 00:00:00 2001 From: Stefan Breunig Date: Tue, 12 Feb 2013 23:22:45 +0100 Subject: [PATCH 09/15] =?UTF-8?q?warn=20when=20chat=20message=20didn?= =?UTF-8?q?=E2=80=99t=20make=20it=20but=20the=20server=20actually=20send?= =?UTF-8?q?=20a=20response?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/chat.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/code/chat.js b/code/chat.js index ac3da081..808b198f 100644 --- a/code/chat.js +++ b/code/chat.js @@ -685,11 +685,15 @@ window.chat.postMsg = function() { lngE6: Math.round(latlng.lng*1E6), factionOnly: !public}; + var errMsg = 'Your message could not be delivered. You can copy&' + + 'paste it here and try again if you want:\n\n' + msg; + window.postAjax('sendPlext', data, - function() { if(public) chat.requestNewPublic(); else chat.requestNewFaction(); }, + function(response) { + if(response.error) alert(errMsg); + if(public) chat.requestNewPublic(); else chat.requestNewFaction(); }, function() { - alert('Your message could not be delivered. You can copy&' + - 'paste it here and try again if you want:\n\n'+msg); + alert(errMsg); } ); From 4c07fb12ae63e82271b7d17c50e4a3580ee77b57 Mon Sep 17 00:00:00 2001 From: Stefan Breunig Date: Wed, 13 Feb 2013 02:49:13 +0100 Subject: [PATCH 10/15] properly check if portal details are available --- code/portal_detail_display.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/code/portal_detail_display.js b/code/portal_detail_display.js index 98b33592..703af772 100644 --- a/code/portal_detail_display.js +++ b/code/portal_detail_display.js @@ -4,13 +4,14 @@ // methods that highlight the portal in the map view. window.renderPortalDetails = function(guid) { - var d = window.portals[guid].options.details; - if(!d) { + if(!window.portals[guid]) { unselectOldPortal(); urlPortal = guid; return; } + var d = window.portals[guid].options.details; + var update = selectPortal(guid); // collect some random data that’s not worth to put in an own method From 360f6f8336dc6d2c1e01414db35a77fa1c0f6cba Mon Sep 17 00:00:00 2001 From: Stefan Breunig Date: Wed, 13 Feb 2013 02:52:27 +0100 Subject: [PATCH 11/15] rework chat handling completely MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The old system was getting too complicated to add new features to. The new one should be easier to understand and will be explained below. This patch should fix #140 and fix #16. There are several places where new data requests may come from: - chat.needMoreMessages checks if we are scrolled too far up or there is no scrollbar. It then requests new messages. - scrolling up - switching the chat tab via chat.chooser - auto refresh - once on boot The latter two always request both types of chat. Faction and public are handled the same way. Public is later split into categories. I will explain the faction chat here because it’s easier. It starts in chat.requestFaction. This will initialize the query to the server for data. The exact query is determined by chat. genPostData. There can only be one faction chat request at a time. Clearing on map move is handled automatically in code/requests.js. Let’s assume the data query is successful. It is now passed to chat.handleFaction which runs some basic checks before the data is processed and stored in chat._factionData. This is done by chat. writeDataToHash. The hash keys are the message GUIDs to avoid duplicates. The hash values are an array of timestamp, processed message and other meta data. There is only one way to render faction chat, so data is directly handed to chat.renderFaction which immediately hands it to chat .renderData. renderData discards the GUIDs and sorts the values by their timestamp. It then iterates over the data to insert date break lines and finally renders the data in the DOM. It also does some magic to keep the correct scrolling position. Chat data will be cleared on map move or zoom. However, the display is not refreshed, so the old, invalid chat data is still displayed. Only once the data query is finished the data is rendered. The upside is that small map operations within your local area appear to never lose their chat data. Downside is that there’s invalid chat for some time when changing cities. --- code/chat.js | 460 +++++++++++++++------------------------ code/request_handling.js | 6 +- main.js | 12 +- style.css | 2 +- 4 files changed, 183 insertions(+), 297 deletions(-) diff --git a/code/chat.js b/code/chat.js index 808b198f..faf7f0b9 100644 --- a/code/chat.js +++ b/code/chat.js @@ -1,22 +1,14 @@ window.chat = function() {}; -window.chat._lastNicksForAutocomplete = [[], []]; -window.chat.addNickForAutocomplete = function(nick, isFaction) { - var r = chat._lastNicksForAutocomplete[isFaction ? 0 : 1]; - if(r.indexOf(nick) !== -1) return; - r.push(nick); - if(r.length >= 15) - r.shift(); -} - window.chat.handleTabCompletion = function() { var el = $('#chatinput input'); var curPos = el.get(0).selectionStart; var text = el.val(); var word = text.slice(0, curPos).replace(/.*\b([a-z0-9-_])/, '$1').toLowerCase(); - var list = window.chat._lastNicksForAutocomplete; - list = list[1].concat(list[0]); + var list = $('#chat > div:visible mark'); + list = list.map(function(ind, mark) { return $(mark).text(); } ); + list = uniqueArray(list); var nick = null; for(var i = 0; i < list.length; i++) { @@ -43,27 +35,24 @@ window.chat.handleTabCompletion = function() { // timestamp and clear management // -window.chat._oldFactionTimestamp = -1; -window.chat._newFactionTimestamp = -1; -window.chat._oldPublicTimestamp = -1; -window.chat._newPublicTimestamp = -1; - -window.chat.getOldestTimestamp = function(public) { - return chat['_old'+(public ? 'Public' : 'Faction')+'Timestamp']; +window.chat.getTimestamps = function(isFaction) { + var storage = isFaction ? chat._factionData : chat._publicData; + return $.map(storage, function(v, k) { return [v[0]]; }); } -window.chat.getNewestTimestamp = function(public) { - return chat['_new'+(public ? 'Public' : 'Faction')+'Timestamp']; +window.chat.getOldestTimestamp = function(isFaction) { + var t = Math.min.apply(null, chat.getTimestamps(isFaction)); + return t === Infinity ? -1 : t; } -window.chat.clearIfRequired = function(elm) { - if(!elm.data('needsClearing')) return; - elm.data('ignoreNextScroll', true).data('needsClearing', false).html(''); +window.chat.getNewestTimestamp = function(isFaction) { + var t = Math.max.apply(null, chat.getTimestamps(isFaction)); + return t === -1*Infinity ? -1 : t; } window.chat._oldBBox = null; -window.chat.genPostData = function(public, getOlderMsgs) { - if(typeof public !== 'boolean') throw('Need to know if public or faction chat.'); +window.chat.genPostData = function(isFaction, getOlderMsgs) { + if(typeof isFaction !== 'boolean') throw('Need to know if public or faction chat.'); chat._localRangeCircle.setLatLng(map.getCenter()); var b = map.getBounds().extend(chat._localRangeCircle.getBounds()); @@ -78,35 +67,30 @@ window.chat.genPostData = function(public, getOlderMsgs) { // need to reset these flags now because clearing will only occur // after the request is finished – i.e. there would be one almost // useless request. - chat._displayedFactionGuids = []; - chat._displayedPublicGuids = []; - chat._displayedPlayerActionTime = {}; - chat._oldFactionTimestamp = -1; - chat._newFactionTimestamp = -1; - chat._oldPublicTimestamp = -1; - chat._newPublicTimestamp = -1; + chat._factionData = {}; + chat._publicData = {}; } chat._oldBBox = bbs; var ne = b.getNorthEast(); var sw = b.getSouthWest(); var data = { - desiredNumItems: public ? CHAT_PUBLIC_ITEMS : CHAT_FACTION_ITEMS, + desiredNumItems: isFaction ? CHAT_FACTION_ITEMS : CHAT_PUBLIC_ITEMS , minLatE6: Math.round(sw.lat*1E6), minLngE6: Math.round(sw.lng*1E6), maxLatE6: Math.round(ne.lat*1E6), maxLngE6: Math.round(ne.lng*1E6), minTimestampMs: -1, maxTimestampMs: -1, - factionOnly: !public + factionOnly: isFaction } if(getOlderMsgs) { // ask for older chat when scrolling up - data = $.extend(data, {maxTimestampMs: chat.getOldestTimestamp(public)}); + data = $.extend(data, {maxTimestampMs: chat.getOldestTimestamp(isFaction)}); } else { // ask for newer chat - var min = chat.getNewestTimestamp(public); + var min = chat.getNewestTimestamp(isFaction); // the inital request will have both timestamp values set to -1, // thus we receive the newest desiredNumItems. After that, we will // only receive messages with a timestamp greater or equal to min @@ -130,322 +114,217 @@ window.chat.genPostData = function(public, getOlderMsgs) { // -// requesting faction +// faction // -window.chat._requestOldFactionRunning = false; -window.chat.requestOldFaction = function(isRetry) { - if(chat._requestOldFactionRunning) return; +window.chat._requestFactionRunning = false; +window.chat.requestFaction = function(getOlderMsgs, isRetry) { + if(chat._requestFactionRunning && !isRetry) return; if(isIdle()) return renderUpdateStatus(); - chat._requestOldFactionRunning = true; + chat._requestFactionRunning = true; - var d = chat.genPostData(false, true); + var d = chat.genPostData(true, getOlderMsgs); var r = window.postAjax( 'getPaginatedPlextsV2', d, - chat.handleOldFaction, + chat.handleFaction, isRetry - ? function() { window.chat._requestOldFactionRunning = false; } - : function() { window.chat.requestOldFaction(true) } - ); - - requests.add(r); -} - -window.chat._requestNewFactionRunning = false; -window.chat.requestNewFaction = function(isRetry) { - if(chat._requestNewFactionRunning) return; - if(window.isIdle()) return renderUpdateStatus(); - chat._requestNewFactionRunning = true; - - var d = chat.genPostData(false, false); - var r = window.postAjax( - 'getPaginatedPlextsV2', - d, - chat.handleNewFaction, - isRetry - ? function() { window.chat._requestNewFactionRunning = false; } - : function() { window.chat.requestNewFaction(true) } + ? function() { window.chat._requestFactionRunning = false; } + : function() { window.chat.requestFaction(getOlderMsgs, true) } ); requests.add(r); } -// -// handle faction -// +window.chat._factionData = {}; +window.chat.handleFaction = function(data, textStatus, jqXHR) { + chat._requestFactionRunning = false; -window.chat.handleOldFaction = function(data, textStatus, jqXHR) { - chat._requestOldFactionRunning = false; - chat.handleFaction(data, textStatus, jqXHR, true); -} - -window.chat.handleNewFaction = function(data, textStatus, jqXHR) { - chat._requestNewFactionRunning = false; - chat.handleFaction(data, textStatus, jqXHR, false); -} - - - -window.chat._displayedFactionGuids = []; -window.chat.handleFaction = function(data, textStatus, jqXHR, isOldMsgs) { if(!data || !data.result) { window.failedRequestCount++; return console.warn('faction chat error. Waiting for next auto-refresh.'); } - var c = $('#chatfaction'); - chat.clearIfRequired(c); - if(data.result.length === 0) return; - chat._newFactionTimestamp = data.result[0][1]; - chat._oldFactionTimestamp = data.result[data.result.length-1][1]; + var old = chat.getOldestTimestamp(true); + chat.writeDataToHash(data, chat._factionData, false); + var oldMsgsWereAdded = old !== chat.getOldestTimestamp(true); - var scrollBefore = scrollBottom(c); - chat.renderPlayerMsgsTo(true, data, isOldMsgs, chat._displayedFactionGuids); - chat.keepScrollPosition(c, scrollBefore, isOldMsgs); + window.chat.renderFaction(oldMsgsWereAdded); if(data.result.length >= CHAT_FACTION_ITEMS) chat.needMoreMessages(); } - +window.chat.renderFaction = function(oldMsgsWereAdded) { + chat.renderData(chat._factionData, 'chatfaction', oldMsgsWereAdded); +} // -// requesting public +// public // -window.chat._requestOldPublicRunning = false; -window.chat.requestOldPublic = function(isRetry) { - if(chat._requestOldPublicRunning) return; +window.chat._requestPublicRunning = false; +window.chat.requestPublic = function(getOlderMsgs, isRetry) { + if(chat._requestPublicRunning && !isRetry) return; if(isIdle()) return renderUpdateStatus(); - chat._requestOldPublicRunning = true; + chat._requestPublicRunning = true; - var d = chat.genPostData(true, true); + var d = chat.genPostData(false, getOlderMsgs); var r = window.postAjax( 'getPaginatedPlextsV2', d, - chat.handleOldPublic, + chat.handlePublic, isRetry - ? function() { window.chat._requestOldPublicRunning = false; } - : function() { window.chat.requestOldPublic(true) } + ? function() { window.chat._requestPublicRunning = false; } + : function() { window.chat.requestPublic(getOlderMsgs, true) } ); requests.add(r); } -window.chat._requestNewPublicRunning = false; -window.chat.requestNewPublic = function(isRetry) { - if(chat._requestNewPublicRunning) return; - if(window.isIdle()) return renderUpdateStatus(); - chat._requestNewPublicRunning = true; +window.chat._publicData = {}; +window.chat.handlePublic = function(data, textStatus, jqXHR) { + chat._requestPublicRunning = false; - var d = chat.genPostData(true, false); - var r = window.postAjax( - 'getPaginatedPlextsV2', - d, - chat.handleNewPublic, - isRetry - ? function() { window.chat._requestNewPublicRunning = false; } - : function() { window.chat.requestNewPublic(true) } - ); - - requests.add(r); -} - - -// -// handle public -// - - -window.chat.handleOldPublic = function(data, textStatus, jqXHR) { - chat._requestOldPublicRunning = false; - chat.handlePublic(data, textStatus, jqXHR, true); -} - -window.chat.handleNewPublic = function(data, textStatus, jqXHR) { - chat._requestNewPublicRunning = false; - chat.handlePublic(data, textStatus, jqXHR, false); -} - -window.chat._displayedPublicGuids = []; -window.chat._displayedPlayerActionTime = {}; -window.chat.handlePublic = function(data, textStatus, jqXHR, isOldMsgs) { if(!data || !data.result) { window.failedRequestCount++; return console.warn('public chat error. Waiting for next auto-refresh.'); } - var ca = $('#chatautomated'); - var cp = $('#chatpublic'); - chat.clearIfRequired(ca); - chat.clearIfRequired(cp); - if(data.result.length === 0) return; - chat._newPublicTimestamp = data.result[0][1]; - chat._oldPublicTimestamp = data.result[data.result.length-1][1]; + var old = chat.getOldestTimestamp(true); + chat.writeDataToHash(data, chat._publicData, true); + var oldMsgsWereAdded = old !== chat.getOldestTimestamp(true); - - var scrollBefore = scrollBottom(ca); - chat.handlePublicAutomated(data); - chat.keepScrollPosition(ca, scrollBefore, isOldMsgs); - - - var scrollBefore = scrollBottom(cp); - chat.renderPlayerMsgsTo(false, data, isOldMsgs, chat._displayedPublicGuids); - chat.keepScrollPosition(cp, scrollBefore, isOldMsgs); + switch(chat.getActive()) { + case 'public': window.chat.renderPublic(oldMsgsWereAdded); break; + case 'compact': window.chat.renderCompact(oldMsgsWereAdded); break; + case 'full': window.chat.renderFull(oldMsgsWereAdded); break; + } if(data.result.length >= CHAT_PUBLIC_ITEMS) chat.needMoreMessages(); } - -window.chat.handlePublicAutomated = function(data) { - $.each(data.result, function(ind, json) { // newest first! - var time = json[1]; - - // ignore player messages - var t = json[2].plext.plextType; - if(t !== 'SYSTEM_BROADCAST' && t !== 'SYSTEM_NARROWCAST') return true; - - var tmpmsg = '', nick = null, pguid, team; - - // each automated message is composed of many text chunks. loop - // over them to gather all necessary data. - $.each(json[2].plext.markup, function(ind, part) { - switch(part[0]) { - case 'PLAYER': - pguid = part[1].guid; - var lastAction = window.chat._displayedPlayerActionTime[pguid]; - // ignore older messages about player - if(lastAction && lastAction[0] > time) return false; - - nick = part[1].plain; - team = part[1].team === 'ALIENS' ? TEAM_ENL : TEAM_RES; - window.setPlayerName(pguid, nick); // free nick name resolves - if(ind > 0) tmpmsg += nick; // don’t repeat nick directly - break; - - case 'TEXT': - tmpmsg += part[1].plain; - break; - - case 'PORTAL': - var latlng = [part[1].latE6/1E6, part[1].lngE6/1E6]; - var js = 'window.zoomToAndShowPortal(\''+part[1].guid+'\', ['+latlng[0]+', '+latlng[1]+'])'; - tmpmsg += ''+part[1].name+''; - break; - } - }); - - // nick will only be set if we don’t have any info about that - // player yet. - if(nick) { - tmpmsg = chat.renderMsg(tmpmsg, nick, time, team); - window.chat._displayedPlayerActionTime[pguid] = [time, tmpmsg]; - }; +window.chat.renderPublic = function(oldMsgsWereAdded) { + // only keep player data + var data = $.map(chat._publicData, function(entry) { + if(!entry[1]) return [entry]; }); - - if(chat.getActive() === 'automated') - window.chat.renderAutomatedMsgsTo(); + chat.renderData(data, 'chatpublic', oldMsgsWereAdded); } -window.chat.renderAutomatedMsgsTo = function() { - var x = window.chat._displayedPlayerActionTime; - // we don’t care about the GUIDs anymore - var vals = $.map(x, function(v, k) { return [v]; }); - // sort them old to new - vals = vals.sort(function(a, b) { return a[0]-b[0]; }); - - var prevTime = null; - var msgs = $.map(vals, function(v) { - var nowTime = new Date(v[0]).toLocaleDateString(); - if(prevTime && prevTime !== nowTime) - var val = chat.renderDivider(nowTime) + v[1]; - else - var val = v[1]; - - prevTime = nowTime; - return val; - }).join('\n'); - - $('#chatautomated').html(msgs); +window.chat.renderCompact = function(oldMsgsWereAdded) { + var data = {}; + $.each(chat._publicData, function(guid, entry) { + // skip player msgs + if(!entry[1]) return true; + var pguid = entry[3]; + // ignore if player has newer data + if(data[pguid] && data[pguid][0] > entry[0]) return true; + data[pguid] = entry; + }); + // data keys are now player guids instead of message guids. However, + // it is all the same to renderData. + chat.renderData(data, 'chatcompact', oldMsgsWereAdded); } - +window.chat.renderFull = function(oldMsgsWereAdded) { + // only keep automatically generated data + var data = $.map(chat._publicData, function(entry) { + if(entry[1]) return [entry]; + }); + chat.renderData(data, 'chatfull', oldMsgsWereAdded); +} // // common // - -window.chat.renderPlayerMsgsTo = function(isFaction, data, isOldMsgs, dupCheckArr) { - var msgs = ''; - var prevTime = null; - - $.each(data.result.reverse(), function(ind, json) { // oldest first! - if(json[2].plext.plextType !== 'PLAYER_GENERATED') return true; - +window.chat.writeDataToHash = function(newData, storageHash, skipSecureMsgs) { + $.each(newData.result, function(ind, json) { // avoid duplicates - if(dupCheckArr.indexOf(json[0]) !== -1) return true; - dupCheckArr.push(json[0]); + if(json[0] in storageHash) return true; var time = json[1]; var team = json[2].plext.team === 'ALIENS' ? TEAM_ENL : TEAM_RES; - var msg, nick, pguid; + var auto = json[2].plext.plextType !== 'PLAYER_GENERATED'; + var msg = '', nick, pguid; $.each(json[2].plext.markup, function(ind, markup) { - if(markup[0] === 'SENDER') { + switch(markup[0]) { + case 'SENDER': // user generated messages nick = markup[1].plain.slice(0, -2); // cut “: ” at end pguid = markup[1].guid; - window.setPlayerName(pguid, nick); // free nick name resolves - if(!isOldMsgs) window.chat.addNickForAutocomplete(nick, isFaction); - } + break; - if(markup[0] === 'TEXT') { - msg = markup[1].plain.autoLink(); - msg = msg.replace(window.PLAYER['nickMatcher'], '$1'); - } + case 'PLAYER': // automatically generated messages + pguid = markup[1].guid; + nick = markup[1].plain; + team = markup[1].team === 'ALIENS' ? TEAM_ENL : TEAM_RES; + if(ind > 0) msg += nick; // don’t repeat nick directly + break; - if(!isFaction && markup[0] === 'SECURE') { - nick = null; - return false; // aka break + case 'TEXT': + var tmp = markup[1].plain.autoLink(); + msg += tmp.replace(window.PLAYER['nickMatcher'], '$1'); + break; + + case 'PORTAL': + var latlng = [markup[1].latE6/1E6, markup[1].lngE6/1E6]; + var js = 'window.zoomToAndShowPortal(\''+markup[1].guid+'\', ['+latlng[0]+', '+latlng[1]+'])'; + msg += ''+markup[1].name+''; + break; + + case 'SECURE': + if(skipSecureMsgs) { + nick = null; + return false; // breaks $.each + } } }); - if(!nick) return true; // aka next - var nowTime = new Date(time).toLocaleDateString(); - if(prevTime && prevTime !== nowTime) - msgs += chat.renderDivider(nowTime); + // format: timestamp, autogenerated, HTML message, player guid + storageHash[json[0]] = [json[1], auto, chat.renderMsg(msg, nick, time, team), pguid]; - msgs += chat.renderMsg(msg, nick, time, team); - prevTime = nowTime; + window.setPlayerName(pguid, nick); // free nick name resolves + }); +} + +// renders data from the data-hash to the element defined by the given +// ID. Set 3rd argument to true if it is likely that old data has been +// added. Latter is only required for scrolling. +window.chat.renderData = function(data, element, likelyWereOldMsgs) { + var elm = $('#'+element); + if(elm.is(':hidden')) return; + + // discard guids and sort old to new + var vals = $.map(data, function(v, k) { return [v]; }); + vals = vals.sort(function(a, b) { return a[0]-b[0]; }); + + // render to string with date separators inserted + var msgs = ''; + var prevTime = null; + $.each(vals, function(ind, msg) { + var nextTime = new Date(msg[0]).toLocaleDateString(); + if(prevTime && prevTime !== nextTime) + msgs += chat.renderDivider(nextTime); + msgs += msg[2]; + prevTime = nextTime; }); - var addTo = isFaction ? $('#chatfaction') : $('#chatpublic'); - - // if there is a change of day between two requests, handle the - // divider insertion here. - if(isOldMsgs) { - var ts = addTo.find('time:first').data('timestamp'); - var nextTime = new Date(ts).toLocaleDateString(); - if(prevTime && prevTime !== nextTime && ts) - msgs += chat.renderDivider(nextTime); - } - - if(isOldMsgs) - addTo.prepend(msgs); - else - addTo.append(msgs); + var scrollBefore = scrollBottom(elm); + elm.html(msgs); + chat.keepScrollPosition(elm, scrollBefore, likelyWereOldMsgs); } window.chat.renderDivider = function(text) { - return '─ '+text+' ────────────────────────────────────────────────────────────────────────────'; + return '─ '+text+' ───────────────────────────────────────────────────────────'; } @@ -486,25 +365,29 @@ window.chat.toggle = function() { window.chat.request = function() { console.log('refreshing chat'); - chat.requestNewFaction(); - chat.requestNewPublic(); + chat.requestFaction(false); + chat.requestPublic(false); } // checks if there are enough messages in the selected chat tab and // loads more if not. window.chat.needMoreMessages = function() { - var activeChat = $('#chat > :visible'); - if(scrollBottom(activeChat) !== 0 || activeChat.scrollTop() !== 0) return; - var activeTab = $('#chatcontrols .active').text(); + var activeTab = chat.getActive(); if(activeTab === 'debug') return; - console.log('no scrollbar in active chat, requesting more msgs'); + var activeChat = $('#chat > :visible'); + + var hasScrollbar = scrollBottom(activeChat) !== 0 || activeChat.scrollTop() !== 0; + var nearTop = activeChat.scrollTop() <= CHAT_REQUEST_SCROLL_TOP; + if(hasScrollbar && !nearTop) return; + + console.log('No scrollbar or near top in active chat. Requesting more data.'); if(activeTab === 'faction') - chat.requestOldFaction(); + chat.requestFaction(true); else - chat.requestOldPublic(); + chat.requestPublic(true); } @@ -525,26 +408,26 @@ window.chat.chooser = function(event) { case 'faction': span.css('color', ''); span.text('tell faction:'); - elm = $('#chatfaction'); break; case 'public': span.css('cssText', 'color: red !important'); span.text('broadcast:'); - elm = $('#chatpublic'); break; - case 'automated': + case 'compact': + case 'full': span.css('cssText', 'color: #bbb !important'); span.text('tell Jarvis:'); - chat.renderAutomatedMsgsTo(); - elm = $('#chatautomated'); break; + + default: + throw('chat.chooser was asked to handle unknown button: ' + tt); } - if(!elm) throw('chat button handled by chat.chooser, yet it is null'); - + var elm = $('#chat' + tt); elm.show(); + eval('chat.render' + tt.capitalize() + '(false);'); if(elm.data('needsScrollTop')) { elm.data('ignoreNextScroll', true); elm.scrollTop(elm.data('needsScrollTop')); @@ -588,7 +471,7 @@ window.chat.setup = function() { $('#chatcontrols a:first').click(window.chat.toggle); $('#chatcontrols a').each(function(ind, elm) { - if($.inArray($(elm).text(), ['automated', 'public', 'faction']) !== -1) + if($.inArray($(elm).text(), ['full', 'compact', 'public', 'faction']) !== -1) $(elm).click(window.chat.chooser); }); @@ -603,15 +486,15 @@ window.chat.setup = function() { $('#chatfaction').scroll(function() { var t = $(this); if(t.data('ignoreNextScroll')) return t.data('ignoreNextScroll', false); - if(t.scrollTop() < 200) chat.requestOldFaction(); - if(scrollBottom(t) === 0) chat.requestNewFaction(); + if(t.scrollTop() < CHAT_REQUEST_SCROLL_TOP) chat.requestFaction(true); + if(scrollBottom(t) === 0) chat.requestFaction(false); }); - $('#chatpublic, #chatautomated').scroll(function() { + $('#chatpublic, #chatfull, #chatcompact').scroll(function() { var t = $(this); if(t.data('ignoreNextScroll')) return t.data('ignoreNextScroll', false); - if(t.scrollTop() < 200) chat.requestOldPublic(); - if(scrollBottom(t) === 0) chat.requestNewPublic(); + if(t.scrollTop() < CHAT_REQUEST_SCROLL_TOP) chat.requestPublic(true); + if(scrollBottom(t) === 0) chat.requestPublic(false); }); chat.request(); @@ -670,7 +553,8 @@ window.chat.setupPosting = function() { window.chat.postMsg = function() { var c = chat.getActive(); - if(c === 'automated') return alert('Jarvis: A strange game. The only winning move is not to play. How about a nice game of chess?'); + if(c === 'full' || c === 'compact') + return alert('Jarvis: A strange game. The only winning move is not to play. How about a nice game of chess?'); var msg = $.trim($('#chatinput input').val()); if(!msg || msg === '') return; @@ -691,7 +575,7 @@ window.chat.postMsg = function() { window.postAjax('sendPlext', data, function(response) { if(response.error) alert(errMsg); - if(public) chat.requestNewPublic(); else chat.requestNewFaction(); }, + if(public) chat.requestPublic(false); else chat.requestFaction(false); }, function() { alert(errMsg); } diff --git a/code/request_handling.js b/code/request_handling.js index 042fc397..6fe0acd3 100644 --- a/code/request_handling.js +++ b/code/request_handling.js @@ -25,10 +25,8 @@ window.requests.abort = function() { window.activeRequests = []; window.failedRequestCount = 0; - window.chat._requestOldPublicRunning = false; - window.chat._requestNewPublicRunning = false; - window.chat._requestOldFactionRunning = false; - window.chat._requestNewFactionRunning = false; + window.chat._requestPublicRunning = false; + window.chat._requestFactionRunning = false; renderUpdateStatus(); } diff --git a/main.js b/main.js index 64a0967d..b190399e 100644 --- a/main.js +++ b/main.js @@ -62,12 +62,14 @@ document.getElementsByTagName('head')[0].innerHTML = '' document.getElementsByTagName('body')[0].innerHTML = '' + '
Loading, please wait
' + '' + '' + '' + '' @@ -115,8 +117,10 @@ var CHAT_MIN_RANGE = 6; var VIEWPORT_PAD_RATIO = 0.3; // how many items to request each query -var CHAT_PUBLIC_ITEMS = 200 -var CHAT_FACTION_ITEMS = 50 +var CHAT_PUBLIC_ITEMS = 200; +var CHAT_FACTION_ITEMS = 50; +// how many pixels to the top before requesting new data +var CHAT_REQUEST_SCROLL_TOP = 200; // Leaflet will get very slow for MANY items. It’s better to display // only some instead of crashing the browser. diff --git a/style.css b/style.css index f7a375cf..15a033d3 100644 --- a/style.css +++ b/style.css @@ -191,7 +191,7 @@ em { top: 25px; } -#chatpublic, #chatautomated { +#chatpublic, #chatfull, #chatcompact, /* FIXME DEPRECATED: */#chatautomated { display: none; } From 4ca80b877e40c19df92bfe8b4b9467ec8aabd3a2 Mon Sep 17 00:00:00 2001 From: Xelio Date: Mon, 11 Feb 2013 21:14:35 +0800 Subject: [PATCH 12/15] Add resonator re-render logic Resonator will re-render if it's level/energy/distance changed Bring portal to front after resonators re-rendered. --- code/map_data.js | 43 ++++++++++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/code/map_data.js b/code/map_data.js index 893ecc3a..e0df8e41 100644 --- a/code/map_data.js +++ b/code/map_data.js @@ -227,7 +227,7 @@ window.renderPortal = function(ent) { u = u || oo.level !== portalLevel; // nothing for the portal changed, so don’t update. Let resonators // manage themselves if they want to be updated. - if(!u) return renderResonators(ent); + if(!u) return renderResonators(ent, old); // there were changes, remove old portal removeByGuid(ent[0]); } @@ -237,7 +237,6 @@ window.renderPortal = function(ent) { // pre-loads player names for high zoom levels loadPlayerNamesForPortal(ent[2]); - var lvWeight = Math.max(2, portalLevel / 1.5); var lvRadius = Math.max(portalLevel + 3, 5); @@ -261,7 +260,7 @@ window.renderPortal = function(ent) { // all resonators have already removed by zooming if(isResonatorsShow()) { for(var i = 0; i <= 7; i++) - removeByGuid(portalResonatorGuid(portalGuid,i)); + removeByGuid(portalResonatorGuid(portalGuid, i)); } delete window.portals[portalGuid]; if(window.selectedPortal === portalGuid) { @@ -287,7 +286,7 @@ window.renderPortal = function(ent) { window.map.setView(latlng, 17); }); - window.renderResonators(ent); + window.renderResonators(ent, null); window.runHooks('portalAdded', {portal: p}); @@ -295,18 +294,28 @@ window.renderPortal = function(ent) { p.addTo(layerGroup); } -window.renderResonators = function(ent) { +window.renderResonators = function(ent, portalLayer) { + if(!isResonatorsShow()) return; + var portalLevel = getPortalLevel(ent[2]); if(portalLevel < getMinPortalLevel() && ent[0] != selectedPortal) return; - if(!isResonatorsShow()) return; - - for(var i=0; i < ent[2].resonatorArray.resonators.length; i++) { + var layerGroup = portalsLayers[parseInt(portalLevel)]; + var reRendered = false; + for(var i = 0; i < ent[2].resonatorArray.resonators.length; i++) { var rdata = ent[2].resonatorArray.resonators[i]; - if(rdata == null) continue; + // skip if resonator didn't change + if(portalLayer) { + var oldRes = findEntityInLeaflet(layerGroup, window.resonators, portalResonatorGuid(ent[0], i)); + if(oldRes && isSameResonator(oldRes.options.details, rdata)) continue; + } - if(window.resonators[portalResonatorGuid(ent[0],i)]) continue; + // skip and remove old resonator if no new resonator + if(rdata === null) { + if(oldRes) removeByGuid(oldRes.options.guid); + continue; + } // offset in meters var dn = rdata.distanceToPortal*SLOT_TO_LAT[rdata.slot]; @@ -332,13 +341,16 @@ window.renderResonators = function(ent) { level: rdata.level, details: rdata, pDetails: ent[2], - guid: portalResonatorGuid(ent[0],i) }); + guid: portalResonatorGuid(ent[0], i) }); r.on('remove', function() { delete window.resonators[this.options.guid]; }); r.on('add', function() { window.resonators[this.options.guid] = this; }); r.addTo(portalsLayers[parseInt(portalLevel)]); + reRendered = true; } + // if there is any resonator re-rendered, bring portal to front + if(reRendered && portalLayer) portalLayer.bringToFront(); } // append portal guid with -resonator-[slot] to get guid for resonators @@ -350,6 +362,15 @@ window.isResonatorsShow = function() { return map.getZoom() >= RESONATOR_DISPLAY_ZOOM_LEVEL; } +window.isSameResonator = function(oldRes, newRes) { + if(!oldRes && !newRes) return true; + if(typeof oldRes !== typeof newRes) return false; + if(oldRes.level !== newRes.level) return false; + if(oldRes.energyTotal !== newRes.energyTotal) return false; + if(oldRes.distanceToPortal !== newRes.distanceToPortal) return false; + return true; +} + window.portalResetColor = function(portal) { portal.setStyle({color: portal.options.fillColor}); } From 79b917c8f1b6e9e7bb5edee4a54e0dedddb79f81 Mon Sep 17 00:00:00 2001 From: Stefan Breunig Date: Wed, 13 Feb 2013 03:22:01 +0100 Subject: [PATCH 13/15] divider bar too short --- code/chat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/chat.js b/code/chat.js index faf7f0b9..4e7b7893 100644 --- a/code/chat.js +++ b/code/chat.js @@ -324,7 +324,7 @@ window.chat.renderData = function(data, element, likelyWereOldMsgs) { window.chat.renderDivider = function(text) { - return '─ '+text+' ───────────────────────────────────────────────────────────'; + return '─ '+text+' ──────────────────────────────────────────────────────────────────────────'; } From ae65dff2d9d9b79d948ab9a4273859f8141abef4 Mon Sep 17 00:00:00 2001 From: Stefan Breunig Date: Wed, 13 Feb 2013 04:10:40 +0100 Subject: [PATCH 14/15] * ditch jQueryUI vanilla styles in favor of own ones. * disable tracking for tooltips and make them behave more like regular ones (this also stops my fan from spinning up when using the intel map) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Improvements welcome. Tooltips are currently placed at the bottom of the element instead of next to cursor. It seems it’s either tracking or placing it not anywhere where one would expect a tooltip. I immediately regret having chosen jQueryUI. It’s not very flexible and has awkward defaults. --- code/boot.js | 7 ++++--- main.js | 3 +-- style.css | 18 ++++++++++++++---- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/code/boot.js b/code/boot.js index a0c7a591..7b1956a9 100644 --- a/code/boot.js +++ b/code/boot.js @@ -191,11 +191,12 @@ window.setupSidebarToggle = function() { window.setupTooltips = function() { $(document).tooltip({ - // enable mouse tracking - track: true, // disable show/hide animation - show: false, + show: { effect: "hide", duration: 0 } , hide: false, + open: function(event, ui) { + ui.tooltip.delay(300).fadeIn(0); + }, content: function() { var title = $(this).attr('title'); diff --git a/main.js b/main.js index e0af1db1..b190399e 100644 --- a/main.js +++ b/main.js @@ -57,8 +57,7 @@ document.getElementsByTagName('head')[0].innerHTML = '' + 'Ingress Intel Map' + '' + '' - + '' - + ''; + + ''; document.getElementsByTagName('body')[0].innerHTML = '' + '
Loading, please wait
' diff --git a/style.css b/style.css index 15a033d3..f179dc6a 100644 --- a/style.css +++ b/style.css @@ -450,10 +450,6 @@ h3 { border: 1px solid #666; } -.mods span[title=""] { - cursor: auto; -} - .res .mods span, .res .meter { border: 1px solid #0076b6; } @@ -616,3 +612,17 @@ aside:nth-child(odd) span { #largepreview img { border: 2px solid #f8ff5e; } + +/* tooltips */ +.ui-tooltip { + background: #1E425D; + border: 1px solid #20A8B1; + box-shadow:0 0 7px #000; + color: #EEEEEE; + font-family: Verdana, sans-serif; + font-size:13px; + max-width: 300px; + padding: 8px; + position: absolute; + z-index: 9999; +} From 43a6adad14675e1a5a186211fda5a3b9c2b8efd2 Mon Sep 17 00:00:00 2001 From: Stefan Breunig Date: Wed, 13 Feb 2013 04:59:36 +0100 Subject: [PATCH 15/15] make many variables overwritable by plugins --- main.js | 61 +++++++++++++++++++++++++++------------------------------ 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/main.js b/main.js index b190399e..320d0c9a 100644 --- a/main.js +++ b/main.js @@ -97,49 +97,55 @@ function wrapper() { L_PREFER_CANVAS = false; // CONFIG OPTIONS //////////////////////////////////////////////////// -var REFRESH = 30; // refresh view every 30s (base time) -var ZOOM_LEVEL_ADJ = 5; // add 5 seconds per zoom level -var REFRESH_GAME_SCORE = 5*60; // refresh game score every 5 minutes -var MAX_IDLE_TIME = 4; // stop updating map after 4min idling -var PRECACHE_PLAYER_NAMES_ZOOM = 17; // zoom level to start pre-resolving player names -var HIDDEN_SCROLLBAR_ASSUMED_WIDTH = 20; -var SIDEBAR_WIDTH = 300; +window.REFRESH = 30; // refresh view every 30s (base time) +window.ZOOM_LEVEL_ADJ = 5; // add 5 seconds per zoom level +window.REFRESH_GAME_SCORE = 5*60; // refresh game score every 5 minutes +window.MAX_IDLE_TIME = 4; // stop updating map after 4min idling +window.PRECACHE_PLAYER_NAMES_ZOOM = 17; // zoom level to start pre-resolving player names +window.HIDDEN_SCROLLBAR_ASSUMED_WIDTH = 20; +window.SIDEBAR_WIDTH = 300; // chat messages are requested for the visible viewport. On high zoom // levels this gets pretty pointless, so request messages in at least a // X km radius. -var CHAT_MIN_RANGE = 6; +window.CHAT_MIN_RANGE = 6; // this controls how far data is being drawn outside the viewport. Set // it 0 to only draw entities that intersect the current view. A value // of one will render an area twice the size of the viewport (or some- // thing like that, Leaflet doc isn’t too specific). Setting it too low // makes the missing data on move/zoom out more obvious. Setting it too // high causes too many items to be drawn, making drag&drop sluggish. -var VIEWPORT_PAD_RATIO = 0.3; +window.VIEWPORT_PAD_RATIO = 0.3; // how many items to request each query -var CHAT_PUBLIC_ITEMS = 200; -var CHAT_FACTION_ITEMS = 50; +window.CHAT_PUBLIC_ITEMS = 200; +window.CHAT_FACTION_ITEMS = 50; // how many pixels to the top before requesting new data -var CHAT_REQUEST_SCROLL_TOP = 200; +window.CHAT_REQUEST_SCROLL_TOP = 200; +window.CHAT_SHRINKED = 60; // Leaflet will get very slow for MANY items. It’s better to display // only some instead of crashing the browser. -var MAX_DRAWN_PORTALS = 1000; -var MAX_DRAWN_LINKS = 400; -var MAX_DRAWN_FIELDS = 200; +window.MAX_DRAWN_PORTALS = 1000; +window.MAX_DRAWN_LINKS = 400; +window.MAX_DRAWN_FIELDS = 200; +// Minimum zoom level resonator will display +window.RESONATOR_DISPLAY_ZOOM_LEVEL = 17; - -var COLOR_SELECTED_PORTAL = '#f00'; -var COLORS = ['#FFCE00', '#0088FF', '#03FE03']; // none, res, enl -var COLORS_LVL = ['#000', '#FECE5A', '#FFA630', '#FF7315', '#E40000', '#FD2992', '#EB26CD', '#C124E0', '#9627F4']; -var COLORS_MOD = {VERY_RARE: '#F78AF6', RARE: '#AD8AFF', COMMON: '#84FBBD'}; +window.COLOR_SELECTED_PORTAL = '#f00'; +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'}; // 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 // from this portal) -var ACCESS_INDICATOR_COLOR = 'orange'; -var RANGE_INDICATOR_COLOR = 'red'; +window.ACCESS_INDICATOR_COLOR = 'orange'; +window.RANGE_INDICATOR_COLOR = 'red'; + + +window.DEFAULT_PORTAL_IMG = 'http://commondatastorage.googleapis.com/ingress/img/default-portal-image.png'; +window.NOMINATIM = 'http://nominatim.openstreetmap.org/search?format=json&limit=1&q='; // INGRESS CONSTANTS ///////////////////////////////////////////////// // http://decodeingress.me/2012/11/18/ingress-portal-levels-and-link-range/ @@ -148,28 +154,19 @@ var MAX_XM_PER_LEVEL = [0, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]; var MIN_AP_FOR_LEVEL = [0, 10000, 30000, 70000, 150000, 300000, 600000, 1200000]; var HACK_RANGE = 40; // in meters, max. distance from portal to be able to access it var OCTANTS = ['E', 'NE', 'N', 'NW', 'W', 'SW', 'S', 'SE']; -var DEFAULT_PORTAL_IMG = 'http://commondatastorage.googleapis.com/ingress/img/default-portal-image.png'; var DESTROY_RESONATOR = 75; //AP for destroying portal var DESTROY_LINK = 187; //AP for destroying link var DESTROY_FIELD = 750; //AP for destroying field // OTHER MORE-OR-LESS CONSTANTS ////////////////////////////////////// -var NOMINATIM = 'http://nominatim.openstreetmap.org/search?format=json&limit=1&q='; -var DEG2RAD = Math.PI / 180; var TEAM_NONE = 0, TEAM_RES = 1, TEAM_ENL = 2; var TEAM_TO_CSS = ['none', 'res', 'enl']; var TYPE_UNKNOWN = 0, TYPE_PORTAL = 1, TYPE_LINK = 2, TYPE_FIELD = 3, TYPE_PLAYER = 4, TYPE_CHAT = 5, TYPE_RESONATOR = 6; -// make PLAYER variable available in site context -var PLAYER = window.PLAYER; -var CHAT_SHRINKED = 60; -// Minimum zoom level resonator will display -var RESONATOR_DISPLAY_ZOOM_LEVEL = 17; - -// Constants for resonator positioning var SLOT_TO_LAT = [0, Math.sqrt(2)/2, 1, Math.sqrt(2)/2, 0, -Math.sqrt(2)/2, -1, -Math.sqrt(2)/2]; var SLOT_TO_LNG = [1, Math.sqrt(2)/2, 0, -Math.sqrt(2)/2, -1, -Math.sqrt(2)/2, 0, Math.sqrt(2)/2]; var EARTH_RADIUS=6378137; +var DEG2RAD = Math.PI / 180; // STORAGE /////////////////////////////////////////////////////////// // global variables used for storage. Most likely READ ONLY. Proper