diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2021-02-14 14:19:28 -0600 |
---|---|---|
committer | mat <27899617+mat-1@users.noreply.github.com> | 2021-02-14 14:19:28 -0600 |
commit | 5e8649c2e0244150873e30ce1420b0e9a6f3f5a2 (patch) | |
tree | 87777683475d1badb919d5749a9718c1d30aa7ee /src/cleaners/skyblock | |
parent | eedd4ff7a3f2816c8e0d3f037c7a1acbb5988495 (diff) | |
download | skyblock-api-5e8649c2e0244150873e30ce1420b0e9a6f3f5a2.tar.gz skyblock-api-5e8649c2e0244150873e30ce1420b0e9a6f3f5a2.tar.bz2 skyblock-api-5e8649c2e0244150873e30ce1420b0e9a6f3f5a2.zip |
add collection categories
Diffstat (limited to 'src/cleaners/skyblock')
-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 |