From fec4545eb064935c1618c36d341ff3e93c142195 Mon Sep 17 00:00:00 2001 From: Lapo Luchini Date: Thu, 28 Aug 2014 15:15:36 +0200 Subject: [PATCH 1/6] Add semicolons to close statements. --- plugins/uniques.user.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/plugins/uniques.user.js b/plugins/uniques.user.js index 6afd588b3..d4c52cbb3 100644 --- a/plugins/uniques.user.js +++ b/plugins/uniques.user.js @@ -67,7 +67,7 @@ window.plugin.uniques.onPortalDetailsUpdated = function() { $('#portaldetails > .imgpreview').after(plugin.uniques.contentHTML); plugin.uniques.updateCheckedAndHighlight(guid); -} +}; window.plugin.uniques.onPublicChatDataAvailable = function(data) { var nick = window.PLAYER.nickname; @@ -156,7 +156,7 @@ window.plugin.uniques.onPublicChatDataAvailable = function(data) { plugin.uniques.setPortalVisited(markup[1][1].guid); } }); -} +}; window.plugin.uniques.updateCheckedAndHighlight = function(guid) { if (guid == window.selectedPortal) { @@ -173,7 +173,7 @@ window.plugin.uniques.updateCheckedAndHighlight = function(guid) { window.setMarkerStyle (portals[guid], guid == selectedPortal); } } -} +}; window.plugin.uniques.setPortalVisited = function(guid) { @@ -189,7 +189,7 @@ window.plugin.uniques.setPortalVisited = function(guid) { plugin.uniques.updateCheckedAndHighlight(guid); plugin.uniques.sync(guid); -} +}; window.plugin.uniques.setPortalCaptured = function(guid) { var uniqueInfo = plugin.uniques.uniques[guid]; @@ -205,7 +205,7 @@ window.plugin.uniques.setPortalCaptured = function(guid) { plugin.uniques.updateCheckedAndHighlight(guid); plugin.uniques.sync(guid); -} +}; window.plugin.uniques.updateVisited = function(visited) { var guid = window.selectedPortal; @@ -226,7 +226,7 @@ window.plugin.uniques.updateVisited = function(visited) { plugin.uniques.updateCheckedAndHighlight(guid); plugin.uniques.sync(guid); -} +}; window.plugin.uniques.updateCaptured = function(captured) { var guid = window.selectedPortal; @@ -247,7 +247,7 @@ window.plugin.uniques.updateCaptured = function(captured) { plugin.uniques.updateCheckedAndHighlight(guid); plugin.uniques.sync(guid); -} +}; // stores the gived GUID for sync plugin.uniques.sync = function(guid) { @@ -255,7 +255,7 @@ plugin.uniques.sync = function(guid) { plugin.uniques.storeLocal('uniques'); plugin.uniques.storeLocal('updateQueue'); plugin.uniques.syncQueue(); -} +}; // sync the queue, but delay the actual sync to group a few updates in a single request window.plugin.uniques.syncQueue = function() { @@ -273,13 +273,13 @@ window.plugin.uniques.syncQueue = function() { plugin.sync.updateMap('uniques', 'uniques', Object.keys(plugin.uniques.updatingQueue)); }, plugin.uniques.SYNC_DELAY); -} +}; //Call after IITC and all plugin loaded window.plugin.uniques.registerFieldForSyncing = function() { if(!window.plugin.sync) return; window.plugin.sync.registerMapForSync('uniques', 'uniques', window.plugin.uniques.syncCallback, window.plugin.uniques.syncInitialed); -} +}; //Call after local or remote change uploaded window.plugin.uniques.syncCallback = function(pluginName, fieldName, e, fullUpdated) { @@ -314,7 +314,7 @@ window.plugin.uniques.syncCallback = function(pluginName, fieldName, e, fullUpda window.runHooks('pluginUniquesUpdateUniques', {guid: e.property}); } } -} +}; //syncing of the field is initialed, upload all queued update window.plugin.uniques.syncInitialed = function(pluginName, fieldName) { @@ -324,7 +324,7 @@ window.plugin.uniques.syncInitialed = function(pluginName, fieldName) { plugin.uniques.syncQueue(); } } -} +}; window.plugin.uniques.storeLocal = function(name) { var key = window.plugin.uniques.FIELDS[name]; @@ -337,7 +337,7 @@ window.plugin.uniques.storeLocal = function(name) { } else { localStorage.removeItem(key); } -} +}; window.plugin.uniques.loadLocal = function(name) { var key = window.plugin.uniques.FIELDS[name]; @@ -346,7 +346,7 @@ window.plugin.uniques.loadLocal = function(name) { if(localStorage[key] !== undefined) { plugin.uniques[name] = JSON.parse(localStorage[key]); } -} +}; /***************************************************************************************************************************************************************/ /** HIGHLIGHTER ************************************************************************************************************************************************/ @@ -383,7 +383,7 @@ window.plugin.uniques.highlighter = { setSelected: function(active) { window.plugin.uniques.isHighlightActive = active; } -} +}; window.plugin.uniques.setupCSS = function() { @@ -391,7 +391,7 @@ window.plugin.uniques.setupCSS = function() { .prop("type", "text/css") .html("@@INCLUDESTRING:plugins/uniques.css@@") .appendTo("head"); -} +}; window.plugin.uniques.setupContent = function() { plugin.uniques.contentHTML = '
' @@ -399,7 +399,7 @@ window.plugin.uniques.setupContent = function() { + '' + '
'; plugin.uniques.disabledMessage = '
Plugin Uniques disabled
'; -} +}; var setup = function() { if($.inArray('pluginUniquesUpdateUniques', window.VALID_HOOKS) < 0) @@ -413,7 +413,7 @@ var setup = function() { window.addHook('publicChatDataAvailable', window.plugin.uniques.onPublicChatDataAvailable); window.addHook('iitcLoaded', window.plugin.uniques.registerFieldForSyncing); window.addPortalHighlighter('Uniques', window.plugin.uniques.highlighter); -} +}; //PLUGIN END ////////////////////////////////////////////////////////// From 36d8187cc8d8ad528c854f9016f0de6bf61fc6b6 Mon Sep 17 00:00:00 2001 From: Lapo Luchini Date: Thu, 28 Aug 2014 15:18:06 +0200 Subject: [PATCH 2/6] Keep date of the current capture of the portal. --- plugins/uniques.user.js | 52 +++++++++++++++++++++++++++++++++++------ 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/plugins/uniques.user.js b/plugins/uniques.user.js index d4c52cbb3..fc34ffc39 100644 --- a/plugins/uniques.user.js +++ b/plugins/uniques.user.js @@ -59,6 +59,7 @@ window.plugin.uniques.onPortalDetailsUpdated = function() { return entity && entity.owner == nickname; } + plugin.uniques.resetCaptured(guid); if(details.resonators.some(installedByPlayer) || details.mods.some(installedByPlayer)) { plugin.uniques.updateVisited(true); } @@ -73,6 +74,7 @@ window.plugin.uniques.onPublicChatDataAvailable = function(data) { var nick = window.PLAYER.nickname; data.raw.success.forEach(function(msg) { var plext = msg[2].plext, + time = msg[1], markup = plext.markup; // search for "x deployed an Ly Resonator on z" @@ -97,7 +99,7 @@ window.plugin.uniques.onPublicChatDataAvailable = function(data) { && markup[1][0] == 'TEXT' && markup[1][1].plain == ' captured ' && markup[2][0] == 'PORTAL') { - plugin.uniques.setPortalCaptured(markup[2][1].guid); + plugin.uniques.setPortalCaptured(markup[2][1].guid, time); } // search for "x linked y to z" @@ -153,19 +155,35 @@ window.plugin.uniques.onPublicChatDataAvailable = function(data) { && markup[2][0] == 'TEXT' && (markup[2][1].plain == ' neutralized by ' || markup[2][1].plain == ' is under attack by ') && markup[3][0] == 'PLAYER') { - plugin.uniques.setPortalVisited(markup[1][1].guid); + plugin.uniques.setPortalVisited(markup[1][1].guid); //TODO: maybe even captured? + if (markup[2][1].plain == ' neutralized by ') + plugin.uniques.resetCaptured(markup[1][1].guid); } }); }; +function timeDiff(time) { + var d = (Date.now() - time) / 3600000; + if (d < 24) + return d.toFixed(1) + ' hours'; + d /= 24; + return d.toFixed(1) + ' days'; +} + window.plugin.uniques.updateCheckedAndHighlight = function(guid) { if (guid == window.selectedPortal) { var uniqueInfo = plugin.uniques.uniques[guid]; visited = (uniqueInfo && uniqueInfo.visited) || false, - captured = (uniqueInfo && uniqueInfo.captured) || false; + captured = (uniqueInfo && uniqueInfo.captured) || false, + since = (uniqueInfo && uniqueInfo.captured && uniqueInfo.since) || 0; + console.log('XXX-display', uniqueInfo); $('#visited').prop('checked', visited); $('#captured').prop('checked', captured); + if (since) + $('#capturedSince').text(' (' + timeDiff(since) + ')'); + else + $('#capturedSince').empty(); } if (window.plugin.uniques.isHighlightActive) { @@ -175,7 +193,6 @@ window.plugin.uniques.updateCheckedAndHighlight = function(guid) { } }; - window.plugin.uniques.setPortalVisited = function(guid) { var uniqueInfo = plugin.uniques.uniques[guid]; if (uniqueInfo) { @@ -191,17 +208,33 @@ window.plugin.uniques.setPortalVisited = function(guid) { plugin.uniques.sync(guid); }; -window.plugin.uniques.setPortalCaptured = function(guid) { +window.plugin.uniques.setPortalCaptured = function(guid, since) { var uniqueInfo = plugin.uniques.uniques[guid]; + console.log('XXX-setCaptured-1', JSON.stringify(uniqueInfo)); if (uniqueInfo) { uniqueInfo.visited = true; uniqueInfo.captured = true; + uniqueInfo.since = since || uniqueInfo.since || Date.now(); } else { plugin.uniques.uniques[guid] = { visited: true, - captured: true + captured: true, + since: since || Date.now() }; } + console.log('XXX-setCaptured-2', JSON.stringify(plugin.uniques.uniques[guid])); + + plugin.uniques.updateCheckedAndHighlight(guid); + plugin.uniques.sync(guid); +}; + +window.plugin.uniques.resetCaptured = function(guid) { + var uniqueInfo = plugin.uniques.uniques[guid]; + console.log('XXX-resetCaptured-1', JSON.stringify(uniqueInfo)); + if (!uniqueInfo || !uniqueInfo.since) + return; + delete uniqueInfo.since; + console.log('XXX-resetCaptured-2', JSON.stringify(uniqueInfo)); plugin.uniques.updateCheckedAndHighlight(guid); plugin.uniques.sync(guid); @@ -222,15 +255,17 @@ window.plugin.uniques.updateVisited = function(visited) { } else { // not visited --> not captured uniqueInfo.visited = false; uniqueInfo.captured = false; + delete uniqueInfo.since; } plugin.uniques.updateCheckedAndHighlight(guid); plugin.uniques.sync(guid); -}; +} window.plugin.uniques.updateCaptured = function(captured) { var guid = window.selectedPortal; var uniqueInfo = plugin.uniques.uniques[guid]; + console.log('XXX-updateCaptured-1', JSON.stringify(uniqueInfo)); if (!uniqueInfo) { plugin.uniques.uniques[guid] = uniqueInfo = { visited: false, @@ -241,9 +276,12 @@ window.plugin.uniques.updateCaptured = function(captured) { if (captured) { // captured --> visited uniqueInfo.captured = true; uniqueInfo.visited = true; + uniqueInfo.since = uniqueInfo.since || Date.now(); } else { uniqueInfo.captured = false; + delete uniqueInfo.since; } + console.log('XXX-updateCaptured-2', JSON.stringify(uniqueInfo)); plugin.uniques.updateCheckedAndHighlight(guid); plugin.uniques.sync(guid); From 386f3139f6fb5e1c4f1aa0b8584a17c7b0cda722 Mon Sep 17 00:00:00 2001 From: Lapo Luchini Date: Thu, 4 Sep 2014 20:55:54 +0200 Subject: [PATCH 3/6] Add highlight color for currently owned portals. --- plugins/uniques.user.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/uniques.user.js b/plugins/uniques.user.js index fc34ffc39..c1b809cb8 100644 --- a/plugins/uniques.user.js +++ b/plugins/uniques.user.js @@ -398,8 +398,11 @@ window.plugin.uniques.highlighter = { if (uniqueInfo) { if (uniqueInfo.captured) { + if (uniqueInfo.since) { + style.fillColor = 'white'; + style.fillOpacity = 0.7; + } // captured (and, implied, visited too) - no highlights - } else if (uniqueInfo.visited) { style.fillColor = 'yellow'; style.fillOpacity = 0.6; From de180bc1c210f863e18135003fc355f3180e3223 Mon Sep 17 00:00:00 2001 From: Lapo Luchini Date: Fri, 5 Sep 2014 00:03:21 +0200 Subject: [PATCH 4/6] Reset portal capture time when someone else conquers it. --- plugins/uniques.user.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/uniques.user.js b/plugins/uniques.user.js index c1b809cb8..92efe53b2 100644 --- a/plugins/uniques.user.js +++ b/plugins/uniques.user.js @@ -95,11 +95,13 @@ window.plugin.uniques.onPublicChatDataAvailable = function(data) { if(plext.plextType == 'SYSTEM_BROADCAST' && markup.length==3 && markup[0][0] == 'PLAYER' - && markup[0][1].plain == nick && markup[1][0] == 'TEXT' && markup[1][1].plain == ' captured ' && markup[2][0] == 'PORTAL') { - plugin.uniques.setPortalCaptured(markup[2][1].guid, time); + if (markup[0][1].plain == nick) + plugin.uniques.setPortalCaptured(markup[2][1].guid, time); + else + plugin.uniques.resetCaptured(markup[2][1].guid); } // search for "x linked y to z" @@ -157,7 +159,7 @@ window.plugin.uniques.onPublicChatDataAvailable = function(data) { && markup[3][0] == 'PLAYER') { plugin.uniques.setPortalVisited(markup[1][1].guid); //TODO: maybe even captured? if (markup[2][1].plain == ' neutralized by ') - plugin.uniques.resetCaptured(markup[1][1].guid); + plugin.uniques.resetCaptured(markup[1][1].guid); } }); }; From 931126f023cec75d0bb8b42210c50eb20384da0e Mon Sep 17 00:00:00 2001 From: Lapo Luchini Date: Fri, 12 Sep 2014 14:08:41 +0200 Subject: [PATCH 5/6] Reset capture using simple faction data available during view. --- plugins/uniques.user.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/uniques.user.js b/plugins/uniques.user.js index 92efe53b2..35d36c527 100644 --- a/plugins/uniques.user.js +++ b/plugins/uniques.user.js @@ -398,8 +398,11 @@ window.plugin.uniques.highlighter = { var style = {}; + console.log(data.portal.options.ent[2].team); if (uniqueInfo) { if (uniqueInfo.captured) { + if (uniqueInfo.since && data.portal.options.ent[2].team != window.PLAYER.team) + plugin.uniques.resetCaptured(guid); if (uniqueInfo.since) { style.fillColor = 'white'; style.fillOpacity = 0.7; From d8151c0b11b7ed254d0fc5d3ec12cff088910665 Mon Sep 17 00:00:00 2001 From: Lapo Luchini Date: Fri, 19 Sep 2014 21:56:44 +0200 Subject: [PATCH 6/6] Show the capture duration in portal details. --- plugins/uniques.user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/uniques.user.js b/plugins/uniques.user.js index 518065954..6a3ca50f5 100755 --- a/plugins/uniques.user.js +++ b/plugins/uniques.user.js @@ -462,7 +462,7 @@ window.plugin.uniques.setupCSS = function() { window.plugin.uniques.setupContent = function() { plugin.uniques.contentHTML = '
' + '' - + '' + + '' + '
'; plugin.uniques.disabledMessage = '
Plugin Uniques disabled
'; };