Skip to content

Commit

Permalink
fix: null check for mech
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiTenno committed Apr 10, 2021
1 parent efe2bfe commit 75a7055
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/ArsenalParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ class ArsenalData {
const { mech, heavy: mechLong, exalted: mechExalted } = MECH;

this.loadout.mech = {};
this.loadout.mech = new Mech(mech);
this.loadout.mech.heavy = new Weapon(mechLong);
this.loadout.mech.exalted = new Weapon(mechExalted);
if (mech && !mech.hide) this.loadout.mech = new Mech(mech);
if (mechLong && !mechLong.hide) this.loadout.mech.heavy = new Weapon(mechLong);
if (mechExalted && !mechExalted.hide) this.loadout.mech.exalted = new Weapon(mechExalted);
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/Mech.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
'use strict';

const { items, loadMods, mapColors } = require('./utils');
const { loadMods, mapColors, findItem } = require('./utils');

module.exports = class WarframeMech {
constructor(mech) {
this.mech = (items.find((item) => item.uniqueName === mech.uniqueName))
|| mech;
this.mech = findItem(mech.uniqueName) || mech;

delete this.mech.patchlogs;
delete this.mech.components;
Expand All @@ -14,8 +13,8 @@ module.exports = class WarframeMech {
this.polarized = mech.polarized;
if (mech.skins) {
this.cosmetics = mech.skins
.map((cosmetic) => (items.find((item) => item.uniqueName === cosmetic.uniqueName))
|| cosmetic);
.filter((cosmetic) => cosmetic)
.map((cosmetic) => findItem(cosmetic.uniqueName) || cosmetic);

this.cosmetics.forEach((cosmetic) => {
/* eslint-disable no-param-reassign */
Expand Down
5 changes: 5 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,15 @@ function mapColors(colors = undefined) {
return colors;
}

const findItem = (uname) => items
.filter((item) => item && typeof item !== 'undefined' && item.uniqueName)
.find((item) => item.uniqueName === uname);

module.exports = {
translateFocus,
loadMods,
translatePolarity,
items,
findItem,
mapColors,
};
2 changes: 1 addition & 1 deletion test/unit/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe('utils', () => {
uniqueName: '/Lotus/Upgrades/Mods/Randomized/LotusRifleRandomModRare',
polarity: 'Varazin',
rarity: 'Common',
baseDrain: 0,
baseDrain: 3,
fusionLimit: 0,
imageName: 'rifle-riven-mod.png',
category: 'Mods',
Expand Down

0 comments on commit 75a7055

Please sign in to comment.