From 5ecb10f3d601af20f63b26bdae3ff27fa6dc891b Mon Sep 17 00:00:00 2001 From: LeJeu <64744459+le-jeu@users.noreply.github.com> Date: Sun, 13 Nov 2022 23:37:16 +0100 Subject: [PATCH] redfection: fix L doesn't exist not yet --- src/redfection/filters.js | 49 ++++++++++++++++++++++----------------- src/redfection/map.js | 16 ++++++------- src/redfection/meta.json | 2 +- 3 files changed, 37 insertions(+), 30 deletions(-) diff --git a/src/redfection/filters.js b/src/redfection/filters.js index fd775b12..a05f4139 100644 --- a/src/redfection/filters.js +++ b/src/redfection/filters.js @@ -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); +} diff --git a/src/redfection/map.js b/src/redfection/map.js index 405b4786..8cd019a4 100644 --- a/src/redfection/map.js +++ b/src/redfection/map.js @@ -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' } }, @@ -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' } }, @@ -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' } }, }); diff --git a/src/redfection/meta.json b/src/redfection/meta.json index d5510c0a..3d1b5440 100644 --- a/src/redfection/meta.json +++ b/src/redfection/meta.json @@ -2,6 +2,6 @@ "author": "jaiperdu", "name": "Redfection", "category": "Info", - "version": "0.2.1", + "version": "0.2.2", "description": "Show redfection portals and links" }