Improvements to passcode redeeming
- use text color instead of background, with font-weight:bold and a small shadow - short format for passcodes
This commit is contained in:
parent
4827c9ac1b
commit
1f13ec3001
@ -1,178 +1,22 @@
|
|||||||
// REDEEMING ///////////////////////////////////////////////////////
|
// REDEEMING ///////////////////////////////////////////////////////
|
||||||
// Heuristic passcode redemption that tries to guess unknown items /
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// TODO remove lots of unused code from the old redeeming method
|
// TODO remove lots of unused code from the old redeeming method
|
||||||
|
|
||||||
/* Abbreviates redemption items.
|
window.REDEEM_SHORT_NAMES = {
|
||||||
* Example: VERY_RARE => VR
|
'portal shield':'S',
|
||||||
*/
|
'force amp':'FA',
|
||||||
window.REDEEM_ABBREVIATE = function(tag) {return tag.split('_').map(function (i) {return i[0];}).join('');};
|
'link amp':'LA',
|
||||||
|
'heatsink':'H',
|
||||||
/* Resource type names mapped to actual names and abbreviations.
|
'multihack':'M',
|
||||||
* Add more here if necessary.
|
'turret':'T',
|
||||||
* Sometimes, items will have more information than just a level. Allow for specialization.
|
'unusual object':'U',
|
||||||
*/
|
'resonator':'R',
|
||||||
window.REDEEM_RESOURCES = {
|
'xmp burster':'X',
|
||||||
RES_SHIELD: {
|
'power cube':'C',
|
||||||
/* modResource */
|
'media':'M',
|
||||||
format: function(acquired) {
|
'ultra strike':'US',
|
||||||
return {long: 'Portal Shield', short: 'S'};
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
FORCE_AMP: {
|
|
||||||
format: function(acquired) {
|
|
||||||
return {long: 'Force Amp', short: 'FA'};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
LINK_AMP: {
|
|
||||||
format: function(acquired) {
|
|
||||||
return {long: 'Link Amp', short: 'LA'};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
HEATSINK: {
|
|
||||||
format: function(acquired) {
|
|
||||||
return {long: 'Heatsink', short: 'H'};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
MULTIHACK: {
|
|
||||||
format: function(acquired) {
|
|
||||||
return {long: 'Multihack', short: 'M'};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
TURRET: {
|
|
||||||
format: function(acquired) {
|
|
||||||
return {long: 'Turret', short: 'T'};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
UNUSUAL: {
|
|
||||||
format: function(acquired) {
|
|
||||||
return {long: 'Unusual Object', short: 'U'};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
EMITTER_A: {
|
|
||||||
/* resourceWithLevels */
|
|
||||||
format: function(acquired) {
|
|
||||||
return {long: 'Resonator', short: 'R'};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
EMP_BURSTER: {
|
|
||||||
/* resourceWithLevels */
|
|
||||||
format: function(acquired) {
|
|
||||||
return {long: 'XMP Burster', short: 'X'};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
POWER_CUBE: {
|
|
||||||
/* resourceWithLevels */
|
|
||||||
format: function(acquired) {
|
|
||||||
return {long: 'Power Cube', short: 'C'};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
MEDIA: {
|
|
||||||
/* resourceWithLevels */
|
|
||||||
format: function(acquired) {
|
|
||||||
return {
|
|
||||||
long: 'Media: <a href="' + (acquired.storyItem.primaryUrl || '#') + '" target="_blank">' + (acquired.storyItem.shortDescription || 'UNKNOWN') + '</a>',
|
|
||||||
short: 'M'
|
|
||||||
};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
FLIP_CARD: {
|
|
||||||
decode: function(type, acquired, key) {
|
|
||||||
/* ADA or JARVIS */
|
|
||||||
return acquired.flipCard.flipCardType;
|
|
||||||
},
|
|
||||||
format: function(acquired) {
|
|
||||||
var type = acquired.flipCard.flipCardType;
|
|
||||||
return {
|
|
||||||
long: type,
|
|
||||||
short: ({ADA: 'AR', JARVIS: 'JV'}[type] || 'FC'),
|
|
||||||
prefix: '<span title="' + (acquired.displayName ? (acquired.displayName.displayDescription || '') : '') + '" class="' + ({ADA: 'res', JARVIS: 'enl'}[type] || '') + '">',
|
|
||||||
suffix: '</span>'
|
|
||||||
};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
PORTAL_LINK_KEY: {
|
|
||||||
decode: function(type, acquired, key) {
|
|
||||||
/* A unique identifier for this portal. */
|
|
||||||
return acquired.portalCoupler.portalGuid;
|
|
||||||
},
|
|
||||||
format: function(acquired) {
|
|
||||||
return {
|
|
||||||
long: 'Portal Key: ' + acquired.portalCoupler.portalTitle || 'Unknown Portal',
|
|
||||||
short: 'K'
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Redemption "handlers" handle decoding and formatting for rewards.
|
|
||||||
*
|
|
||||||
* Redemption "decoders" are used for returning the primary attribute (key) from
|
|
||||||
* different types of items. Pretty self-explanatory.
|
|
||||||
*
|
|
||||||
* Redemption "formatters" are used for formatting specific types of password rewards.
|
|
||||||
* Right now, Ingress has resourceWithLevels (leveled resources) and modResource (mods).
|
|
||||||
* Resources with levels have levels, and mods have rarity. Format them appropriately.
|
|
||||||
*/
|
|
||||||
window.REDEEM_HANDLERS = {
|
|
||||||
resource: {
|
|
||||||
decode: function(type, acquired, key) {return 'RESOURCE';},
|
|
||||||
format: function(acquired, group) {
|
|
||||||
var prefix = acquired.str.prefix || '';
|
|
||||||
var suffix = acquired.str.suffix || '';
|
|
||||||
return {
|
|
||||||
table: '<td>+</td><td>' + prefix + acquired.str.long + suffix + ' [' + acquired.count + ']</td>',
|
|
||||||
html: acquired.count + '×' + prefix + acquired.str.short + suffix,
|
|
||||||
plain: acquired.count + '@' + acquired.str.short
|
|
||||||
};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// A leveled resource, such as XMPs, resonators, or power cubes.
|
|
||||||
resourceWithLevels: {
|
|
||||||
decode: function(type, acquired, key) {return acquired[key].level;},
|
|
||||||
format: function(acquired, level) {
|
|
||||||
var prefix = '<span style="color: ' + (window.COLORS_LVL[level] || 'white') + ';">';
|
|
||||||
var suffix = '</span>';
|
|
||||||
return {
|
|
||||||
table: '<td>' + prefix + 'L' + level + suffix + '</td><td>' + acquired.str.long + ' [' + acquired.count + ']</td>',
|
|
||||||
html: acquired.count + '×' + acquired.str.short + prefix + level + suffix,
|
|
||||||
plain: acquired.count + '@' + acquired.str.short + level
|
|
||||||
};
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// A mod, such as portal shields or link amplifiers.
|
|
||||||
modResource: {
|
|
||||||
decode: function(type, acquired, key) {return acquired[key].rarity;},
|
|
||||||
format: function(acquired, rarity) {
|
|
||||||
var prefix = '<span style="color: ' + (window.COLORS_MOD[rarity] || 'white') + ';">';
|
|
||||||
var suffix = '</span>';
|
|
||||||
var abbreviation = window.REDEEM_ABBREVIATE(rarity);
|
|
||||||
return {
|
|
||||||
table: '<td>' + prefix + abbreviation + suffix + '</td><td>' + acquired.str.long + ' [' + acquired.count + ']</td>',
|
|
||||||
html: acquired.count + '×' + acquired.str.short + ':' + prefix + abbreviation + suffix,
|
|
||||||
plain: acquired.count + '@' + acquired.str.short + ':' + abbreviation
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Redemption "hints" hint at what an unknown resource might be from its object properties.
|
|
||||||
*/
|
|
||||||
window.REDEEM_HINTS = {
|
|
||||||
level: 'resourceWithLevels',
|
|
||||||
rarity: 'modResource'
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Redemption errors. Very self-explanatory.
|
|
||||||
*/
|
|
||||||
window.REDEEM_ERRORS = {
|
|
||||||
ALREADY_REDEEMED: 'The passcode has already been redeemed.',
|
|
||||||
ALREADY_REDEEMED_BY_PLAYER : 'You have already redeemed this passcode.',
|
|
||||||
INVALID_PASSCODE: 'This passcode is invalid.'
|
|
||||||
};
|
|
||||||
|
|
||||||
/* These are HTTP status codes returned by the redemption API.
|
/* These are HTTP status codes returned by the redemption API.
|
||||||
* TODO: Move to another file? Use more generally across IITC?
|
* TODO: Move to another file? Use more generally across IITC?
|
||||||
@ -182,21 +26,8 @@ window.REDEEM_STATUSES = {
|
|||||||
500: 'Internal server error'
|
500: 'Internal server error'
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Encouragement for people who got it in.
|
|
||||||
* Just for fun.
|
|
||||||
*/
|
|
||||||
window.REDEEM_ENCOURAGEMENT = [
|
|
||||||
"Passcode accepted!",
|
|
||||||
"Access granted.",
|
|
||||||
"Resources acquired.",
|
|
||||||
"Power up!",
|
|
||||||
"Asset transfer in progress.",
|
|
||||||
"Well done, Agent.",
|
|
||||||
"Make the " + {'RESISTANCE' : 'Resistance', 'ENLIGHTENED' : 'Enlightened'}[PLAYER.team] + " proud!"
|
|
||||||
];
|
|
||||||
|
|
||||||
window.handleRedeemResponse = function(data, textStatus, jqXHR) {
|
window.handleRedeemResponse = function(data, textStatus, jqXHR) {
|
||||||
var passcode = this.passcode, to_dialog, dialog_title;
|
var passcode = this.passcode;
|
||||||
|
|
||||||
if(data.error) {
|
if(data.error) {
|
||||||
dialog({
|
dialog({
|
||||||
@ -206,14 +37,42 @@ window.handleRedeemResponse = function(data, textStatus, jqXHR) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var encouragement = window.REDEEM_ENCOURAGEMENT[Math.floor(Math.random() * window.REDEEM_ENCOURAGEMENT.length)];
|
var format = "long";
|
||||||
|
try {
|
||||||
|
format = localStorage["iitc-passcode-format"];
|
||||||
|
} catch(e) {}
|
||||||
|
|
||||||
var html = '<p><strong>' + encouragement + '</strong></p><ul class="redeemReward">';
|
var formatHandlers = {
|
||||||
|
"short": formatPasscodeShort,
|
||||||
|
"long": formatPasscodeLong
|
||||||
|
}
|
||||||
|
if(!formatHandlers[format])
|
||||||
|
format = "long";
|
||||||
|
|
||||||
if(0 < data.xm)
|
var html = formatHandlers[format](data);
|
||||||
html += '<li>' + window.escapeHtmlSpecialChars(data.xm) + ' XM</li>';
|
|
||||||
if(0 < data.ap)
|
var that = this;
|
||||||
html += '<li>' + window.escapeHtmlSpecialChars(data.ap) + ' AP</li>';
|
var buttons = {};
|
||||||
|
Object.keys(formatHandlers).forEach(function(label) {
|
||||||
|
if(label == format) return;
|
||||||
|
|
||||||
|
buttons[label.toUpperCase()] = function() {
|
||||||
|
$(this).dialog("close");
|
||||||
|
localStorage["iitc-passcode-format"] = label;
|
||||||
|
handleRedeemResponse.call(that, data, textStatus, jqXHR);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Display it
|
||||||
|
dialog({
|
||||||
|
title: 'Passcode: ' + passcode,
|
||||||
|
html: html,
|
||||||
|
buttons: buttons
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
window.formatPasscodeLong = function(data) {
|
||||||
|
var html = '<p><strong>Passcode confirmed. Acquired items:</strong></p><ul class="redeemReward">';
|
||||||
|
|
||||||
if(data.other) {
|
if(data.other) {
|
||||||
data.other.forEach(function(item) {
|
data.other.forEach(function(item) {
|
||||||
@ -221,15 +80,20 @@ window.handleRedeemResponse = function(data, textStatus, jqXHR) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(0 < data.xm)
|
||||||
|
html += '<li>' + window.escapeHtmlSpecialChars(data.xm) + ' XM</li>';
|
||||||
|
if(0 < data.ap)
|
||||||
|
html += '<li>' + window.escapeHtmlSpecialChars(data.ap) + ' AP</li>';
|
||||||
|
|
||||||
if(data.inventory) {
|
if(data.inventory) {
|
||||||
data.inventory.forEach(function(type) {
|
data.inventory.forEach(function(type) {
|
||||||
type.awards.forEach(function(item) {
|
type.awards.forEach(function(item) {
|
||||||
html += '<li>' + item.count + ' ';
|
html += '<li>' + item.count + 'x ';
|
||||||
|
|
||||||
var l = item.level;
|
var l = item.level;
|
||||||
if(0 < l) {
|
if(0 < l) {
|
||||||
l = parseInt(l);
|
l = parseInt(l);
|
||||||
html += '<span class="itemlevel" style="background:' + COLORS_LVL[l] + '">L' + l + '</span> ';
|
html += '<span class="itemlevel" style="color:' + COLORS_LVL[l] + '">L' + l + '</span> ';
|
||||||
}
|
}
|
||||||
|
|
||||||
html += window.escapeHtmlSpecialChars(type.name) + '</li>';
|
html += window.escapeHtmlSpecialChars(type.name) + '</li>';
|
||||||
@ -237,14 +101,56 @@ window.handleRedeemResponse = function(data, textStatus, jqXHR) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
html += '</ul>';
|
html += '</ul>'
|
||||||
|
return html;
|
||||||
|
}
|
||||||
|
|
||||||
// Display it
|
window.formatPasscodeShort = function(data) {
|
||||||
dialog({
|
|
||||||
title: 'Passcode: ' + passcode,
|
if(data.other) {
|
||||||
html: html
|
var awards = data.other.map(window.escapeHtmlSpecialChars);
|
||||||
|
} else {
|
||||||
|
var awards = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(0 < data.xm)
|
||||||
|
awards.push(window.escapeHtmlSpecialChars(data.xm) + ' XM');
|
||||||
|
if(0 < data.ap)
|
||||||
|
awards.push(window.escapeHtmlSpecialChars(data.ap) + ' AP');
|
||||||
|
|
||||||
|
if(data.inventory) {
|
||||||
|
data.inventory.forEach(function(type) {
|
||||||
|
type.awards.forEach(function(item) {
|
||||||
|
var str = "";
|
||||||
|
if(item.count > 1)
|
||||||
|
str += item.count + " ";
|
||||||
|
|
||||||
|
if(window.REDEEM_SHORT_NAMES[type.name.toLowerCase()]) {
|
||||||
|
var shortName = window.REDEEM_SHORT_NAMES[type.name.toLowerCase()];
|
||||||
|
|
||||||
|
var l = item.level;
|
||||||
|
if(0 < l) {
|
||||||
|
l = parseInt(l);
|
||||||
|
str += '<span class="itemlevel" style="color:' + COLORS_LVL[l] + '">' + shortName + l + '</span>';
|
||||||
|
} else {
|
||||||
|
str += shortName;
|
||||||
|
}
|
||||||
|
} else { // no short name known
|
||||||
|
var l = item.level;
|
||||||
|
if(0 < l) {
|
||||||
|
l = parseInt(l);
|
||||||
|
str += '<span class="itemlevel" style="color:' + COLORS_LVL[l] + '">L' + l + '</span> ';
|
||||||
|
}
|
||||||
|
str += type.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
awards.push(str);
|
||||||
});
|
});
|
||||||
};
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return '<p class="redeemReward">' + awards.join(', ') + '</p>'
|
||||||
|
}
|
||||||
|
|
||||||
window.setupRedeem = function() {
|
window.setupRedeem = function() {
|
||||||
$("#redeem").keypress(function(e) {
|
$("#redeem").keypress(function(e) {
|
||||||
|
@ -943,7 +943,8 @@ td + td {
|
|||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
.redeemReward .itemlevel {
|
.redeemReward .itemlevel {
|
||||||
padding: 0 0.2em;
|
font-weight: bold;
|
||||||
|
text-shadow: 0 0 1px #000; /* L8 is hard to read on blue background */
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
.redeem-result-table {
|
.redeem-result-table {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user