From e8b96e41327506fc0f651c9106aa56347b27b83b Mon Sep 17 00:00:00 2001 From: nea Date: Sat, 27 May 2023 23:38:16 +0200 Subject: Add backpacks to inventories --- src/cleaners/skyblock/inventory.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/cleaners') diff --git a/src/cleaners/skyblock/inventory.ts b/src/cleaners/skyblock/inventory.ts index b5c85e2..5df3eb1 100644 --- a/src/cleaners/skyblock/inventory.ts +++ b/src/cleaners/skyblock/inventory.ts @@ -107,7 +107,13 @@ export const INVENTORIES = { personal_vault: 'personal_vault_contents' } -export type Inventories = { [name in keyof typeof INVENTORIES]: Item[] } +export type Backpack = { + icon: Item | null, + items: Item[], + slot: string, +}; + +export type Inventories = { backpacks: Backpack[] } & { [name in keyof typeof INVENTORIES]: Item[] } export async function cleanInventories(data: typedHypixelApi.SkyBlockProfileMember): Promise { const cleanInventories: any = {} @@ -125,5 +131,22 @@ export async function cleanInventories(data: typedHypixelApi.SkyBlockProfileMemb cleanInventories[cleanInventoryName] = inventoryContents } } + const backpacks = data.backpack_contents + const backpackIcons = data.backpack_icons ?? {}; + const cleanBackpacks: Backpack[] = []; + if (backpacks) { + for (const backpackId in backpacks) { + const backpack = backpacks[backpackId] + const contents = await cleanInventory(backpack.data) + const icon = backpackIcons[backpackId] + + cleanBackpacks.push({ + items: contents, + slot: backpackId, + icon: (icon && (await cleanInventory(icon.data))[0]) ?? null, + }) + } + } + cleanInventories['backpacks'] = cleanBackpacks; return cleanInventories } \ No newline at end of file -- cgit