Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
le-jeu authored and modos189 committed Nov 19, 2024
1 parent 46550e5 commit de178e5
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 85 deletions.
25 changes: 14 additions & 11 deletions core/code/map_data_render.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ window.Render.prototype.createPlaceholderPortalEntity = function (guid, latE6, l
];

this.createPortalEntity(ent, 'core'); // placeholder
}
};

/**
* Creates a portal entity from the provided game entity data.
Expand All @@ -351,8 +351,9 @@ window.Render.prototype.createPortalEntity = function (ent, details) {

// add missing fields
data.guid = guid;
if (!data.timestamp)
if (!data.timestamp) {
data.timestamp = ent[1];
}

// LEGACY - TO BE REMOVED AT SOME POINT! use .guid, .timestamp and .data instead
data.ent = ent;
Expand Down Expand Up @@ -386,14 +387,14 @@ window.Render.prototype.createPortalEntity = function (ent, details) {
// check for URL links to portal, and select it if this is the one
if (window.urlPortalLL && window.urlPortalLL[0] === latlng.lat && window.urlPortalLL[1] === latlng.lng) {
// URL-passed portal found via pll parameter - set the guid-based parameter
log.log('urlPortalLL ' + window.urlPortalLL[0] + ',' + urlPortalLL[1] + ' matches portal GUID ' + data.guid);
log.log('urlPortalLL ' + window.urlPortalLL[0] + ',' + window.urlPortalLL[1] + ' matches portal GUID ' + data.guid);

window.urlPortal = data.guid;
window.urlPortalLL = undefined; // clear the URL parameter so it's not matched again
}
if (window.urlPortal === data.guid) {
// URL-passed portal found via guid parameter - set it as the selected portal
log.log('urlPortal GUID ' + urlPortal + ' found - selecting...');
log.log('urlPortal GUID ' + window.urlPortal + ' found - selecting...');
window.selectedPortal = data.guid;
window.urlPortal = undefined; // clear the URL parameter so it's not matched again
}
Expand All @@ -405,26 +406,28 @@ window.Render.prototype.createPortalEntity = function (ent, details) {

marker.updateDetails(data);

window.runHooks('portalAdded', {portal: marker, previousData: previousData});
window.runHooks('portalAdded', { portal: marker, previousData: previousData });
} else {
marker = createMarker(latlng, data);
marker = window.createMarker(latlng, data);

// in case of incomplete data while having fresh details in cache, update the portal with those details
if (portalDetail.isFresh(guid)) {
var oldDetails = portalDetail.get(guid);
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
portalDetail.remove(guid);
} else if (marker.willUpdate(oldDetails))
window.portalDetail.remove(guid);
} else if (marker.willUpdate(oldDetails)) {
marker.updateDetails(oldDetails);
}
}

window.runHooks('portalAdded', { portal: marker });

window.portals[data.guid] = marker;

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

window.ornaments.addPortal(marker);
Expand Down
2 changes: 1 addition & 1 deletion core/code/portal_detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ window.portalDetail.isFresh = function (guid) {
return cache.isFresh(guid);
};

window.portalDetail.remove = function(guid) {
window.portalDetail.remove = function (guid) {
return cache.remove(guid);
};

Expand Down
16 changes: 11 additions & 5 deletions core/code/portal_detail_display.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ window.renderPortalUrl = function (lat, lng, title, guid) {
*
* @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.renderPortalDetails = function (guid, forceSelect) {
if (forceSelect || window.selectedPortal !== guid) {
window.selectPortal(window.portals[guid] ? guid : null, 'renderPortalDetails');
}
if ($('#sidebar').is(':visible')) {
window.resetScrollOnNewPortal();
window.renderPortalDetails.lastVisible = guid;
Expand Down Expand Up @@ -184,7 +186,7 @@ window.renderPortalDetails = function(guid, forceSelect) {
window.renderPortalUrl(lat, lng, title, guid);

// compatibility
var data = hasFullDetails ? getPortalSummaryData(details) : details;
var data = hasFullDetails ? window.getPortalSummaryData(details) : details;

// only run the hooks when we have a portalDetails object - most plugins rely on the extended data
// TODO? another hook to call always, for any plugins that can work with less data?
Expand Down Expand Up @@ -348,11 +350,15 @@ window.selectPortal = function (guid, event) {
if (!update && oldPortal) oldPortal.setSelected(false);

// Change style of selected portal
if(newPortal) newPortal.setSelected(true);
if (newPortal) newPortal.setSelected(true);

window.setPortalIndicators(newPortal);

window.runHooks('portalSelected', { selectedPortalGuid: guid, unselectedPortalGuid: oldPortalGuid, event: event });
window.runHooks('portalSelected', {
selectedPortalGuid: guid,
unselectedPortalGuid: oldPortalGuid,
event: event,
});
return update;
};

Expand Down
20 changes: 14 additions & 6 deletions core/code/portal_info.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,20 @@ window.getCurrentPortalEnergy = function (d) {
return nrg;
};

window.getPortalHealth = function(d) {
var max = getTotalPortalEnergy(d);
var cur = getCurrentPortalEnergy(d);
/**
* Calculates the health percentage of a portal based on its current and total energy.
*
* @function getPortalHealth
* @param {Object} d - The portal detail object containing resonator information.
* @returns {number} The portal health as a percentage (0-100).
* Returns 0 if the portal has no total energy.
*/
window.getPortalHealth = function (d) {
var max = window.getTotalPortalEnergy(d);
var cur = window.getCurrentPortalEnergy(d);

return max>0 ? Math.floor(cur/max*100) : 0;
}
return max > 0 ? Math.floor((cur / max) * 100) : 0;
};

/**
* Calculates the range of a portal for creating links. The range depends on portal level and any installed Link Amps.
Expand All @@ -75,7 +83,7 @@ window.getPortalHealth = function(d) {
* total range after applying the boost (`range`),
* and a boolean indicating if the portal is linkable (`isLinkable`).
*/
window.getPortalRange = function(d) {
window.getPortalRange = function (d) {
// formula by the great gals and guys at
// http://decodeingress.me/2012/11/18/ingress-portal-levels-and-link-range/
var range = {
Expand Down
Loading

0 comments on commit de178e5

Please sign in to comment.