Skip to content

Commit

Permalink
Merge branch 'IITC-CE:master' into lint
Browse files Browse the repository at this point in the history
  • Loading branch information
nexushoratio authored Feb 15, 2025
2 parents aa7e9b3 + f71dc2b commit 8503462
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 31 deletions.
16 changes: 9 additions & 7 deletions core/code/map_data_render.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,6 @@ window.Render.prototype.endRenderPass = function () {

// reorder portals to be after links/fields
this.bringPortalsToFront();

this.isRendering = false;
};

/**
Expand Down Expand Up @@ -403,9 +401,16 @@ window.Render.prototype.createPortalEntity = function (ent, details) {
if (oldPortal) {
// update marker style/highlight and layer
marker = window.portals[data.guid];

marker.updateDetails(data);

if (window.portalDetail.isFresh(guid)) {
var oldDetails = window.portalDetail.get(guid);
if (data.timestamp > oldDetails.timestamp) {
// data is more recent than the cached details so we remove them from the cache
window.portalDetail.remove(guid);
}
}

window.runHooks('portalAdded', { portal: marker, previousData: previousData });
} else {
marker = window.createMarker(latlng, data);
Expand All @@ -424,12 +429,9 @@ window.Render.prototype.createPortalEntity = function (ent, details) {
window.runHooks('portalAdded', { portal: marker });

window.portals[data.guid] = marker;

if (window.selectedPortal === data.guid) {
marker.renderDetails();
}
}


window.ornaments.addPortal(marker);

// TODO? postpone adding to the map layer
Expand Down
7 changes: 6 additions & 1 deletion core/code/portal_detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,19 @@ var handleResponse = function (deferred, guid, data, success) {
}

if (success) {
// Parse portal details
var dict = window.decodeArray.portal(data.result, 'detailed');
cache.store(guid, dict);

// entity format, as used in map data
var ent = [guid, data.result[13], data.result];
var portal = window.mapDataRequest.render.createPortalEntity(ent, 'detailed');

// Update cache with from current map
cache.store(guid, portal.options.data);

deferred.resolve(portal.options.data);
window.runHooks('portalDetailLoaded', { guid: guid, success: success, details: portal.options.data, ent: ent });
window.runHooks('portalDetailLoaded', { guid: guid, success: success, details: portal.options.data, ent: ent, portal: portal });
} else {
if (data && data.error === 'RETRY') {
// server asked us to try again
Expand Down
22 changes: 15 additions & 7 deletions core/code/portal_detail_display.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,17 @@ window.renderPortalUrl = function (lat, lng, title, guid) {
};

/**
* Renders the details of a portal in the sidebar.
* Selects a portal, refresh its data and renders the details of the portal in the sidebar.
*
* @function renderPortalDetails
* @param {string|null} guid - The globally unique identifier of the portal to display details for.
* @param {boolean} [forceSelect=false] - If true, forces the portal to be selected even if it's already the current portal.
*/
window.renderPortalDetails = function (guid, forceSelect) {
if (forceSelect || window.selectedPortal !== guid) {
window.selectPortal(window.portals[guid] ? guid : null, 'renderPortalDetails');
window.selectPortal(guid && window.portals[guid] ? guid : null, 'renderPortalDetails');
}

if ($('#sidebar').is(':visible')) {
window.resetScrollOnNewPortal();
window.renderPortalDetails.lastVisible = guid;
Expand All @@ -84,10 +85,7 @@ window.renderPortalDetails = function (guid, forceSelect) {
window.portalDetail.request(guid);
}

// TODO? handle the case where we request data for a particular portal GUID, but it *isn't* in
// window.portals....

if (!window.portals[guid]) {
if (!guid || !window.portals[guid]) {
window.urlPortal = guid;
$('#portaldetails').html('');
if (window.isSmartphone()) {
Expand All @@ -97,7 +95,17 @@ window.renderPortalDetails = function (guid, forceSelect) {
return;
}

var portal = window.portals[guid];
window.renderPortalToSideBar(window.portals[guid]);
};

/**
* Renders the details of a portal in the sidebar.
*
* @function renderPortalToSideBar
* @param {L.PortalMarker} portal - The portal marker object holding portal details.
*/
window.renderPortalToSideBar = function (portal) {
var guid = portal.options.guid;
var details = portal.getDetails();
var hasFullDetails = portal.hasFullDetails();
var historyDetails = window.getPortalHistoryDetails(details);
Expand Down
12 changes: 0 additions & 12 deletions core/code/portal_marker.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,21 +186,9 @@ L.PortalMarker = L.CircleMarker.extend({
};
L.setOptions(this, dataOptions);

if (this._selected) {
this.renderDetails();
}

this.setSelected();
},

renderDetails() {
if (!this._rendering) {
this._rendering = true;
window.renderPortalDetails(this._details.guid);
this._rendering = false;
}
},

getDetails: function () {
return this._details;
},
Expand Down
25 changes: 25 additions & 0 deletions core/code/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ window.setupSidebar = function () {
setupLargeImagePreview();
setupAddons();
$('#sidebar').show();
// setup portal detail display update
window.addHook('portalAdded', sidebarOnPortalAdded);
window.addHook('portalDetailLoaded', sidebarOnPortalDetailLoaded);
};

/**
Expand Down Expand Up @@ -212,3 +215,25 @@ function setupAddons() {

window.RegionScoreboardSetup();
}

/**
* portalAdded callback to update the sidebar
*
* @function sidebarOnPortalAdded
*/
function sidebarOnPortalAdded(data) {
if (data.portal.options.guid === window.selectedPortal) {
window.renderPortalDetails(window.selectedPortal);
}
}

/**
* portalDetailLoaded callback to update the sidebar
*
* @function sidebarOnPortalDetailLoaded
*/
function sidebarOnPortalDetailLoaded(data) {
if (data.success && data.guid === window.selectedPortal) {
window.renderPortalToSideBar(data.portal);
}
}
1 change: 1 addition & 0 deletions plugins/bookmarks.js
Original file line number Diff line number Diff line change
Expand Up @@ -1438,6 +1438,7 @@ var setup = function () {
}

window.addHook('portalSelected', window.plugin.bookmarks.onPortalSelected);
window.addHook('portalDetailsUpdated', window.plugin.bookmarks.onPortalSelected);
window.addHook('search', window.plugin.bookmarks.onSearch);

// Sync
Expand Down
4 changes: 2 additions & 2 deletions plugins/machina-tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,13 +359,13 @@ function createInfoLink(text, title, clickCallback) {
return aside;
}

machinaTools.onPortalDetailsUpdated = function () {
machinaTools.onPortalDetailsUpdated = function (data) {
var portalData;

// If the portal was cleared then exit.
if (window.selectedPortal === null) return;

portalData = window.portalDetail.get(window.selectedPortal);
portalData = data.portalData;

if (portalData.team === window.TEAM_CODE_MAC) {
var linkdetails = $('.linkdetails');
Expand Down
4 changes: 2 additions & 2 deletions plugins/uniques.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ window.plugin.uniques.contentHTML = null;

window.plugin.uniques.isHighlightActive = false;

window.plugin.uniques.onPortalDetailsUpdated = function () {
window.plugin.uniques.onPortalDetailsUpdated = function (data) {
if (typeof Storage === 'undefined') {
$('#portaldetails > .imgpreview').after(window.plugin.uniques.disabledMessage);
return;
}

var guid = window.selectedPortal,
details = window.portalDetail.get(guid),
details = data.portalDetails,
nickname = window.PLAYER.nickname;
if (details) {
if (details.owner === nickname) {
Expand Down

0 comments on commit 8503462

Please sign in to comment.