2024-01-25 14:49:45 +01:00
|
|
|
import { getIndexAfter } from "@/src/helpers/stringHelpers";
|
|
|
|
import { logger } from "@/src/utils/logger";
|
2024-06-17 16:41:02 +02:00
|
|
|
import Items, { Category, MinimalItem, Warframe, Weapon } from "warframe-items";
|
2024-05-31 14:15:43 +02:00
|
|
|
import badItems from "@/static/json/exclude-mods.json";
|
2024-06-17 16:41:02 +02:00
|
|
|
import {
|
|
|
|
dict_en,
|
|
|
|
ExportRecipes,
|
|
|
|
ExportWarframes,
|
|
|
|
ExportWeapons,
|
|
|
|
IPowersuit,
|
|
|
|
IRecipe
|
|
|
|
} from "warframe-public-export-plus";
|
2024-01-25 14:49:45 +01:00
|
|
|
|
2024-05-04 14:44:23 +02:00
|
|
|
export type MinWarframe = Omit<Warframe, "patchlogs">;
|
|
|
|
export type MinWeapon = Omit<Weapon, "patchlogs">;
|
|
|
|
export type MinItem = Omit<MinimalItem, "patchlogs">;
|
2024-01-25 14:49:45 +01:00
|
|
|
|
2024-06-10 14:03:03 +02:00
|
|
|
export type WeaponTypeInternal =
|
|
|
|
| "LongGuns"
|
|
|
|
| "Pistols"
|
|
|
|
| "Melee"
|
|
|
|
| "SpaceMelee"
|
|
|
|
| "SpaceGuns"
|
|
|
|
| "SentinelWeapons"
|
|
|
|
| "OperatorAmps"
|
|
|
|
| "SpecialItems";
|
2024-01-25 14:49:45 +01:00
|
|
|
|
2024-05-04 14:44:23 +02:00
|
|
|
export const items: MinItem[] = Array.from(new Items({ category: ["All"] }) as MinimalItem[]).map(item => {
|
2024-01-25 14:49:45 +01:00
|
|
|
const next = { ...item };
|
|
|
|
delete next.patchlogs;
|
|
|
|
return next;
|
|
|
|
});
|
|
|
|
|
2024-06-10 14:03:03 +02:00
|
|
|
export const getWeaponType = (weaponName: string): WeaponTypeInternal => {
|
|
|
|
const weaponInfo = ExportWeapons[weaponName];
|
2024-01-25 14:49:45 +01:00
|
|
|
|
|
|
|
if (!weaponInfo) {
|
|
|
|
throw new Error(`unknown weapon ${weaponName}`);
|
|
|
|
}
|
|
|
|
|
2024-06-06 14:23:46 +02:00
|
|
|
// Many non-weapon items are "Pistols" in Public Export, so some duck typing is needed.
|
|
|
|
if (weaponInfo.totalDamage == 0) {
|
|
|
|
throw new Error(`${weaponName} doesn't quack like a weapon`);
|
|
|
|
}
|
|
|
|
|
2024-06-10 14:03:03 +02:00
|
|
|
const weaponType = weaponInfo.productCategory;
|
2024-01-25 14:49:45 +01:00
|
|
|
|
|
|
|
if (!weaponType) {
|
|
|
|
logger.error(`unknown weapon category for item ${weaponName}`);
|
|
|
|
throw new Error(`unknown weapon category for item ${weaponName}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
return weaponType;
|
|
|
|
};
|
|
|
|
|
|
|
|
const getNamesObj = (category: Category) =>
|
|
|
|
new Items({ category: [category] }).reduce<{ [index: string]: string }>((acc, item) => {
|
2024-05-31 14:15:43 +02:00
|
|
|
if (!(item.uniqueName! in badItems)) {
|
|
|
|
acc[item.name!.replace("'S", "'s")] = item.uniqueName!;
|
|
|
|
}
|
2024-01-25 14:49:45 +01:00
|
|
|
return acc;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
export const modNames = getNamesObj("Mods");
|
|
|
|
export const resourceNames = getNamesObj("Resources");
|
|
|
|
export const miscNames = getNamesObj("Misc");
|
|
|
|
export const relicNames = getNamesObj("Relics");
|
|
|
|
export const skinNames = getNamesObj("Skins");
|
|
|
|
export const arcaneNames = getNamesObj("Arcanes");
|
|
|
|
export const gearNames = getNamesObj("Gear");
|
|
|
|
//logger.debug(`gear names`, { gearNames });
|
|
|
|
|
|
|
|
export const craftNames = Object.fromEntries(
|
|
|
|
(
|
|
|
|
new Items({
|
|
|
|
category: [
|
|
|
|
"Warframes",
|
|
|
|
"Gear",
|
|
|
|
"Melee",
|
|
|
|
"Primary",
|
|
|
|
"Secondary",
|
|
|
|
"Sentinels",
|
|
|
|
"Misc",
|
|
|
|
"Arch-Gun",
|
|
|
|
"Arch-Melee"
|
|
|
|
]
|
|
|
|
}) as Warframe[]
|
|
|
|
)
|
|
|
|
.flatMap(item => item.components || [])
|
|
|
|
.filter(item => item.drops && item.drops[0])
|
|
|
|
.map(item => [item.drops![0].type, item.uniqueName])
|
|
|
|
);
|
|
|
|
|
|
|
|
export const blueprintNames = Object.fromEntries(
|
|
|
|
Object.keys(craftNames)
|
|
|
|
.filter(name => name.includes("Blueprint"))
|
|
|
|
.map(name => [name, craftNames[name]])
|
|
|
|
);
|
|
|
|
|
2024-06-17 16:41:02 +02:00
|
|
|
// Gets a recipe by its uniqueName
|
|
|
|
export const getItemByBlueprint = (uniqueName: string): IRecipe | undefined => {
|
|
|
|
return ExportRecipes[uniqueName];
|
2024-01-25 14:49:45 +01:00
|
|
|
};
|
|
|
|
|
2024-06-07 15:58:20 +02:00
|
|
|
export const getExalted = (uniqueName: string) => {
|
|
|
|
const suit = getSuitByUniqueName(uniqueName);
|
|
|
|
if (suit?.exalted !== undefined) {
|
|
|
|
return suit.exalted;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-01-25 14:49:45 +01:00
|
|
|
export const getItemCategoryByUniqueName = (uniqueName: string) => {
|
|
|
|
//Lotus/Types/Items/MiscItems/PolymerBundle
|
|
|
|
|
|
|
|
let splitWord = "Items/";
|
|
|
|
if (!uniqueName.includes("/Items/")) {
|
|
|
|
splitWord = "/Types/";
|
|
|
|
}
|
|
|
|
|
|
|
|
const index = getIndexAfter(uniqueName, splitWord);
|
|
|
|
if (index === -1) {
|
|
|
|
logger.error(`error parsing item category ${uniqueName}`);
|
|
|
|
throw new Error(`error parsing item category ${uniqueName}`);
|
|
|
|
}
|
|
|
|
const category = uniqueName.substring(index).split("/")[0];
|
|
|
|
return category;
|
|
|
|
};
|
|
|
|
|
2024-06-10 14:03:03 +02:00
|
|
|
export const getSuitByUniqueName = (uniqueName: string): IPowersuit | undefined => {
|
|
|
|
return ExportWarframes[uniqueName];
|
2024-06-07 15:58:20 +02:00
|
|
|
};
|
|
|
|
|
2024-01-25 14:49:45 +01:00
|
|
|
export const getItemByUniqueName = (uniqueName: string) => {
|
|
|
|
const item = items.find(item => item.uniqueName === uniqueName);
|
|
|
|
return item;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getItemByName = (name: string) => {
|
|
|
|
const item = items.find(item => item.name === name);
|
|
|
|
return item;
|
|
|
|
};
|
2024-06-02 17:37:09 +02:00
|
|
|
|
2024-06-10 14:03:03 +02:00
|
|
|
export const getEnglishString = (key: string): string => {
|
|
|
|
return dict_en[key] ?? key;
|
2024-06-02 17:37:09 +02:00
|
|
|
};
|