Attempt Fix vehicle filtering for maps with 0 tanks or helicopters

2.12 Squad, some layers have no vehicles, so when reading JSON from the wiki team we reject a promise because no data[t].vehicles property, this sets to empty array before we attempt a filter.

Should stop promise rejection during startup
This commit is contained in:
ect0s 2022-02-12 13:56:21 -05:00
parent f34426d61f
commit 5964b37769

View File

@ -2,7 +2,7 @@ export default class Layer {
constructor(data) {
this.name = data.Name;
this.classname = data.levelName;
this.layerid = data.rawName
this.layerid = data.rawName;
this.map = {
name: data.mapName
};
@ -30,10 +30,10 @@ export default class Layer {
spawnDelay: vehicle.delay,
respawnDelay: vehicle.respawnTime
})),
numberOfTanks: data[t].vehicles.filter((v) => {
numberOfTanks: (data[t].vehicles || []).filter((v) => {
return v.icon.match(/tank/);
}).length,
numberOfHelicopters: data[t].vehicles.filter((v) => {
numberOfHelicopters: (data[t].vehicles || []).filter((v) => {
return v.icon.match(/helo/);
}).length
});