Skip to content

Commit

Permalink
perf: filter items to just arsenal items and skins (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
SlayerOrnstein authored Sep 27, 2024
1 parent 574470a commit 6147471
Show file tree
Hide file tree
Showing 18 changed files with 102 additions and 47 deletions.
8 changes: 4 additions & 4 deletions src/ArchonCrystal.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ export default class ArchonCrystal {
/**
*
* @param {Object} crystal The archon crystal object
* @param {string} local The locale to get translations in
* @param {string} locale The locale to get translations in
*/
constructor(crystal, local) {
constructor(crystal, locale = 'en') {
/**
* Archon shard color
* @type {String}
*/
this.color = archonShardColor(crystal.Color, local);
this.color = archonShardColor(crystal.Color, locale);

/**
* Archon shard modifier
* @type {String}
*/
this.modifier = archonShardUpgradeType(crystal.Color, crystal.UpgradeType, local);
this.modifier = archonShardUpgradeType(crystal.Color, crystal.UpgradeType, locale);
}
}
2 changes: 1 addition & 1 deletion src/ItemConfig.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { colors } from 'warframe-items/utilities';

import Skin from './Skin.js';
import mapToHex from './Util.js';
import { mapToHex } from './Utils.js';

/**
* Item customizations such as colors and applied skins
Expand Down
13 changes: 7 additions & 6 deletions src/LoadOutInventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ export default class LoadOutInventory {
/**
*
* @param {Object} item The loadout data
* @param {string} [locale='en'] The locale to return loudout items in
*/
constructor(item) {
constructor(item, locale = 'en') {
/**
* Skins applied to weapons
* @type {WeaponSkin}
Expand All @@ -22,30 +23,30 @@ export default class LoadOutInventory {
* An array of the player's currently equiped Warframe (or powersuits)
* @type {LoadOutItem}
*/
this.suits = item.Suits.map((s) => new LoadOutItem(s));
this.suits = item.Suits.map((s) => new LoadOutItem(s, locale));

/**
* An array of the player's currently equiped secondary weapon
* @type {LoadOutItem | undefined}
*/
this.secondary = item.Pistols?.map((p) => new LoadOutItem(p));
this.secondary = item.Pistols?.map((p) => new LoadOutItem(p, locale));

/**
* An array of the player's currently equiped primary weapon
* @type {LoadOutItem | undefined}
*/
this.primary = item.LongGuns?.map((lg) => new LoadOutItem(lg));
this.primary = item.LongGuns?.map((lg) => new LoadOutItem(lg, locale));

/**
* An array of the player's currently equiped melee weapon
* @type {LoadOutItem | undefined}
*/
this.melee = item.Melee?.map((m) => new LoadOutItem(m));
this.melee = item.Melee?.map((m) => new LoadOutItem(m, locale));

/**
* Items that have counted towards the players mastery rank
* @type {XpInfo}
*/
this.xpInfo = item.XPInfo.map((xp) => new XpInfo(xp));
this.xpInfo = item.XPInfo.map((xp) => new XpInfo(xp, locale));
}
}
8 changes: 5 additions & 3 deletions src/LoadOutItem.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { colors, find } from 'warframe-items/utilities';
import { colors } from 'warframe-items/utilities';
import { parseDate, toTitleCase } from 'warframe-worldstate-data/utilities';

import ItemConfig from './ItemConfig.js';
import Polarity from './Polarity.js';
import { find } from './Utils.js';

/**
* An an item in LoadOutInventory
Expand All @@ -12,8 +13,9 @@ export default class LoadOutItem {
/**
*
* @param {Object} weapon The loadout item from LoadoutInventory
* @param {string} [locale='en'] The locale to return item in
*/
constructor(weapon) {
constructor(weapon, locale = 'en') {
/**
* Item ID
* @type {String}
Expand All @@ -26,7 +28,7 @@ export default class LoadOutItem {
*/
this.uniqueName = weapon.ItemType;

const item = find.findItem(weapon.ItemType);
const item = find(weapon.ItemType, locale);
if (item) {
/**
* Item in-game name
Expand Down
2 changes: 1 addition & 1 deletion src/Mission.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default class Mission {
* @param {Object} mission The mission data
* @param {string} locale The locale to return in
*/
constructor(mission, locale) {
constructor(mission, locale = 'en') {
const uniqueName = mission.type || mission.Tag;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/OperatorLoadOuts.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { colors } from 'warframe-items/utilities';

import Skin from './Skin.js';
import mapToHex from './Util.js';
import { mapToHex } from './Utils.js';

/**
* Player's operator loadout
Expand Down
4 changes: 2 additions & 2 deletions src/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class Profile {
* @param {Object} profile The profile data to parse
* @param {string} locale The locale to return in where possible
*/
constructor(profile, locale) {
constructor(profile, locale = 'en') {
/**
* Player's acount ID
* @type {Stirng}
Expand All @@ -40,7 +40,7 @@ export default class Profile {
* Current loadout
* @type {LoadOutInventory}
*/
this.loadout = new LoadOutInventory(profile.LoadOutInventory);
this.loadout = new LoadOutInventory(profile.LoadOutInventory, locale);

/**
* Railjack and drifter Intrinsics
Expand Down
2 changes: 1 addition & 1 deletion src/ProfileParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default class ProfileParser {
* @param {Object} data The data returned by getProfile endpoint
* @param {string} locale The locale to return where possible
*/
constructor(data, locale) {
constructor(data, locale = 'en') {
/**
* Player's profile
* @type {Profile}
Expand Down
7 changes: 4 additions & 3 deletions src/Skin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { find } from 'warframe-items/utilities';
import { find } from './Utils.js';

/**
* A skin class
Expand All @@ -8,15 +8,16 @@ export default class Skin {
/**
*
* @param {Object} skin The skin data to parse
* @param {string} [locale='en'] The locale to return skin item in
*/
constructor(skin) {
constructor(skin, locale = 'en') {
/**
* Unique name
* @type {String}
*/
this.uniqueName = skin.ItemType;

const item = find.findItem(skin.ItemType);
const item = find(skin.ItemType, locale);
/**
* The Warframe item that matches the unique name
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Syndicate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class Syndicate {
* @param {Object} affiliation The syndicate data
* @param {string} locale locale code
*/
constructor(affiliation, locale) {
constructor(affiliation, locale = 'en') {
// TODO: name is readable but still might want to clean them up
// i.e "NewLokaSyndicate" can be "New Loka"" instead

Expand Down
14 changes: 0 additions & 14 deletions src/Util.js

This file was deleted.

64 changes: 64 additions & 0 deletions src/Utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import Items from 'warframe-items';

/** @module */

/**
* Map base10 int colors to hex color strings
* @param {Record<string, number | undefined>} colors color map
* @returns {Record<string, string>}
*/
export const mapToHex = (colors) => {
const hex = {};
Object.entries(colors).forEach(([key, /** @type {undefined | number} */ value]) => {
hex[key] = Math.abs(value).toString(16).toUpperCase();
});
return hex;
};

const categories = [
'Skins',
'Primary',
'Secondary',
'Melee',
'Arch-Melee',
'Arch-Gun',
'Warframes',
'Archwing',
'Sentinels',
'Pets',
];

/**
* Find an item by Item#uniqueName
* @param {string} name string with which to query
* @param {string} [locale='en'] locale to use for internationalization
* @returns {Item}
*/
export const find = (name, locale = 'en') => {
const items = new Items({
category: categories,
i18n: locale,
i18nOnObject: true,
});

const item = items.find((i) => i.uniqueName === name);

let itemClone = { ...item };
if (locale !== 'en' && itemClone.i18n[locale] && itemClone.i18n[locale]) {
itemClone = { ...itemClone, ...itemClone.i18n[locale] };

if (itemClone.abilities) {
itemClone.abilities = itemClone.abilities.map((ability) => ({
uniqueName: ability.abilityUniqueName || ability.uniqueName || undefined,
name: ability.abilityName || ability.name,
description: ability.abilityDescription || ability.description,
imageName: ability.imageName ?? undefined,
}));
}

delete itemClone.i18n;
return itemClone;
}

return item;
};
7 changes: 4 additions & 3 deletions src/XpInfo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { find } from 'warframe-items/utilities';
import { find } from './Utils.js';

/**
* An item that has contributed to a player's mastery rank
Expand All @@ -8,8 +8,9 @@ export default class XpInfo {
/**
*
* @param {Object} info The info for a given ranked item
* @param {string} locale langauge to return item in
*/
constructor(info) {
constructor(info, locale = 'en') {
/**
* Unique name
* @type {String}
Expand All @@ -26,6 +27,6 @@ export default class XpInfo {
* The item corrosponding to the unique name.
* @type {module:"warframe-items".Item | undefined}
*/
this.item = find.findItem(info.ItemType);
this.item = find(info.ItemType, locale);
}
}
2 changes: 1 addition & 1 deletion test/unit/archonCrystal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('ArchonShard', () => {
UpgradeType: '/Lotus/Upgrades/Invigorations/ArchonCrystalUpgrades/ArchonCrystalUpgradeWarframeArmourMaxMythic',
};

const shard = new ArchonCrystal(shardData, 'en');
const shard = new ArchonCrystal(shardData);

assert.strictEqual(shard.color, 'Tauforged Azure');
assert.strictEqual(shard.modifier, '+225 Armor');
Expand Down
2 changes: 1 addition & 1 deletion test/unit/mission.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('Mission', () => {
type: 'SolNode35',
};

const mission = new Mission(data, 'en');
const mission = new Mission(data);

assert.strictEqual(mission.node, 'Arcadia (Mars)');
assert.strictEqual(mission.nodeKey, data.type);
Expand Down
4 changes: 2 additions & 2 deletions test/unit/mock.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ describe('Mock ProfileParser', () => {
it('should handle real data', function () {
this.timeout(20000);

assert.isOk(new ProfileParser(ornstein, 'en'));
assert.isOk(new ProfileParser(tobiah, 'en'));
assert.isOk(new ProfileParser(ornstein));
assert.isOk(new ProfileParser(tobiah));
});
});
});
4 changes: 2 additions & 2 deletions test/unit/stats.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ describe('Mock ProfileParser', () => {
it('should handle real data', function () {
this.timeout(10000);

assert.isOk(new Stats(ornstein.Stats, 'en'));
assert.isOk(new Stats(tobiah.Stats, 'en'));
assert.isOk(new Stats(ornstein.Stats));
assert.isOk(new Stats(tobiah.Stats));
});
});
});
2 changes: 1 addition & 1 deletion test/unit/xpinfo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('XpInfo', () => {
XP: 785691,
};

const xp = new XpInfo(data, 'en');
const xp = new XpInfo(data);

assert.strictEqual(xp.uniqueName, '/Lotus/Weapons/Grineer/LongGuns/GrineerAssaultRifle/TwinGrakatas');
assert.strictEqual(xp.item.name, 'Twin Grakatas');
Expand Down

0 comments on commit 6147471

Please sign in to comment.