aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-05-20 21:01:22 -0500
committermat <github@matdoes.dev>2022-05-20 21:01:22 -0500
commitfad0de1fec8c3ac5eea06000f0bc31c769a33145 (patch)
tree0e7b71f7315398a2bebc17fc7732bd7387150784
parent1590406fdc3ce3d31b3f9f1b45d0bbf4ad07af31 (diff)
downloadskyblock-api-fad0de1fec8c3ac5eea06000f0bc31c769a33145.tar.gz
skyblock-api-fad0de1fec8c3ac5eea06000f0bc31c769a33145.tar.bz2
skyblock-api-fad0de1fec8c3ac5eea06000f0bc31c769a33145.zip
sort achievements
-rw-r--r--src/cleaners/achievements.ts24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/cleaners/achievements.ts b/src/cleaners/achievements.ts
index 2e75cc6..5d10209 100644
--- a/src/cleaners/achievements.ts
+++ b/src/cleaners/achievements.ts
@@ -11,7 +11,7 @@ interface TieredAchievement {
interface ChallengeAchievement {
id: string
name: string
- achieved: boolean
+ unlocked: boolean
description: string
}
@@ -37,18 +37,30 @@ export async function cleanPlayerAchievements(data: typedHypixelApi.PlayerDataRe
description: value ? achievementData.description.replace(/%s/g, value.toString()) : achievementData.description
})
}
+ tieredAchievements.sort((a, b) => (b.value ?? 0) - (a.value ?? 0))
+
+ let unlockedChallengeAchievements: ChallengeAchievement[] = []
+ let lockedChallengeAchievements: ChallengeAchievement[] = []
- let challengeAchievements: ChallengeAchievement[] = []
for (const [achievementId, achievementData] of Object.entries(achievementsData.one_time)) {
- challengeAchievements.push({
+ const achievement: ChallengeAchievement = {
id: achievementId.toLowerCase(),
name: achievementData.name,
- achieved: data.achievementsOneTime.includes(`skyblock_${achievementId.toLowerCase()}`),
+ unlocked: data.achievementsOneTime.includes(`skyblock_${achievementId.toLowerCase()}`),
description: achievementData.description
- })
+ }
+ if (achievement.unlocked)
+ unlockedChallengeAchievements.push(achievement)
+ else
+ lockedChallengeAchievements.push(achievement)
}
- return { tiered: tieredAchievements, challenge: challengeAchievements }
+ return {
+ tiered: tieredAchievements, challenge: [
+ ...unlockedChallengeAchievements,
+ ...lockedChallengeAchievements
+ ]
+ }
}
// this shouldn't be possible