diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cleaners/skyblock/collections.ts | 32 |
1 files changed, 26 insertions, 6 deletions
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 |