diff options
author | nea <nea@nea.moe> | 2023-05-27 23:38:16 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-05-27 23:38:16 +0200 |
commit | e8b96e41327506fc0f651c9106aa56347b27b83b (patch) | |
tree | fd77e9005e68231dc992ce538e5519b4dc489dc3 /src/cleaners/skyblock/inventory.ts | |
parent | e99e8d2693f046449bd74c8cbdabb9bd88621a87 (diff) | |
download | skyblock-api-feat/backpacks.tar.gz skyblock-api-feat/backpacks.tar.bz2 skyblock-api-feat/backpacks.zip |
Add backpacks to inventoriesfeat/backpacks
Diffstat (limited to 'src/cleaners/skyblock/inventory.ts')
-rw-r--r-- | src/cleaners/skyblock/inventory.ts | 25 |
1 files changed, 24 insertions, 1 deletions
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<Inventories> { 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 |