aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-04-20 19:16:16 -0500
committermat <github@matdoes.dev>2022-04-20 19:16:16 -0500
commit6b2bdd5b86eb0ebdf67b50bf5f2dcf74044fe914 (patch)
tree986d1f11c1267d9598a15f6031aeee1e2925ea63 /src/cleaners
parent5712e10eec2c9fa881bdf19295808404c56f7d33 (diff)
downloadskyblock-api-6b2bdd5b86eb0ebdf67b50bf5f2dcf74044fe914.tar.gz
skyblock-api-6b2bdd5b86eb0ebdf67b50bf5f2dcf74044fe914.tar.bz2
skyblock-api-6b2bdd5b86eb0ebdf67b50bf5f2dcf74044fe914.zip
store api ids in skyblock-constants
Diffstat (limited to 'src/cleaners')
-rw-r--r--src/cleaners/skyblock/collections.ts8
-rw-r--r--src/cleaners/skyblock/harp.ts15
-rw-r--r--src/cleaners/skyblock/pets.ts8
-rw-r--r--src/cleaners/skyblock/skills.ts8
-rw-r--r--src/cleaners/skyblock/slayers.ts6
-rw-r--r--src/cleaners/skyblock/zones.ts10
6 files changed, 47 insertions, 8 deletions
diff --git a/src/cleaners/skyblock/collections.ts b/src/cleaners/skyblock/collections.ts
index 119e292..fe8ee1d 100644
--- a/src/cleaners/skyblock/collections.ts
+++ b/src/cleaners/skyblock/collections.ts
@@ -1,5 +1,6 @@
import { cleanItemId, hypixelItemNames } from './itemId.js'
import typedHypixelApi from 'typed-hypixel-api'
+import * as constants from '../../constants.js'
const COLLECTIONS = {
'farming': [
@@ -97,13 +98,17 @@ function getCategory(collectionName): CollectionCategory | undefined {
}
export function cleanCollections(data: typedHypixelApi.SkyBlockProfileMember): Collection[] {
+
// collection tiers show up like this: [ GRAVEL_3, GOLD_INGOT_2, MELON_-1, LOG_2:1_7, RAW_FISH:3_-1]
// these tiers are the same for all players in a coop
const playerCollectionTiersRaw: string[] = data?.unlocked_coll_tiers ?? []
const playerCollectionTiers: { [key: string]: number } = {}
+ let rawCollectionNames: Set<string> = new Set()
+
for (const collectionTierNameValueRaw of playerCollectionTiersRaw) {
const [collectionTierNameRaw, collectionTierValueRaw] = collectionTierNameValueRaw.split(/_(?=-?\d+$)/)
+ rawCollectionNames.add(collectionTierNameRaw)
const collectionName = cleanItemId(collectionTierNameRaw)
// ensure it's at least 0
const collectionValue: number = Math.max(parseInt(collectionTierValueRaw), 0)
@@ -113,6 +118,9 @@ export function cleanCollections(data: typedHypixelApi.SkyBlockProfileMember): C
playerCollectionTiers[collectionName] = collectionValue
}
+ constants.addCollections(Array.from(rawCollectionNames))
+
+
// collection names show up like this: { LOG: 49789, LOG:2: 26219, MUSHROOM_COLLECTION: 2923}
// these values are different for each player in a coop
const playerCollectionXpsRaw: { [key in hypixelItemNames]?: number } = data?.collection ?? {}
diff --git a/src/cleaners/skyblock/harp.ts b/src/cleaners/skyblock/harp.ts
index b1ec905..c38013e 100644
--- a/src/cleaners/skyblock/harp.ts
+++ b/src/cleaners/skyblock/harp.ts
@@ -1,5 +1,5 @@
import typedHypixelApi from 'typed-hypixel-api'
-import { fetchHarpSongs } from '../../constants.js'
+import * as constants from '../../constants.js'
export interface HarpSong {
id: string
@@ -26,11 +26,14 @@ export async function cleanHarp(data: typedHypixelApi.SkyBlockProfileMember): Pr
const harpQuestData = data.harp_quest ?? {}
const songs: HarpSong[] = []
- const allHarpSongNames = await fetchHarpSongs()
+ let songIds: string[] = []
+
+ const allHarpSongIds = await constants.fetchHarpSongs()
for (const item in data.harp_quest) {
if (item.startsWith('song_') && item.endsWith('_best_completion')) {
const apiSongName = item.slice('song_'.length, -'_best_completion'.length)
+ songIds.push(apiSongName)
const songName = renamedSongs[apiSongName] ?? apiSongName
songs.push({
id: songName,
@@ -41,10 +44,12 @@ export async function cleanHarp(data: typedHypixelApi.SkyBlockProfileMember): Pr
}
}
- const missingHarpSongNames = allHarpSongNames.filter(songName => !songs.find(song => (renamedSongs[song.id] ?? song.id) === songName))
- for (const songName of missingHarpSongNames) {
+ constants.addHarpSongs(songIds)
+
+ const missingHarpSongId = allHarpSongIds.filter(songId => !songIds.includes(songId))
+ for (const songId of missingHarpSongId) {
songs.push({
- id: renamedSongs[songName] ?? songName,
+ id: renamedSongs[songId] ?? songId,
completions: 0,
perfectCompletions: 0,
progress: 0
diff --git a/src/cleaners/skyblock/pets.ts b/src/cleaners/skyblock/pets.ts
index 031924a..4ee7cda 100644
--- a/src/cleaners/skyblock/pets.ts
+++ b/src/cleaners/skyblock/pets.ts
@@ -1,8 +1,8 @@
import typedHypixelApi from 'typed-hypixel-api'
import { fetchItemList } from '../../hypixel.js'
import { levelFromXpTable } from '../../util.js'
-import { fetchPets } from '../../constants.js'
import { ItemListItem } from './itemList.js'
+import * as constants from '../../constants.js'
// https://hypixel-skyblock.fandom.com/wiki/Module:Pet/LevelingData?action=edit
@@ -57,12 +57,15 @@ export async function cleanPets(data: typedHypixelApi.SkyBlockProfileMember): Pr
const obtainedPets: Pet[] = []
let activePet: Pet | null = null
- const allPetIds = await fetchPets()
+ const allPetIds = await constants.fetchPets()
const obtainedPetIds: string[] = []
const itemList = await fetchItemList()
+ let petIds: string[] = []
+
for (const petData of data.pets ?? []) {
+ petIds.push(petData.type)
const xpTable = RARITY_XP_TABLES[petData.tier] ?? RARITY_XP_TABLES.LEGENDARY
const level = levelFromXpTable(petData.exp, xpTable)
const pet: Pet = {
@@ -80,6 +83,7 @@ export async function cleanPets(data: typedHypixelApi.SkyBlockProfileMember): Pr
activePet = pet
}
+ constants.addPets(petIds)
const missingPetIds = allPetIds.filter(id => !obtainedPetIds.includes(id))
return {
diff --git a/src/cleaners/skyblock/skills.ts b/src/cleaners/skyblock/skills.ts
index 9aa3fb7..d035a96 100644
--- a/src/cleaners/skyblock/skills.ts
+++ b/src/cleaners/skyblock/skills.ts
@@ -1,6 +1,7 @@
import typedHypixelApi from 'typed-hypixel-api'
import { fetchSkills } from '../../constants.js'
import { levelFromXpTable } from '../../util.js'
+import * as constants from '../../constants.js'
export interface Skill {
name: string
@@ -139,9 +140,13 @@ export function levelForSkillXp(xp: number, maxLevel: number) {
export async function cleanSkills(data: typedHypixelApi.SkyBlockProfileMember): Promise<Skill[]> {
const allSkillNames = await fetchSkills()
const skills: Skill[] = []
+
+ let skillNamesFound: string[] = []
+
for (const item in data) {
if (item.startsWith('experience_skill_')) {
const skillName = item.slice('experience_skill_'.length)
+ skillNamesFound.push(skillName)
// the amount of total xp you have in this skill
const skillXp: number = data[item]
@@ -173,6 +178,9 @@ export async function cleanSkills(data: typedHypixelApi.SkyBlockProfileMember):
}
}
+ constants.addSkills(skillNamesFound)
+
+
// add missing skills
const missingSkillNames = allSkillNames.filter(skillName => !skills.some(skill => skill.name === skillName))
for (const skillName of missingSkillNames) {
diff --git a/src/cleaners/skyblock/slayers.ts b/src/cleaners/skyblock/slayers.ts
index 94c23f0..f70ddc5 100644
--- a/src/cleaners/skyblock/slayers.ts
+++ b/src/cleaners/skyblock/slayers.ts
@@ -1,4 +1,5 @@
import typedHypixelApi from 'typed-hypixel-api'
+import * as constants from '../../constants.js'
const SLAYER_NAMES = {
@@ -48,7 +49,10 @@ export function cleanSlayers(data: typedHypixelApi.SkyBlockProfileMember): Slaye
let totalXp: number = 0
let totalKills: number = 0
+ let slayerIds: string[] = []
+
for (const slayerNameRaw in slayersDataRaw) {
+ slayerIds.push(slayerNameRaw)
const slayerDataRaw = slayersDataRaw[slayerNameRaw]
// convert name provided by api (spider) to the real name (tarantula)
@@ -108,6 +112,8 @@ export function cleanSlayers(data: typedHypixelApi.SkyBlockProfileMember): Slaye
totalKills += slayerKills
}
+ constants.addSlayers(slayerIds)
+
return {
xp: totalXp,
kills: totalKills,
diff --git a/src/cleaners/skyblock/zones.ts b/src/cleaners/skyblock/zones.ts
index 556a2e7..92f4e81 100644
--- a/src/cleaners/skyblock/zones.ts
+++ b/src/cleaners/skyblock/zones.ts
@@ -6,9 +6,17 @@ export interface Zone {
visited: boolean
}
+export function zoneIdToName(id: string) {
+ // this currently does nothing, but in the future it could get data from https://api.hypixel.net/resources/games
+ return id
+}
+
export async function cleanVisitedZones(data: typedHypixelApi.SkyBlockProfileMember): Promise<Zone[]> {
const rawZones = data?.visited_zones || []
+
+ constants.addZones(rawZones)
+
// TODO: store all the zones that exist in SkyBlock, add add those to the array with visited being false
const zones: Zone[] = []
@@ -16,7 +24,7 @@ export async function cleanVisitedZones(data: typedHypixelApi.SkyBlockProfileMem
for (const rawZoneName of knownZones) {
zones.push({
- name: rawZoneName,
+ name: zoneIdToName(rawZoneName),
visited: rawZones.includes(rawZoneName)
})
}