mirror of
https://github.com/AsgardEternal/SquadJS.git
synced 2024-09-29 05:14:26 -05:00
58 lines
1.3 KiB
JavaScript
58 lines
1.3 KiB
JavaScript
import axios from 'axios';
|
|
|
|
import Logger from 'core/logger';
|
|
|
|
import Layer from './layer.js';
|
|
|
|
class Layers {
|
|
constructor() {
|
|
this.layers = [];
|
|
|
|
this.pulled = false;
|
|
}
|
|
|
|
async pull(force = false) {
|
|
if (this.pulled && !force) {
|
|
Logger.verbose('Layers', 2, 'Already pulled layers.');
|
|
return;
|
|
}
|
|
if (force) Logger.verbose('Layers', 1, 'Forcing update to layer information...');
|
|
|
|
this.layers = [];
|
|
|
|
Logger.verbose('Layers', 1, 'Pulling layers...');
|
|
const response = await axios.post( // Change get to post for mod support
|
|
'http://hub.afocommunity.com/api/layers.json', [0, 1959152751]
|
|
);
|
|
|
|
for (const layer of response.data.Maps) {
|
|
this.layers.push(new Layer(layer));
|
|
}
|
|
|
|
Logger.verbose('Layers', 1, `Pulled ${this.layers.length} layers.`);
|
|
|
|
this.pulled = true;
|
|
|
|
return this.layers;
|
|
}
|
|
|
|
async getLayerByCondition(condition) {
|
|
await this.pull();
|
|
|
|
const matches = this.layers.filter(condition);
|
|
if (matches.length >= 1) return matches[0];
|
|
|
|
return null;
|
|
}
|
|
|
|
getLayerByName(name) {
|
|
return this.getLayerByCondition((layer) => layer.name === name);
|
|
}
|
|
|
|
getLayerByClassname(classname) {
|
|
return this.getLayerByCondition((layer) => layer.classname === classname);
|
|
}
|
|
}
|
|
|
|
export default new Layers();
|