Skip to content

Commit

Permalink
Merge branch 'master' into areasUnderAttack
Browse files Browse the repository at this point in the history
  • Loading branch information
bryndavies committed Jun 30, 2015
2 parents 6b1f4a1 + 570f7a0 commit 3e31da8
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 91 deletions.
3 changes: 2 additions & 1 deletion code/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
// portalSelected: called when portal on map is selected/unselected.
// Provide guid of selected and unselected portal.
// mapDataRefreshStart: called when we start refreshing map data
// mapDataEntityInject: called just as we start to render data. has callback to inject cached entities into the map render
// mapDataRefreshEnd: called when we complete the map data load
// portalAdded: called when a portal has been received and is about to
// be added to its layer group. Note that this does NOT
Expand Down Expand Up @@ -55,7 +56,7 @@
window._hooks = {}
window.VALID_HOOKS = [
'portalSelected', 'portalDetailsUpdated',
'mapDataRefreshStart', 'mapDataRefreshEnd',
'mapDataRefreshStart', 'mapDataEntityInject', 'mapDataRefreshEnd',
'portalAdded', 'linkAdded', 'fieldAdded',
'publicChatDataAvailable', 'factionChatDataAvailable',
'requestFinished', 'nicknameClicked',
Expand Down
3 changes: 3 additions & 0 deletions code/map_data_request.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ window.MapDataRequest.prototype.refresh = function() {

this.render.startRenderPass(tileParams.level, dataBounds);

var _render = this.render;
window.runHooks ('mapDataEntityInject', {callback: function(ents) { _render.processGameEntities(ents);}});


this.render.processGameEntities(artifact.getArtifactEntities());

Expand Down
40 changes: 3 additions & 37 deletions code/portal_detail_display.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,46 +41,13 @@ window.renderPortalDetails = function(guid) {


var img = fixPortalImageUrl(details ? details.image : data.image);
var title = data.title;
var title = (details && details.title) || (data && data.title) || '(untitled)';

var lat = data.latE6/1E6;
var lng = data.lngE6/1E6;

var imgTitle = details ? getPortalDescriptionFromDetails(details) : data.title;
imgTitle += '\n\nClick to show full image.';
var portalDetailObj = details ? window.getPortalDescriptionFromDetailsExtended(details) : undefined;
var imgTitle = title+'\n\nClick to show full image.';

var portalDetailedDescription = '';

if(portalDetailObj) {
portalDetailedDescription = '<table description="Portal Photo Details" class="portal_details">';

// TODO (once the data supports it) - portals can have multiple photos. display all, with navigation between them
// (at this time the data isn't returned from the server - although a count of images IS returned!)

if(portalDetailObj.submitter.name.length > 0) {
if(portalDetailObj.submitter.team) {
submitterSpan = '<span class="' + (portalDetailObj.submitter.team === 'RESISTANCE' ? 'res' : 'enl') + ' nickname">';
} else {
submitterSpan = '<span class="none">';
}
portalDetailedDescription += '<tr><th>Photo by:</th><td>' + submitterSpan
+ escapeHtmlSpecialChars(portalDetailObj.submitter.name) + '</span>'+(portalDetailObj.submitter.voteCount !== undefined ? ' (' + portalDetailObj.submitter.voteCount + ' votes)' : '')+'</td></tr>';
}
if(portalDetailObj.submitter.link.length > 0) {
portalDetailedDescription += '<tr><th>Photo from:</th><td><a href="'
+ escapeHtmlSpecialChars(portalDetailObj.submitter.link) + '">' + escapeHtmlSpecialChars(portalDetailObj.submitter.link) + '</a></td></tr>';
}

if(portalDetailObj.description) {
portalDetailedDescription += '<tr class="padding-top"><th>Description:</th><td>' + escapeHtmlSpecialChars(portalDetailObj.description) + '</td></tr>';
}
// if(d.descriptiveText.map.ADDRESS) {
// portalDetailedDescription += '<tr><th>Address:</th><td>' + escapeHtmlSpecialChars(d.descriptiveText.map.ADDRESS) + '</td></tr>';
// }

portalDetailedDescription += '</table>';
}

// portal level. start with basic data - then extend with fractional info in tooltip if available
var levelInt = (teamStringToId(data.team) == TEAM_NONE) ? 0 : data.level;
Expand Down Expand Up @@ -127,7 +94,7 @@ window.renderPortalDetails = function(guid) {
.html('') //to ensure it's clear
.attr('class', TEAM_TO_CSS[teamStringToId(data.team)])
.append(
$('<h3>').attr({class:'title'}).text(data.title),
$('<h3>').attr({class:'title'}).text(title),

$('<span>').attr({
class: 'close',
Expand All @@ -141,7 +108,6 @@ window.renderPortalDetails = function(guid) {
.attr({class:'imgpreview', title:imgTitle, style:"background-image: url('"+img+"')"})
.append(
$('<span>').attr({id:'level', title: levelDetails}).text(levelInt),
$('<div>').attr({class:'portalDetails'}).html(portalDetailedDescription),
$('<img>').attr({class:'hide', src:img})
),

Expand Down
53 changes: 0 additions & 53 deletions code/portal_detail_display_tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,59 +23,6 @@ window.getRangeText = function(d) {
title];
}

// generates description text from details for portal
window.getPortalDescriptionFromDetails = function(details) {
return details.title || '(untitled)';

// var descObj = details.descriptiveText.map;
// // FIXME: also get real description?
// var desc = descObj.TITLE;
// if(descObj.ADDRESS)
// desc += '\n' + descObj.ADDRESS;
//// if(descObj.ATTRIBUTION)
//// desc += '\nby '+descObj.ATTRIBUTION+' ('+descObj.ATTRIBUTION_LINK+')';
// return desc;
}

// Grabs more info, including the submitter name for the current main
// portal image
window.getPortalDescriptionFromDetailsExtended = function(details) {
var descObj = details.title;
var photoStreamObj = details.photoStreamInfo;

var submitterObj = new Object();
submitterObj.type = "";
submitterObj.name = "";
submitterObj.team = "";
submitterObj.link = "";
submitterObj.voteCount = undefined;

if(photoStreamObj && photoStreamObj.hasOwnProperty("coverPhoto") && photoStreamObj.coverPhoto.hasOwnProperty("attributionMarkup")) {
submitterObj.name = "Unknown";

var attribution = photoStreamObj.coverPhoto.attributionMarkup;
submitterObj.type = attribution[0];
if(attribution[1].hasOwnProperty("plain"))
submitterObj.name = attribution[1].plain;
if(attribution[1].hasOwnProperty("team"))
submitterObj.team = attribution[1].team;
if(attribution[1].hasOwnProperty("attributionLink"))
submitterObj.link = attribution[1].attributionLink;
if(photoStreamObj.coverPhoto.hasOwnProperty("voteCount"))
submitterObj.voteCount = photoStreamObj.coverPhoto.voteCount;
}


var portalDetails = {
title: descObj.TITLE,
description: descObj.DESCRIPTION,
address: descObj.ADDRESS,
submitter: submitterObj
};

return portalDetails;
}


// given portal details, returns html code to display mod details.
window.getModDetails = function(d) {
Expand Down
62 changes: 62 additions & 0 deletions plugins/cache-details-on-map.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// ==UserScript==
// @id iitc-plugin-cache-details-on-map@jonatkins
// @name IITC plugin: Cache viewed portal details and always show them on the map
// @category Cache
// @version 0.1.0.@@DATETIMEVERSION@@
// @namespace https://github.com/jonatkins/ingress-intel-total-conversion
// @updateURL @@UPDATEURL@@
// @downloadURL @@DOWNLOADURL@@
// @description [@@BUILDNAME@@-@@BUILDDATE@@] Cache the details of recently viewed portals and use this to populate the map when possible
// @include https://www.ingress.com/intel*
// @include http://www.ingress.com/intel*
// @match https://www.ingress.com/intel*
// @match http://www.ingress.com/intel*
// @include https://www.ingress.com/mission/*
// @include http://www.ingress.com/mission/*
// @match https://www.ingress.com/mission/*
// @match http://www.ingress.com/mission/*
// @grant none
// ==/UserScript==

@@PLUGINSTART@@

// PLUGIN START ////////////////////////////////////////////////////////


// use own namespace for plugin
window.plugin.cachePortalDetailsOnMap = function() {};

window.plugin.cachePortalDetailsOnMap.MAX_AGE = 12*60*60; //12 hours max age for cached data

window.plugin.cachePortalDetailsOnMap.portalDetailLoaded = function(data) {
window.plugin.cachePortalDetailsOnMap.cache[data.guid] = { loadtime: Date.now(), ent: data.ent };
};

window.plugin.cachePortalDetailsOnMap.entityInject = function(data) {
var maxAge = Date.now() - window.plugin.cachePortalDetailsOnMap.MAX_AGE*1000;

var ents = [];
for (var guid in window.plugin.cachePortalDetailsOnMap.cache) {
if (window.plugin.cachePortalDetailsOnMap.cache[guid].loadtime < maxAge) {
window.plugin.cachePortalDetailsOnMap.cache.delete(guid);
} else {
ents.push(window.plugin.cachePortalDetailsOnMap.cache[guid].ent);
}
}
data.callback(ents);
};


window.plugin.cachePortalDetailsOnMap.setup = function() {

window.plugin.cachePortalDetailsOnMap.cache = {};

addHook('portalDetailLoaded', window.plugin.cachePortalDetailsOnMap.portalDetailLoaded);
addHook('mapDataEntityInject', window.plugin.cachePortalDetailsOnMap.entityInject);
};

var setup = window.plugin.cachePortalDetailsOnMap.setup;

// PLUGIN END //////////////////////////////////////////////////////////

@@PLUGINEND@@

0 comments on commit 3e31da8

Please sign in to comment.