From 9cfb8eb66288e325ae4e0e171e33fa99f871efc7 Mon Sep 17 00:00:00 2001 From: DuckySoLucky Date: Wed, 26 Jun 2024 01:35:13 +0200 Subject: [PATCH] fix(stats): types and some other things for svelte-check --- .github/workflows/webiste.yml | 2 +- src/lib/components/Item.svelte | 6 +++--- src/lib/constants/NotEnoughUpdates-REPO | 2 +- src/lib/sections/stats/Accessories.svelte | 4 ++-- src/lib/stats/items/stats.ts | 5 ++--- src/lib/stats/missing.ts | 4 ++++ src/lib/stats/player_stats.ts | 4 ++-- src/lib/stats/slayer.ts | 5 ++--- src/types/processed/profile/items.d.ts | 4 ++++ src/types/stats.d.ts | 2 +- 10 files changed, 22 insertions(+), 16 deletions(-) diff --git a/.github/workflows/webiste.yml b/.github/workflows/webiste.yml index a8f0d19bb..d38d00dfa 100644 --- a/.github/workflows/webiste.yml +++ b/.github/workflows/webiste.yml @@ -8,7 +8,7 @@ on: paths: ["src/**", ".github/workflows/website.yml"] env: - NODE_VERSION: "19" + NODE_VERSION: "21" CONTAINER_REGISTRY: ghcr.io IMAGE_NAME: ${{ github.repository }} diff --git a/src/lib/components/Item.svelte b/src/lib/components/Item.svelte index 2b1613016..b20950cf4 100644 --- a/src/lib/components/Item.svelte +++ b/src/lib/components/Item.svelte @@ -6,7 +6,7 @@ import { Avatar, Tooltip } from "bits-ui"; import Image from "lucide-svelte/icons/image"; - export let piece: ProcessedItem; + export let piece: ProcessedItem | ProcessedPet; export let isInventory = false; export let showCount = true; @@ -16,7 +16,7 @@ const bgColor = piece.rarity ? getRarityClass(piece.rarity.toLowerCase() as string, "bg") : "bg-background"; const enchanted = isEnchanted(piece as ProcessedItem); - const showNumbers = showCount && piece.Count > 1; + const showNumbers = showCount && (piece as ProcessedItem).Count > 1; const processedItem = piece as ProcessedItem; const processedPet = piece as unknown as ProcessedPet; @@ -33,7 +33,7 @@ {#if showNumbers}
- {piece.Count} + {processedItem.Count}
{/if} diff --git a/src/lib/constants/NotEnoughUpdates-REPO b/src/lib/constants/NotEnoughUpdates-REPO index f73d9d055..e3bdcf63a 160000 --- a/src/lib/constants/NotEnoughUpdates-REPO +++ b/src/lib/constants/NotEnoughUpdates-REPO @@ -1 +1 @@ -Subproject commit f73d9d055f133e93ccd7af162be74c529c8b7bfa +Subproject commit e3bdcf63a01b1123598edc901a9ab2c4621c3d68 diff --git a/src/lib/sections/stats/Accessories.svelte b/src/lib/sections/stats/Accessories.svelte index abc567c7c..98b82657b 100644 --- a/src/lib/sections/stats/Accessories.svelte +++ b/src/lib/sections/stats/Accessories.svelte @@ -102,9 +102,9 @@ +{accessories.magicalPower.riftPrism} MP {/if} - {#if accessories.magicalPower.hegemony > 0} + {#if accessories.magicalPower.hegemony.amount > 0 && accessories.magicalPower.hegemony.rarity !== null}
  • - Hegemony Artifact: + Hegemony Artifact: = +{accessories.magicalPower.hegemony} MP
  • diff --git a/src/lib/stats/items/stats.ts b/src/lib/stats/items/stats.ts index af71ff508..3bbf26a28 100644 --- a/src/lib/stats/items/stats.ts +++ b/src/lib/stats/items/stats.ts @@ -1,7 +1,7 @@ -import { getRawLore } from "$lib/helper"; -import type { ProcessedItem } from "$types/stats"; import * as constants from "$constants/constants"; +import { getRawLore } from "$lib/helper"; import type { ItemStats } from "$types/processed/profile/stats"; +import type { ProcessedItem } from "$types/stats"; export function getStatsFromItem(item: ProcessedItem) { const regex = /^([A-Za-z ]+): ([+-]([0-9]+(?:,[0-9]{3})*(?:\.[0-9]{0,2})?))/; @@ -25,7 +25,6 @@ export function getStatsFromItem(item: ProcessedItem) { if (statName) { stats[statName] = 0; - // @ts-expect-error: Object is possibly 'null'. stats[statName] += statValue; } } diff --git a/src/lib/stats/missing.ts b/src/lib/stats/missing.ts index 2c78e84a2..d5f2477e3 100644 --- a/src/lib/stats/missing.ts +++ b/src/lib/stats/missing.ts @@ -186,6 +186,10 @@ export async function getMissingAccessories(items: Accessories, userProfile: Mem accessories: activeAccessories.reduce((a, b) => a + helper.getMagicalPower(b.rarity, helper.getId(b)), 0), abiphone: abiphoneContacts ? Math.floor(abiphoneContacts / 2) : 0, riftPrism: riftPrism ? 11 : 0, + hegemony: { + rarity: activeAccessories.find((a) => helper.getId(a) === "HEGEMONY")?.rarity ?? null, + amount: helper.getMagicalPower(activeAccessories.find((a) => helper.getId(a) === "HEGEMONY")?.rarity ?? "", "HEGEMONY_ARTIFACT") + }, rarities: {} }; diff --git a/src/lib/stats/player_stats.ts b/src/lib/stats/player_stats.ts index 5e105b23b..bdc92b147 100644 --- a/src/lib/stats/player_stats.ts +++ b/src/lib/stats/player_stats.ts @@ -91,7 +91,7 @@ export function getPlayerStats(profile: Stats) { } } - if (profile.slayer.data) { + if (profile.slayer?.data) { for (const [slayer, data] of Object.entries(profile.slayer.data)) { const bonusStats = getBonusStat(data.level.level, `slayer_${slayer}`, data.level.maxLevel); @@ -106,7 +106,7 @@ export function getPlayerStats(profile: Stats) { } } - if (profile.dungeons.level.level > 0) { + if (profile.dungeons?.level?.level !== undefined) { const bonusStats = getBonusStat(profile.dungeons.level.level, "skill_dungeoneering", 50); for (const [name, value] of Object.entries(bonusStats)) { diff --git a/src/lib/stats/slayer.ts b/src/lib/stats/slayer.ts index 0d7476a7a..b76e85aa2 100644 --- a/src/lib/stats/slayer.ts +++ b/src/lib/stats/slayer.ts @@ -1,6 +1,5 @@ -import type { Member, SlayerBoss } from "$types/global"; import * as constants from "$constants/constants"; -import type { Slayer } from "$types/processed/profile/slayer"; +import type { Member, SlayerBoss, SlayerData } from "$types/global"; function getKills(slayer: SlayerBoss) { if (slayer === undefined) { @@ -64,7 +63,7 @@ export function getSlayer(userProfile: Member) { return null; } - const output = { data: {} } as Slayer; + const output = { data: {} } as SlayerData; for (const id of constants.SLAYERS) { const data = slayerData[id]; output.data[id] = { diff --git a/src/types/processed/profile/items.d.ts b/src/types/processed/profile/items.d.ts index 07d23265c..ecc8fb2f3 100644 --- a/src/types/processed/profile/items.d.ts +++ b/src/types/processed/profile/items.d.ts @@ -242,6 +242,10 @@ export type AccessoriesOutput = { accessories: number; abiphone: number; riftPrism: number; + hegemony: { + rarity: string | null; + amount: number; + }; rarities: Record; }; }; diff --git a/src/types/stats.d.ts b/src/types/stats.d.ts index fb1f2eaa0..423a7fc18 100644 --- a/src/types/stats.d.ts +++ b/src/types/stats.d.ts @@ -39,7 +39,7 @@ export type Stats = { mining: MiningStats; farming: Farming; fishing: Fishing; - slayer: SlayerData; + slayer: SlayerData | null; dungeons: DungeonsStats | null; minions: Minions; bestiary: BestiaryStats;