From 5e8649c2e0244150873e30ce1420b0e9a6f3f5a2 Mon Sep 17 00:00:00 2001 From: mat <27899617+mat-1@users.noreply.github.com> Date: Sun, 14 Feb 2021 14:19:28 -0600 Subject: add collection categories --- src/cleaners/skyblock/collections.ts | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) (limited to 'src/cleaners/skyblock') diff --git a/src/cleaners/skyblock/collections.ts b/src/cleaners/skyblock/collections.ts index a70d7b8..3b1a178 100644 --- a/src/cleaners/skyblock/collections.ts +++ b/src/cleaners/skyblock/collections.ts @@ -69,13 +69,27 @@ const COLLECTIONS = { 'lily_pad', 'ink_sac', 'sponge' - ] + ], + // no item should be here, but in case a new collection is added itll default to this + 'unknown': [] } as const +type CollectionCategory = keyof typeof COLLECTIONS + export interface Collection { name: string xp: number level: number + category: CollectionCategory +} + +// get a category name (farming) from a collection name (wheat) +function getCategory(collectionName): CollectionCategory { + for (const categoryName in COLLECTIONS) { + const categoryItems = COLLECTIONS[categoryName] + if (categoryItems.includes(collectionName)) + return categoryName as CollectionCategory + } } export function cleanCollections(data: any): Collection[] { @@ -103,11 +117,17 @@ export function cleanCollections(data: any): Collection[] { for (const collectionNameRaw in playerCollectionValuesRaw) { const collectionValue: number = playerCollectionValuesRaw[collectionNameRaw] const collectionName = cleanItemId(collectionNameRaw) - playerCollectionValues.push({ - name: collectionName, - xp: collectionValue, - level: playerCollectionTiers[collectionName] - }) + const collectionLevel = playerCollectionTiers[collectionName] + const collectionCategory = getCategory(collectionName) ?? 'unknown' + + // in some very weird cases the collection level will be undefined, we should ignore these collections + if (collectionLevel !== undefined) + playerCollectionValues.push({ + name: collectionName, + xp: collectionValue, + level: collectionLevel, + category: collectionCategory + }) } return playerCollectionValues } \ No newline at end of file -- cgit