diff --git a/src/controllers/dynamic/getProfileViewingDataController.ts b/src/controllers/dynamic/getProfileViewingDataController.ts index 808c3242..40e57c58 100644 --- a/src/controllers/dynamic/getProfileViewingDataController.ts +++ b/src/controllers/dynamic/getProfileViewingDataController.ts @@ -20,13 +20,14 @@ import type { } from "../../types/inventoryTypes/inventoryTypes.ts"; import { LoadoutIndex } from "../../types/inventoryTypes/inventoryTypes.ts"; import type { RequestHandler } from "express"; -import { catBreadHash, getJSONfromString } from "../../helpers/stringHelpers.ts"; -import { ExportCustoms, ExportDojoRecipes } from "warframe-public-export-plus"; +import { getJSONfromString } from "../../helpers/stringHelpers.ts"; +import { ExportDojoRecipes } from "warframe-public-export-plus"; import type { IStatsClient } from "../../types/statTypes.ts"; import { toStoreItem } from "../../services/itemDataService.ts"; import type { FlattenMaps } from "mongoose"; import type { IEquipmentClient } from "../../types/equipmentTypes.ts"; import type { ILoadoutConfigClient } from "../../types/saveLoadoutTypes.ts"; +import { skinLookupTable } from "../../helpers/skinLookupTable.ts"; const getProfileViewingDataByPlayerIdImpl = async (playerId: string): Promise => { const account = await Account.findById(playerId, "DisplayName"); @@ -261,8 +262,6 @@ interface IXPComponentClient { locTags?: Record; } -let skinLookupTable: Record | undefined; - const resolveAndCollectSkins = ( inventory: TInventoryDatabaseDocument, skins: Set, @@ -274,12 +273,6 @@ const resolveAndCollectSkins = ( // Resolve oids to type names if (config.Skins[i].length == 24) { if (config.Skins[i].substring(0, 16) == "ca70ca70ca70ca70") { - if (!skinLookupTable) { - skinLookupTable = {}; - for (const key of Object.keys(ExportCustoms)) { - skinLookupTable[catBreadHash(key)] = key; - } - } config.Skins[i] = skinLookupTable[parseInt(config.Skins[i].substring(16), 16)]; } else { const skinItem = inventory.WeaponSkins.id(config.Skins[i]); diff --git a/src/helpers/skinLookupTable.ts b/src/helpers/skinLookupTable.ts new file mode 100644 index 00000000..24e7496f --- /dev/null +++ b/src/helpers/skinLookupTable.ts @@ -0,0 +1,8 @@ +import { ExportCustoms } from "warframe-public-export-plus"; +import { catBreadHash } from "./stringHelpers.ts"; + +export const skinLookupTable: Record = {}; + +for (const key of Object.keys(ExportCustoms)) { + skinLookupTable[catBreadHash(key)] = key; +} diff --git a/src/services/inventoryService.ts b/src/services/inventoryService.ts index 92d48d4c..560dbc20 100644 --- a/src/services/inventoryService.ts +++ b/src/services/inventoryService.ts @@ -83,7 +83,7 @@ import type { INemesisProfile } from "../helpers/nemesisHelpers.ts"; import { generateNemesisProfile } from "../helpers/nemesisHelpers.ts"; import type { TAccountDocument } from "./loginService.ts"; import { unixTimesInMs } from "../constants/timeConstants.ts"; -import { addString, catBreadHash } from "../helpers/stringHelpers.ts"; +import { addString } from "../helpers/stringHelpers.ts"; import type { IEquipmentClient, IEquipmentDatabase, @@ -92,6 +92,7 @@ import type { } from "../types/equipmentTypes.ts"; import { EquipmentFeatures, Status } from "../types/equipmentTypes.ts"; import type { ITypeCount } from "../types/commonTypes.ts"; +import { skinLookupTable } from "../helpers/skinLookupTable.ts"; export const createInventory = async ( accountOwnerId: Types.ObjectId, @@ -2371,6 +2372,25 @@ export const cleanupInventory = async (inventory: TInventoryDatabaseDocument): P } }; +const collectSkins = (skins: string[], weaponMap: Map, itemsToAdd: Set): void => { + for (const skinId of skins) { + if (skinId.startsWith("ca70ca70ca70ca70")) { + const typeName = skinLookupTable[parseInt(skinId.slice(16), 16)]; + if (!weaponMap.has(typeName)) itemsToAdd.add(typeName); + } + } +}; + +const replaceSkinIds = (skins: string[], weaponMap: Map): void => { + for (let i = 0; i < skins.length; i++) { + const skinId = skins[i]; + if (skinId.startsWith("ca70ca70ca70ca70")) { + const inventoryId = weaponMap.get(skinLookupTable[parseInt(skinId.slice(16), 16)]); + if (inventoryId) skins[i] = inventoryId; + } + } +}; + export const getDialogue = (inventory: TInventoryDatabaseDocument, dialogueName: string): IDialogueDatabase => { inventory.DialogueHistory ??= {}; inventory.DialogueHistory.Dialogues ??= []; @@ -2560,27 +2580,3 @@ export const updateEntratiVault = (inventory: TInventoryDatabaseDocument): void } } }; - -const skinLookupTable: Record = {}; -for (const key of Object.keys(ExportCustoms)) { - skinLookupTable[catBreadHash(key)] = key; -} - -const collectSkins = (skins: string[], weaponMap: Map, itemsToAdd: Set): void => { - for (const skinId of skins) { - if (skinId.startsWith("ca70ca70ca70ca70")) { - const typeName = skinLookupTable[parseInt(skinId.slice(16), 16)]; - if (!weaponMap.has(typeName)) itemsToAdd.add(typeName); - } - } -}; - -const replaceSkinIds = (skins: string[], weaponMap: Map): void => { - for (let i = 0; i < skins.length; i++) { - const skinId = skins[i]; - if (skinId.startsWith("ca70ca70ca70ca70")) { - const inventoryId = weaponMap.get(skinLookupTable[parseInt(skinId.slice(16), 16)]); - if (inventoryId) skins[i] = inventoryId; - } - } -};