Merge pull request #667 from fkloft/guess-player-levels
guess-player-levels
This commit is contained in:
commit
07c3e3216e
@ -2,7 +2,7 @@
|
|||||||
// @id iitc-plugin-guess-player-levels@breunigs
|
// @id iitc-plugin-guess-player-levels@breunigs
|
||||||
// @name IITC plugin: guess player level
|
// @name IITC plugin: guess player level
|
||||||
// @category Info
|
// @category Info
|
||||||
// @version 0.4.10.@@DATETIMEVERSION@@
|
// @version 0.5.0.@@DATETIMEVERSION@@
|
||||||
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
|
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
|
||||||
// @updateURL @@UPDATEURL@@
|
// @updateURL @@UPDATEURL@@
|
||||||
// @downloadURL @@DOWNLOADURL@@
|
// @downloadURL @@DOWNLOADURL@@
|
||||||
@ -27,6 +27,7 @@ window.plugin.guessPlayerLevels = function() {};
|
|||||||
window.plugin.guessPlayerLevels.setupCallback = function() {
|
window.plugin.guessPlayerLevels.setupCallback = function() {
|
||||||
$('#toolbox').append(' <a onclick="window.plugin.guessPlayerLevels.guess()" title="Show player level guesses based on resonator placement in displayed portals">Guess player levels</a>');
|
$('#toolbox').append(' <a onclick="window.plugin.guessPlayerLevels.guess()" title="Show player level guesses based on resonator placement in displayed portals">Guess player levels</a>');
|
||||||
addHook('portalDetailLoaded', window.plugin.guessPlayerLevels.extractPortalData);
|
addHook('portalDetailLoaded', window.plugin.guessPlayerLevels.extractPortalData);
|
||||||
|
addHook('publicChatDataAvailable', window.plugin.guessPlayerLevels.extractChatData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -34,37 +35,64 @@ window.plugin.guessPlayerLevels.setupCallback = function() {
|
|||||||
window.plugin.guessPlayerLevels.fetchLevelByPlayer = function(nick) {
|
window.plugin.guessPlayerLevels.fetchLevelByPlayer = function(nick) {
|
||||||
var cache = window.plugin.guessPlayerLevels._nameToLevelCache;
|
var cache = window.plugin.guessPlayerLevels._nameToLevelCache;
|
||||||
|
|
||||||
if(cache["#" + nick] === undefined) {
|
if(cache['#' + nick] === undefined)
|
||||||
// no use in reading localStorage repeatedly
|
cache = window.plugin.guessPlayerLevels._loadLevels();
|
||||||
if(window.plugin.guessPlayerLevels._localStorageLastUpdate < Date.now() - 10*1000) {
|
|
||||||
try {
|
|
||||||
cache = JSON.parse(localStorage["plugin-guess-player-levels"])
|
|
||||||
window.plugin.guessPlayerLevels._nameToLevelCache = cache;
|
|
||||||
window.plugin.guessPlayerLevels._localStorageLastUpdate = Date.now();
|
|
||||||
} catch(e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return cache["#" + nick];
|
var details = cache['#' + nick];
|
||||||
|
if(details === undefined)
|
||||||
|
return 1;
|
||||||
|
if(typeof details === 'number')
|
||||||
|
return details;
|
||||||
|
return details.guessed;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function is intended to be called by other plugins
|
||||||
|
window.plugin.guessPlayerLevels.fetchLevelDetailsByPlayer = function(nick) {
|
||||||
|
var cache = window.plugin.guessPlayerLevels._nameToLevelCache;
|
||||||
|
|
||||||
|
if(cache['#' + nick] === undefined)
|
||||||
|
cache = window.plugin.guessPlayerLevels._loadLevels();
|
||||||
|
|
||||||
|
var details = cache['#' + nick];
|
||||||
|
if(details === undefined)
|
||||||
|
return {min: 1, guessed: 1};
|
||||||
|
if(typeof details === 'number')
|
||||||
|
return {min: 1, guessed: details};
|
||||||
|
return details;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.plugin.guessPlayerLevels._nameToLevelCache = {};
|
window.plugin.guessPlayerLevels._nameToLevelCache = {};
|
||||||
window.plugin.guessPlayerLevels._localStorageLastUpdate = 0;
|
window.plugin.guessPlayerLevels._localStorageLastUpdate = 0;
|
||||||
|
|
||||||
|
window.plugin.guessPlayerLevels._loadLevels = function() {
|
||||||
|
// no use in reading localStorage repeatedly
|
||||||
|
if(window.plugin.guessPlayerLevels._localStorageLastUpdate < Date.now() - 10*1000) {
|
||||||
|
try {
|
||||||
|
var cache = JSON.parse(localStorage['plugin-guess-player-levels'])
|
||||||
|
window.plugin.guessPlayerLevels._nameToLevelCache = cache;
|
||||||
|
window.plugin.guessPlayerLevels._localStorageLastUpdate = Date.now();
|
||||||
|
} catch(e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return window.plugin.guessPlayerLevels._nameToLevelCache;
|
||||||
|
}
|
||||||
|
|
||||||
window.plugin.guessPlayerLevels.setLevelTitle = function(dom) {
|
window.plugin.guessPlayerLevels.setLevelTitle = function(dom) {
|
||||||
// expects dom node with nick in its child text node
|
// expects dom node with nick in its child text node
|
||||||
|
|
||||||
var el = $(dom);
|
var el = $(dom);
|
||||||
var nick = el.text();
|
var nick = el.text();
|
||||||
|
|
||||||
var level = window.plugin.guessPlayerLevels.fetchLevelByPlayer(nick);
|
var details = window.plugin.guessPlayerLevels.fetchLevelDetailsByPlayer(nick);
|
||||||
|
|
||||||
var text;
|
var text;
|
||||||
if (level) {
|
if(details.min == 8)
|
||||||
text = 'Min player level: ' + level + ' (guessed)';
|
text = 'Player level: 8';
|
||||||
} else {
|
else {
|
||||||
text = 'Min player level unknown';
|
text = 'Min player level: ' + details.min;
|
||||||
|
if(details.min != details.guessed)
|
||||||
|
text += '\nGuessed player level: ' + details.guessed;
|
||||||
}
|
}
|
||||||
window.setupTooltips(el);
|
window.setupTooltips(el);
|
||||||
|
|
||||||
@ -81,7 +109,7 @@ window.plugin.guessPlayerLevels.setLevelTitle = function(dom) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.plugin.guessPlayerLevels.setupChatNickHelper = function() {
|
window.plugin.guessPlayerLevels.setupChatNickHelper = function() {
|
||||||
$(document).on('mouseenter', '.nickname', function() {
|
$(document).on('mouseenter', '.nickname, .pl_nudge_player', function() {
|
||||||
window.plugin.guessPlayerLevels.setLevelTitle(this);
|
window.plugin.guessPlayerLevels.setLevelTitle(this);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -121,12 +149,49 @@ window.plugin.guessPlayerLevels.extractPortalData = function(data) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
window.plugin.guessPlayerLevels.savePlayerLevel = function(nick, level) {
|
window.plugin.guessPlayerLevels.extractChatData = function(data) {
|
||||||
var stored = window.plugin.guessPlayerLevels.fetchLevelByPlayer(nick);
|
data.raw.result.forEach(function(msg) {
|
||||||
if(stored && stored >= level)
|
var plext = msg[2].plext;
|
||||||
return;
|
if(plext.plextType == 'SYSTEM_BROADCAST'
|
||||||
|
&& plext.markup.length==5
|
||||||
|
&& plext.markup[0][0] == 'PLAYER'
|
||||||
|
&& plext.markup[1][0] == 'TEXT'
|
||||||
|
&& plext.markup[1][1].plain == ' deployed an '
|
||||||
|
&& plext.markup[2][0] == 'TEXT'
|
||||||
|
&& plext.markup[2][0] == 'TEXT'
|
||||||
|
&& plext.markup[3][0] == 'TEXT'
|
||||||
|
&& plext.markup[3][1].plain == ' Resonator on ') {
|
||||||
|
var nick = plext.markup[0][1].plain;
|
||||||
|
var lvl = parseInt(plext.markup[2][1].plain.substr(1));
|
||||||
|
window.plugin.guessPlayerLevels.savePlayerLevel(nick, lvl, true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
window.plugin.guessPlayerLevels._nameToLevelCache["#" + nick] = level;
|
window.plugin.guessPlayerLevels.savePlayerLevel = function(nick, level, safe) {
|
||||||
|
var cache = window.plugin.guessPlayerLevels._loadLevels();
|
||||||
|
|
||||||
|
var details = cache['#' + nick];
|
||||||
|
if(details === undefined)
|
||||||
|
details = {min: 1, guessed: 1};
|
||||||
|
if(typeof details === 'number')
|
||||||
|
details = {min: 1, guessed: details};
|
||||||
|
|
||||||
|
if(safe) {
|
||||||
|
if(details.min >= level)
|
||||||
|
return;
|
||||||
|
|
||||||
|
details.min = level;
|
||||||
|
if(details.guessed < details.min)
|
||||||
|
details.guessed = details.min;
|
||||||
|
} else {
|
||||||
|
if(details.guessed >= level)
|
||||||
|
return;
|
||||||
|
|
||||||
|
details.guessed = level;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.plugin.guessPlayerLevels._nameToLevelCache['#' + nick] = details;
|
||||||
|
|
||||||
// to minimize accesses to localStorage, writing is delayed a bit
|
// to minimize accesses to localStorage, writing is delayed a bit
|
||||||
|
|
||||||
@ -134,7 +199,7 @@ window.plugin.guessPlayerLevels.savePlayerLevel = function(nick, level) {
|
|||||||
clearTimeout(window.plugin.guessPlayerLevels._writeTimeout);
|
clearTimeout(window.plugin.guessPlayerLevels._writeTimeout);
|
||||||
|
|
||||||
window.plugin.guessPlayerLevels._writeTimeout = setTimeout(function() {
|
window.plugin.guessPlayerLevels._writeTimeout = setTimeout(function() {
|
||||||
localStorage["plugin-guess-player-levels"] = JSON.stringify(window.plugin.guessPlayerLevels._nameToLevelCache);
|
localStorage['plugin-guess-player-levels'] = JSON.stringify(window.plugin.guessPlayerLevels._nameToLevelCache);
|
||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +277,7 @@ window.plugin.guessPlayerLevels.guess = function() {
|
|||||||
buttons: {
|
buttons: {
|
||||||
'RESET GUESSES': function() {
|
'RESET GUESSES': function() {
|
||||||
// clear all guessed levels from local storage
|
// clear all guessed levels from local storage
|
||||||
localStorage.removeItem("plugin-guess-player-levels")
|
localStorage.removeItem('plugin-guess-player-levels')
|
||||||
window.plugin.guessPlayerLevels._nameToLevelCache = {}
|
window.plugin.guessPlayerLevels._nameToLevelCache = {}
|
||||||
// now force all portals through the callback manually
|
// now force all portals through the callback manually
|
||||||
$.each(window.portals, function(guid,p) {
|
$.each(window.portals, function(guid,p) {
|
||||||
@ -243,7 +308,7 @@ var setup = function() {
|
|||||||
// we used to sture level guesses as one localStorage key per player, named 'level-PLAYER_GUID'
|
// we used to sture level guesses as one localStorage key per player, named 'level-PLAYER_GUID'
|
||||||
// they're now stored in a single storage key - 'plugin-guess-player-levels' - so clear these old entries
|
// they're now stored in a single storage key - 'plugin-guess-player-levels' - so clear these old entries
|
||||||
$.each(Object.keys(localStorage), function(ind,key) {// legacy code - should be removed in the future
|
$.each(Object.keys(localStorage), function(ind,key) {// legacy code - should be removed in the future
|
||||||
if(key.lastIndexOf("level-",0)===0) {
|
if(key.lastIndexOf('level-',0)===0) {
|
||||||
localStorage.removeItem(key);
|
localStorage.removeItem(key);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
// @id iitc-plugin-player-tracker@breunigs
|
// @id iitc-plugin-player-tracker@breunigs
|
||||||
// @name IITC Plugin: Player tracker
|
// @name IITC Plugin: Player tracker
|
||||||
// @category Layer
|
// @category Layer
|
||||||
// @version 0.10.1.@@DATETIMEVERSION@@
|
// @version 0.10.2.@@DATETIMEVERSION@@
|
||||||
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
|
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
|
||||||
// @updateURL @@UPDATEURL@@
|
// @updateURL @@UPDATEURL@@
|
||||||
// @downloadURL @@DOWNLOADURL@@
|
// @downloadURL @@DOWNLOADURL@@
|
||||||
@ -311,16 +311,22 @@ window.plugin.playerTracker.drawData = function() {
|
|||||||
var popup = '<span class="nickname '+cssClass+'" style="font-weight:bold;">' + playerData.nick + '</span>';
|
var popup = '<span class="nickname '+cssClass+'" style="font-weight:bold;">' + playerData.nick + '</span>';
|
||||||
|
|
||||||
if(window.plugin.guessPlayerLevels !== undefined &&
|
if(window.plugin.guessPlayerLevels !== undefined &&
|
||||||
window.plugin.guessPlayerLevels.fetchLevelByPlayer !== undefined) {
|
window.plugin.guessPlayerLevels.fetchLevelDetailsByPlayer !== undefined) {
|
||||||
var playerLevel = window.plugin.guessPlayerLevels.fetchLevelByPlayer(pguid);
|
function getLevel(lvl) {
|
||||||
if(playerLevel !== undefined) {
|
return '<span style="padding:4px;color:white;background-color:'+COLORS_LVL[lvl]+'">'+lvl+'</span>';
|
||||||
popup += '<span style="font-weight:bold;margin-left:10px;">Level '
|
|
||||||
+ playerLevel
|
|
||||||
+ ' (guessed)'
|
|
||||||
+ '</span>';
|
|
||||||
} else {
|
|
||||||
popup += '<span style="font-weight:bold;margin-left:10px;">Level unknown</span>'
|
|
||||||
}
|
}
|
||||||
|
popup += '<span style="font-weight:bold;margin-left:10px;">';
|
||||||
|
|
||||||
|
var playerLevelDetails = window.plugin.guessPlayerLevels.fetchLevelDetailsByPlayer(pguid);
|
||||||
|
if(playerLevelDetails.min == 8) {
|
||||||
|
popup += 'Level ' + getLevel(8);
|
||||||
|
} else {
|
||||||
|
popup += 'Min level: ' + getLevel(playerLevelDetails.min);
|
||||||
|
if(playerLevelDetails.min != playerLevelDetails.guessed)
|
||||||
|
popup += ', guessed level: ' + getLevel(playerLevelDetails.guessed);
|
||||||
|
}
|
||||||
|
|
||||||
|
popup += '</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
popup += '<br>'
|
popup += '<br>'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user