2021-02-03 11:33:01 -06:00
|
|
|
import axios from 'axios';
|
|
|
|
|
2021-02-25 07:02:08 -06:00
|
|
|
import Logger from 'core/logger';
|
|
|
|
|
2021-02-03 11:33:01 -06:00
|
|
|
import Layer from './layer.js';
|
|
|
|
|
|
|
|
class Layers {
|
|
|
|
constructor() {
|
|
|
|
this.layers = [];
|
|
|
|
|
|
|
|
this.pulled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
async pull(force = false) {
|
2021-02-25 07:02:08 -06:00
|
|
|
if (this.pulled && !force) {
|
2021-02-25 14:50:18 -06:00
|
|
|
Logger.verbose('Layers', 2, 'Already pulled layers.');
|
2021-02-25 07:02:08 -06:00
|
|
|
return;
|
|
|
|
}
|
2021-02-25 14:50:18 -06:00
|
|
|
if (force) Logger.verbose('Layers', 1, 'Forcing update to layer information...');
|
2021-02-03 12:41:35 -06:00
|
|
|
|
2021-02-25 07:02:08 -06:00
|
|
|
this.layers = [];
|
2021-02-03 11:33:01 -06:00
|
|
|
|
2021-03-04 16:36:57 -06:00
|
|
|
Logger.verbose('Layers', 1, 'Pulling layers...');
|
2023-03-02 01:21:25 -06:00
|
|
|
const response = await axios.post( // Change get to post for mod support
|
|
|
|
'http://hub.afocommunity.com/api/layers.json', [0, 1959152751]
|
2021-03-04 16:36:57 -06:00
|
|
|
);
|
2023-03-20 06:49:14 -05:00
|
|
|
|
|
|
|
// const response = await axios.get(
|
|
|
|
// 'https://raw.githubusercontent.com/Squad-Wiki/squad-wiki-pipeline-map-data/master/completed_output/_Current%20Version/finished.json'
|
|
|
|
// );
|
2021-02-25 11:37:20 -06:00
|
|
|
|
2021-02-25 14:50:18 -06:00
|
|
|
for (const layer of response.data.Maps) {
|
|
|
|
this.layers.push(new Layer(layer));
|
|
|
|
}
|
2021-02-25 11:37:20 -06:00
|
|
|
|
2021-02-25 14:50:18 -06:00
|
|
|
Logger.verbose('Layers', 1, `Pulled ${this.layers.length} layers.`);
|
2021-02-25 11:37:20 -06:00
|
|
|
|
2021-02-25 14:50:18 -06:00
|
|
|
this.pulled = true;
|
2021-02-25 07:02:08 -06:00
|
|
|
|
2021-02-03 11:33:01 -06:00
|
|
|
return this.layers;
|
|
|
|
}
|
|
|
|
|
|
|
|
async getLayerByCondition(condition) {
|
|
|
|
await this.pull();
|
|
|
|
|
|
|
|
const matches = this.layers.filter(condition);
|
2023-03-06 14:17:21 -06:00
|
|
|
if (matches.length >= 1) return matches[0];
|
2021-02-03 11:33:01 -06:00
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
getLayerByName(name) {
|
|
|
|
return this.getLayerByCondition((layer) => layer.name === name);
|
|
|
|
}
|
|
|
|
|
|
|
|
getLayerByClassname(classname) {
|
|
|
|
return this.getLayerByCondition((layer) => layer.classname === classname);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default new Layers();
|