Skip to content

Commit

Permalink
redfection: fix L doesn't exist not yet
Browse files Browse the repository at this point in the history
  • Loading branch information
le-jeu committed Nov 13, 2022
1 parent 7c97a48 commit 5ecb10f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 30 deletions.
49 changes: 28 additions & 21 deletions src/redfection/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,24 +124,31 @@ export function filterEntities() {
* @extends L.Layer
* @param {{name: string, filter: FilterDesc}} options
*/
export const FilterLayer = L.Layer.extend({
options: {
name: null,
filter: {},
},

initialize: function (options) {
L.setOptions(this, options);
set(this.options.name, this.options.filter);
},

onAdd: function () {
remove(this.options.name);
filterEntities();
},

onRemove: function () {
set(this.options.name, this.options.filter);
filterEntities();
},
});
let FilterLayer = null;

export function filterLayer(options) {
if (!FilterLayer) {
FilterLayer = L.Layer.extend({
options: {
name: null,
filter: {},
},

initialize: function (options) {
L.setOptions(this, options);
set(this.options.name, this.options.filter);
},

onAdd: function () {
remove(this.options.name);
filterEntities();
},

onRemove: function () {
set(this.options.name, this.options.filter);
filterEntities();
},
});
}
return new FilterLayer(options);
}
16 changes: 8 additions & 8 deletions src/redfection/map.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { FilterLayer } from './filters';
import { filterLayer } from './filters';

export function createDefaultOverlays() {
var addLayers = {};

var portalsLayers = [];
portalsLayers[0] = new FilterLayer({
portalsLayers[0] = filterLayer({
name: 'Unclaimed/Placeholder Portals',
filter: [
{ portal: true, data: { team: 'N' } },
Expand All @@ -14,7 +14,7 @@ export function createDefaultOverlays() {
addLayers['Unclaimed/Placeholder Portals'] = portalsLayers[0];
for (var i = 1; i <= 8; i++) {
var t = 'Level ' + i + ' Portals';
portalsLayers[i] = new FilterLayer({
portalsLayers[i] = filterLayer({
name: t,
filter: [
{ portal: true, data: { level: i, team: 'R' } },
Expand All @@ -25,28 +25,28 @@ export function createDefaultOverlays() {
addLayers[t] = portalsLayers[i];
}

var fieldsLayer = new FilterLayer({
var fieldsLayer = filterLayer({
name: 'Fields',
filter: { field: true },
});
addLayers['Fields'] = fieldsLayer;

var linksLayer = new FilterLayer({
var linksLayer = filterLayer({
name: 'Links',
filter: { link: true },
});
addLayers['Links'] = linksLayer;

// faction-specific layers
var resistanceLayer = new FilterLayer({
var resistanceLayer = filterLayer({
name: 'Resistance',
filter: { portal: true, link: true, field: true, data: { team: 'R' } },
});
var enlightenedLayer = new FilterLayer({
var enlightenedLayer = filterLayer({
name: 'Enlightened',
filter: { portal: true, link: true, field: true, data: { team: 'E' } },
});
var machinaLayer = new FilterLayer({
var machinaLayer = filterLayer({
name: window.TEAM_NAMES[window.TEAM_MAC],
filter: { portal: true, link: true, field: true, data: { team: 'M' } },
});
Expand Down
2 changes: 1 addition & 1 deletion src/redfection/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
"author": "jaiperdu",
"name": "Redfection",
"category": "Info",
"version": "0.2.1",
"version": "0.2.2",
"description": "Show redfection portals and links"
}

0 comments on commit 5ecb10f

Please sign in to comment.