Skip to content

Commit

Permalink
Merge commit '3387afa015f42242468370bd58fa2934dca9384d' into rejected
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Castle committed Oct 26, 2024
2 parents 4358049 + 3387afa commit 6d97cbb
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 164 deletions.
6 changes: 0 additions & 6 deletions .eslintignore

This file was deleted.

19 changes: 0 additions & 19 deletions .eslintrc.json

This file was deleted.

50 changes: 50 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import prettier from 'eslint-plugin-prettier';
import globals from 'globals';
import eslint from '@eslint/js';
import PrettierRecommended from 'eslint-plugin-prettier/recommended';

export default [
eslint.configs.recommended,
PrettierRecommended,
{
ignores: [
'eslint.config.js',
'core/external/*.js',
'plugins/external/*.js',
'**/node_modules',
'**/build',
'**/mobile',
'**/docs',
'**/json_examples',
'**/external',
],
},
{
plugins: {
prettier,
},

languageOptions: {
globals: {
...globals.browser,
...globals.jquery,
...globals.greasemonkey,
},

ecmaVersion: 2024,
sourceType: 'module',
},

rules: {
eqeqeq: 'error',
'spaced-comment': 'error',
'no-unused-expressions': 'error',
},
},
{
files: ['plugins/*.js'],
rules: {
'no-unused-vars': ['error', { vars: 'all', varsIgnorePattern: '^setup|changelog$' }],
},
},
];
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
"private": true,
"type": "module",
"devDependencies": {
"@eslint/js": "^9.9.1",
"chai": "^4.3.6",
"eslint": "^8.20.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint": "^9.9.1",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.2.1",
"globals": "^15.9.0",
"mocha": "^9.2.2",
"prettier": "^2.7.1"
"prettier": "^3.3.3"
},
"scripts": {
"build": "npm run build:local",
Expand Down
108 changes: 52 additions & 56 deletions plugins/ap-stats.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
// @author Hollow011
// @name Available AP statistics
// @category Info
// @version 0.4.4
// @version 0.4.5
// @description Displays the per-team AP gains available in the current view.

/* exported setup, changelog --eslint */

var changelog = [
{
version: '0.4.5',
changes: ['Refactoring: fix eslint'],
},
{
version: '0.4.4',
changes: ['Version upgrade due to a change in the wrapper: plugin icons are now vectorized'],
Expand All @@ -18,45 +22,43 @@ var changelog = [
];

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

window.plugin.compAPStats.setupCallback = function() {
window.plugin.compAPStats.setupCallback = function () {
// add a new div to the bottom of the sidebar and style it
$('#sidebar').append('<div id="available_ap_display"></div>');
$('#available_ap_display').css({'color':'#ffce00', 'font-size':'90%', 'padding':'4px 2px'});
$('#available_ap_display').css({ color: '#ffce00', 'font-size': '90%', padding: '4px 2px' });

// do an initial calc for sidebar sizing purposes
window.plugin.compAPStats.update(false);

// make the value update when the map data updates
window.addHook('mapDataRefreshEnd', window.plugin.compAPStats.mapDataRefreshEnd);
window.addHook('requestFinished', window.plugin.compAPStats.requestFinished);
};

}

window.plugin.compAPStats.mapDataRefreshEnd = function() {
window.plugin.compAPStats.mapDataRefreshEnd = function () {
if (window.plugin.compAPStats.timer) {
clearTimeout(window.plugin.compAPStats.timer);
window.plugin.compAPStats.timer = undefined;
}

window.plugin.compAPStats.update(true);
}
};

window.plugin.compAPStats.requestFinished = function() {
window.plugin.compAPStats.requestFinished = function () {
// process on a short delay, so if multiple requests finish in a short time we only calculate once
if (window.plugin.compAPStats.timer === undefined) {
window.plugin.compAPStats.timer = setTimeout( function() {
window.plugin.compAPStats.timer = setTimeout(function () {
window.plugin.compAPStats.timer = undefined;
window.plugin.compAPStats.update(false);
}, 0.75*1000);
}, 0.75 * 1000);
}
}
};

window.plugin.compAPStats.updateNoPortals = function (hasFinished) {
$('#available_ap_display').html('Available AP in this area: '
+ '<div style="color:red">Zoom closer to get all portals loaded.<div>');
}
window.plugin.compAPStats.updateNoPortals = function () {
$('#available_ap_display').html('Available AP in this area: <div style="color:red">Zoom closer to get all portals loaded.<div>');
};

window.plugin.compAPStats.update = function (hasFinished) {
if (!window.getDataZoomTileParameters().hasPortals) {
Expand All @@ -67,62 +69,56 @@ window.plugin.compAPStats.update = function (hasFinished) {
var result = window.plugin.compAPStats.compAPStats();
var loading = hasFinished ? '' : 'Loading...';

var formatRow = function(team,data) {
var title = 'Destroy and capture '+data.destroyPortals+' portals\n'
+ 'Destroy '+data.destroyLinks+' links and '+data.destroyFields+' fields\n'
+ 'Capture '+data.capturePortals+' neutral portals, complete '+data.finishPortals+' portals\n'
+ '(unknown additional AP for links/fields)';
return '<tr><td>'+team+'</td><td style="text-align:right" title="'+title+'">'+digits(data.AP)+'</td></tr>';
}


$('#available_ap_display').html('Available AP in this area: '
+ loading
+ '<table>'
+ formatRow('Enlightened',result.enl)
+ formatRow('Resistance', result.res)
+ '</table>');
}

var formatRow = function (team, data) {
var title =
`Destroy and capture ${data.destroyPortals} portals\n` +
`Destroy ${data.destroyLinks} links and ${data.destroyFields} fields\n` +
`Capture ${data.capturePortals} neutral portals, complete ${data.finishPortals} portals\n` +
`(unknown additional AP for links/fields)`;
return `<tr><td>${team}</td><td style="text-align:right" title="${title}">${window.digits(data.AP)}</td></tr>`;
};

window.plugin.compAPStats.compAPStats = function() {
$('#available_ap_display').html(
`Available AP in this area: ${loading}<table>${formatRow('Enlightened', result.enl)}${formatRow('Resistance', result.res)}</table>`
);
};

window.plugin.compAPStats.compAPStats = function () {
var result = {
res: { AP: 0, destroyPortals: 0, capturePortals: 0, finishPortals: 0, destroyLinks: 0, destroyFields: 0 },
enl: { AP: 0, destroyPortals: 0, capturePortals: 0, finishPortals: 0, destroyLinks: 0, destroyFields: 0 },
};


var displayBounds = map.getBounds();
var displayBounds = window.map.getBounds();

// AP to fully deploy a neutral portal
var PORTAL_FULL_DEPLOY_AP = CAPTURE_PORTAL + 8*DEPLOY_RESONATOR + COMPLETION_BONUS;
var PORTAL_FULL_DEPLOY_AP = window.CAPTURE_PORTAL + 8 * window.DEPLOY_RESONATOR + window.COMPLETION_BONUS;

// Grab every portal in the viewable area and compute individual AP stats
// (fields and links are counted separately below)
$.each(window.portals, function(ind, portal) {
$.each(window.portals, function (ind, portal) {
var data = portal.options.data;

// eliminate offscreen portals
if(!displayBounds.contains(portal.getLatLng())) return true; //$.each 'continue'
if (!displayBounds.contains(portal.getLatLng())) return true; // $.each 'continue'

// AP to complete a portal - assuming it's already captured (so no CAPTURE_PORTAL)
var completePortalAp = 0;
if ('resCount' in data && data.resCount < 8) {
completePortalAp = (8-data.resCount)*DEPLOY_RESONATOR + COMPLETION_BONUS;
completePortalAp = (8 - data.resCount) * window.DEPLOY_RESONATOR + window.COMPLETION_BONUS;
}

// AP to destroy this portal
var destroyAp = (data.resCount || 0) * DESTROY_RESONATOR;
var destroyAp = (data.resCount || 0) * window.DESTROY_RESONATOR;

if (portal.options.team === TEAM_ENL) {
if (portal.options.team === window.TEAM_ENL) {
result.res.AP += destroyAp + PORTAL_FULL_DEPLOY_AP;
result.res.destroyPortals++;
if (completePortalAp) {
result.enl.AP += completePortalAp;
result.enl.finishPortals++;
}
} else if (portal.options.team === TEAM_RES) {
} else if (portal.options.team === window.TEAM_RES) {
result.enl.AP += destroyAp + PORTAL_FULL_DEPLOY_AP;
result.enl.destroyPortals++;
if (completePortalAp) {
Expand All @@ -139,38 +135,38 @@ window.plugin.compAPStats.compAPStats = function() {
});

// now every link that starts/ends at a point on screen
$.each(window.links, function(guid, link) {
$.each(window.links, function (guid, link) {
// only consider links that start/end on-screen
var points = link.getLatLngs();
if (displayBounds.contains(points[0]) || displayBounds.contains(points[1])) {
if (link.options.team == TEAM_ENL) {
result.res.AP += DESTROY_LINK;
if (link.options.team === window.TEAM_ENL) {
result.res.AP += window.DESTROY_LINK;
result.res.destroyLinks++;
} else if (link.options.team == TEAM_RES) {
result.enl.AP += DESTROY_LINK;
} else if (link.options.team === window.TEAM_RES) {
result.enl.AP += window.DESTROY_LINK;
result.enl.destroyLinks++;
}
}
});

// and now all fields that have a vertex on screen
$.each(window.fields, function(guid, field) {
$.each(window.fields, function (guid, field) {
// only consider fields with at least one vertex on screen
var points = field.getLatLngs();
if (displayBounds.contains(points[0]) || displayBounds.contains(points[1]) || displayBounds.contains(points[2])) {
if (field.options.team == TEAM_ENL) {
result.res.AP += DESTROY_FIELD;
if (field.options.team === window.TEAM_ENL) {
result.res.AP += window.DESTROY_FIELD;
result.res.destroyFields++;
} else if (field.options.team == TEAM_RES) {
result.enl.AP += DESTROY_FIELD;
} else if (field.options.team === window.TEAM_RES) {
result.enl.AP += window.DESTROY_FIELD;
result.enl.destroyFields++;
}
}
});

return result;
}
};

var setup = function() {
var setup = function () {
window.plugin.compAPStats.setupCallback();
}
};
28 changes: 15 additions & 13 deletions plugins/basemap-bing.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// @author johnd0e
// @name Bing maps
// @category Map Tiles
// @version 0.3.3
// @version 0.3.4
// @description Add the bing.com map layers.

/* exported setup, changelog --eslint */
/* global L, layerChooser */
/* global L -- eslint */

var changelog = [
{
version: '0.3.4',
changes: ['Refactoring: fix eslint'],
},
{
version: '0.3.3',
changes: ['Version upgrade due to a change in the wrapper: plugin icons are now vectorized'],
Expand All @@ -23,42 +27,40 @@ var mapBing = {};

mapBing.sets = {
Road: {
imagerySet: 'RoadOnDemand'
imagerySet: 'RoadOnDemand',
},
Dark: {
imagerySet: 'CanvasDark'
imagerySet: 'CanvasDark',
},
Aerial: {
imagerySet: 'Aerial'
imagerySet: 'Aerial',
},
Hybrid: {
imagerySet: 'AerialWithLabelsOnDemand'
}
imagerySet: 'AerialWithLabelsOnDemand',
},
};

mapBing.options = {
// set this to your API key
key: 'ArR2hTa2C9cRQZT-RmgrDkfvh3PwEVRl0gB34OO4wJI7vQNElg3DDWvbo5lfUs3p'
key: 'ArR2hTa2C9cRQZT-RmgrDkfvh3PwEVRl0gB34OO4wJI7vQNElg3DDWvbo5lfUs3p',
};

function setup () {
function setup() {
setupBingLeaflet();

for (var name in mapBing.sets) {
var options = L.extend({}, mapBing.options, mapBing.sets[name]);
layerChooser.addBaseLayer(L.bingLayer(options), 'Bing ' + name);
window.layerChooser.addBaseLayer(L.bingLayer(options), 'Bing ' + name);
}
}

function setupBingLeaflet () {
function setupBingLeaflet() {
try {
// https://github.com/shramov/leaflet-plugins/blob/master/layer/tile/Bing.js
'@include_raw:external/Bing.js@'; // eslint-disable-line


// https://github.com/shramov/leaflet-plugins/blob/master/layer/tile/Bing.addon.applyMaxNativeZoom.js
'@include_raw:external/Bing.addon.applyMaxNativeZoom.js@'; // eslint-disable-line

} catch (e) {
console.error('Bing.js loading failed');
throw e;
Expand Down
Loading

0 comments on commit 6d97cbb

Please sign in to comment.