Skip to content

Commit

Permalink
update(misc): add null checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Zickles committed Dec 23, 2024
1 parent 1744784 commit c8acb8b
Show file tree
Hide file tree
Showing 16 changed files with 295 additions and 264 deletions.
1 change: 1 addition & 0 deletions src/lib/sections/stats/MiscSection.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
</script>

<h3 class="text-2xl capitalize">Miscellaneous</h3>
{console.log(profile.misc)}

<Essence />
<!-- TODO: Essence Shop -->
Expand Down
58 changes: 30 additions & 28 deletions src/lib/sections/stats/misc/auctions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,34 @@
const misc = getContext<StatsType["misc"]>("misc");
</script>

<Items title="Auctions Sold">
<div slot="text">
<AdditionStat text="Fees" data={format(misc.auctions.fees)} />
<AdditionStat text="Coins Earned" data={format(misc.auctions.gold_earned)} />
<AdditionStat text="Items Sold" data={format(misc.auctions.total_sold.total)} asterisk={true}>
{#each Object.entries(misc.auctions.total_sold) as [rarity, amount]}
{#if rarity !== "total"}
<AdditionStat text={rarity} data={amount} textRarityColor={rarity.toLowerCase()} />
{/if}
{/each}
</AdditionStat>
</div>
</Items>
{#if misc.auctions != null}
<Items title="Auctions Sold">
<div slot="text">
<AdditionStat text="Fees" data={format(misc.auctions.fees)} />
<AdditionStat text="Coins Earned" data={format(misc.auctions.gold_earned)} />
<AdditionStat text="Items Sold" data={format(misc.auctions.total_sold.total)} asterisk={true}>
{#each Object.entries(misc.auctions.total_sold) as [rarity, amount]}
{#if rarity !== "total"}
<AdditionStat text={rarity} data={amount} textRarityColor={rarity.toLowerCase()} />
{/if}
{/each}
</AdditionStat>
</div>
</Items>

<Items title="Auctions Bought">
<div slot="text">
<AdditionStat text="Bids" data={format(misc.auctions.bids)} />
<AdditionStat text="Highest Bid" data={format(misc.auctions.highest_bid)} />
<AdditionStat text="Won" data={format(misc.auctions.won)} />
<AdditionStat text="Coins Spent" data={format(misc.auctions.gold_spent)} />
<AdditionStat text="Items Bought" data={format(misc.auctions.total_bought.total)} asterisk={true}>
{#each Object.entries(misc.auctions.total_bought) as [rarity, amount]}
{#if rarity !== "total"}
<AdditionStat text={rarity} data={amount} textRarityColor={rarity.toLowerCase()} />
{/if}
{/each}
</AdditionStat>
</div>
</Items>
<Items title="Auctions Bought">
<div slot="text">
<AdditionStat text="Bids" data={format(misc.auctions.bids)} />
<AdditionStat text="Highest Bid" data={format(misc.auctions.highest_bid)} />
<AdditionStat text="Won" data={format(misc.auctions.won)} />
<AdditionStat text="Coins Spent" data={format(misc.auctions.gold_spent)} />
<AdditionStat text="Items Bought" data={format(misc.auctions.total_bought.total)} asterisk={true}>
{#each Object.entries(misc.auctions.total_bought) as [rarity, amount]}
{#if rarity !== "total"}
<AdditionStat text={rarity} data={amount} textRarityColor={rarity.toLowerCase()} />
{/if}
{/each}
</AdditionStat>
</div>
</Items>
{/if}
30 changes: 16 additions & 14 deletions src/lib/sections/stats/misc/claimed.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@
const misc = getContext<StatsType["misc"]>("misc");
</script>

<Items title="Claimed Items">
<div slot="text">
{#each Object.entries(misc.claimed_items) as [item, time]}
<AdditionStat
text={item.replaceAll("_", " ")}
data={formatDistanceToNowStrict(time, {
addSuffix: true
})}
asterisk={true}>
{formatDate(time, "'Claimed on' dd MMMM yyyy 'at' HH:mm")}
</AdditionStat>
{/each}
</div>
</Items>
{#if misc.claimed_items != null}
<Items title="Claimed Items">
<div slot="text">
{#each Object.entries(misc.claimed_items) as [item, time]}
<AdditionStat
text={item.replaceAll("_", " ")}
data={formatDistanceToNowStrict(time, {
addSuffix: true
})}
asterisk={true}>
{formatDate(time, "'Claimed on' dd MMMM yyyy 'at' HH:mm")}
</AdditionStat>
{/each}
</div>
</Items>
{/if}
16 changes: 9 additions & 7 deletions src/lib/sections/stats/misc/damage.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
const misc = getContext<StatsType["misc"]>("misc");
</script>

<Items title="Damage">
<div slot="text">
{#each Object.entries(misc.damage) as [text, data]}
<AdditionStat text={text.replaceAll("_", " ")} data={format(data.toFixed(3))} />
{/each}
</div>
</Items>
{#if misc.damage != null}
<Items title="Damage">
<div slot="text">
{#each Object.entries(misc.damage) as [text, data]}
<AdditionStat text={text.replaceAll("_", " ")} data={format(data.toFixed(3))} />
{/each}
</div>
</Items>
{/if}
66 changes: 34 additions & 32 deletions src/lib/sections/stats/misc/dragons.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,37 @@
const misc = getContext<StatsType["misc"]>("misc");
</script>

<Items title="Dragons">
<div slot="text">
<AdditionStat text="Most Damage" data={format(misc.dragons.most_damage.best.toFixed(0))} asterisk={true}>
{#each Object.entries(misc.dragons.most_damage) as [text, data]}
{#if text !== "best"}
<AdditionStat {text} data={format(data.toFixed(0))} />
{/if}
{/each}
</AdditionStat>
<AdditionStat text="Fastest Kill" data={misc.dragons.fastest_kill.best} asterisk={true}>
{#each Object.entries(misc.dragons.fastest_kill) as [text, data]}
{#if text !== "best"}
<AdditionStat {text} {data} />
{/if}
{/each}
</AdditionStat>
<AdditionStat text="Last Hits" data={format(misc.dragons.last_hits.total)} asterisk={true}>
{#each Object.entries(misc.dragons.last_hits) as [text, data]}
{#if text !== "total"}
<AdditionStat {text} data={format(data)} />
{/if}
{/each}
</AdditionStat>
<AdditionStat text="Deats" data={format(misc.dragons.deaths.total)} asterisk={true}>
{#each Object.entries(misc.dragons.deaths) as [text, data]}
{#if text !== "total"}
<AdditionStat {text} data={format(data)} />
{/if}
{/each}
</AdditionStat>
</div>
</Items>
{#if misc.dragons != null}
<Items title="Dragons">
<div slot="text">
<AdditionStat text="Most Damage" data={format(misc.dragons.most_damage.best.toFixed(0))} asterisk={true}>
{#each Object.entries(misc.dragons.most_damage) as [text, data]}
{#if text !== "best"}
<AdditionStat {text} data={format(data.toFixed(0))} />
{/if}
{/each}
</AdditionStat>
<AdditionStat text="Fastest Kill" data={misc.dragons.fastest_kill.best} asterisk={true}>
{#each Object.entries(misc.dragons.fastest_kill) as [text, data]}
{#if text !== "best"}
<AdditionStat {text} {data} />
{/if}
{/each}
</AdditionStat>
<AdditionStat text="Last Hits" data={format(misc.dragons.last_hits.total)} asterisk={true}>
{#each Object.entries(misc.dragons.last_hits) as [text, data]}
{#if text !== "total"}
<AdditionStat {text} data={format(data)} />
{/if}
{/each}
</AdditionStat>
<AdditionStat text="Deats" data={format(misc.dragons.deaths.total)} asterisk={true}>
{#each Object.entries(misc.dragons.deaths) as [text, data]}
{#if text !== "total"}
<AdditionStat {text} data={format(data)} />
{/if}
{/each}
</AdditionStat>
</div>
</Items>
{/if}
16 changes: 9 additions & 7 deletions src/lib/sections/stats/misc/endstone.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
const misc = getContext<StatsType["misc"]>("misc");
</script>

<Items title="Endstone Protector">
<div slot="text">
{#each Object.entries(misc.endstone_protector) as [text, data]}
<AdditionStat text={text.replaceAll("_", " ")} data={format(data)} />
{/each}
</div>
</Items>
{#if misc.endstone_protector != null}
<Items title="Endstone Protector">
<div slot="text">
{#each Object.entries(misc.endstone_protector) as [text, data]}
<AdditionStat text={text.replaceAll("_", " ")} data={format(data)} />
{/each}
</div>
</Items>
{/if}
34 changes: 18 additions & 16 deletions src/lib/sections/stats/misc/essence.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@
const misc = getContext<StatsType["misc"]>("misc");
</script>

<div class="space-y-4">
<h3 class="text-xl font-semibold">Essence</h3>
<div class="flex flex-wrap gap-4">
{#each misc.essence as essence}
{@const hasUnlocked = essence.amount}
<Chip image={{ src: essence.texture }} class={cn("h-fit w-fit", { "opacity-50": !hasUnlocked })}>
<div class={cn("flex flex-col")}>
<div class="font-bold">
<span class="opacity-60">{essence.name}</span>
<div class="text-sm">
<span class="opacity-60">Amount:</span>
<span class="text-text">{format(essence.amount)}</span>
{#if misc.essence != null}
<div class="space-y-4">
<h3 class="text-xl font-semibold">Essence</h3>
<div class="flex flex-wrap gap-4">
{#each misc.essence as essence}
{@const hasUnlocked = essence.amount}
<Chip image={{ src: essence.texture }} class={cn("h-fit w-fit", { "opacity-50": !hasUnlocked })}>
<div class={cn("flex flex-col")}>
<div class="font-bold">
<span class="opacity-60">{essence.name}</span>
<div class="text-sm">
<span class="opacity-60">Amount:</span>
<span class="text-text">{format(essence.amount)}</span>
</div>
</div>
</div>
</div>
</Chip>
{/each}
</Chip>
{/each}
</div>
</div>
</div>
{/if}
16 changes: 9 additions & 7 deletions src/lib/sections/stats/misc/gifts.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
const misc = getContext<StatsType["misc"]>("misc");
</script>

<Items title="Gifts">
<div slot="text">
{#each Object.entries(misc.gifts) as [text, data]}
<AdditionStat text={text.replaceAll("_", " ")} data={format(data)} />
{/each}
</div>
</Items>
{#if misc.gifts != null}
<Items title="Gifts">
<div slot="text">
{#each Object.entries(misc.gifts) as [text, data]}
<AdditionStat text={text.replaceAll("_", " ")} data={format(data)} />
{/each}
</div>
</Items>
{/if}
16 changes: 9 additions & 7 deletions src/lib/sections/stats/misc/jerry.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
const misc = getContext<StatsType["misc"]>("misc");
</script>

<Items title="Season of Jerry">
<div slot="text">
{#each Object.entries(misc.season_of_jerry) as [text, data]}
<AdditionStat text={text.replaceAll("_", " ")} data={format(data)} />
{/each}
</div>
</Items>
{#if misc.season_of_jerry != null}
<Items title="Season of Jerry">
<div slot="text">
{#each Object.entries(misc.season_of_jerry) as [text, data]}
<AdditionStat text={text.replaceAll("_", " ")} data={format(data)} />
{/each}
</div>
</Items>
{/if}
54 changes: 28 additions & 26 deletions src/lib/sections/stats/misc/kills.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,34 @@
const misc = getContext<StatsType["misc"]>("misc");
</script>

<div class="space-y-4">
<h3 class="text-xl font-semibold">Kills</h3>
<div>
<AdditionStat text="Total Kills" data={format(misc.kills.total_kills)} />
<AdditionStat text="Total Deaths" data={format(misc.kills.total_deaths)} />
</div>
<div class="flex flex-wrap gap-4">
<div class="flex min-w-96 flex-col gap-1 rounded-lg bg-background/30">
<div class="flex w-full items-center justify-center gap-1.5 border-b-2 border-icon py-2 text-center font-semibold uppercase">Kills</div>
<VirtualList height={320} width="100%" itemCount={misc.kills.kills.length} itemSize={misc.kills.kills.length > 0 ? 20 : 0} scrollDirection="vertical">
<div slot="item" let:index let:style {style} class="px-4 font-semibold">
<div class="inline-block capitalize text-text/60">#{index + 1}</div>
<div class="inline-block text-text">{misc.kills.kills[index].name}</div>
<div class="inline-block text-text/60">: {format(misc.kills.kills[index].amount)}</div>
</div>
</VirtualList>
{#if misc.kills != null}
<div class="space-y-4">
<h3 class="text-xl font-semibold">Kills</h3>
<div>
<AdditionStat text="Total Kills" data={format(misc.kills.total_kills)} />
<AdditionStat text="Total Deaths" data={format(misc.kills.total_deaths)} />
</div>
<div class="flex min-w-96 flex-col gap-1 rounded-lg bg-background/30">
<div class="flex w-full items-center justify-center gap-1.5 border-b-2 border-icon py-2 text-center font-semibold uppercase">Deaths</div>
<VirtualList height={320} width="100%" itemCount={misc.kills.deaths.length} itemSize={misc.kills.deaths.length > 0 ? 20 : 0} scrollDirection="vertical">
<div slot="item" let:index let:style {style} class="px-4 font-semibold">
<div class="inline-block capitalize text-text/60">#{index + 1}</div>
<div class="inline-block text-text">{misc.kills.deaths[index].name}</div>
<div class="inline-block text-text/60">: {format(misc.kills.deaths[index].amount)}</div>
</div>
</VirtualList>
<div class="flex flex-wrap gap-4">
<div class="flex min-w-96 flex-col gap-1 rounded-lg bg-background/30">
<div class="flex w-full items-center justify-center gap-1.5 border-b-2 border-icon py-2 text-center font-semibold uppercase">Kills</div>
<VirtualList height={320} width="100%" itemCount={misc.kills.kills.length} itemSize={misc.kills.kills.length > 0 ? 20 : 0} scrollDirection="vertical">
<div slot="item" let:index let:style {style} class="px-4 font-semibold">
<div class="inline-block capitalize text-text/60">#{index + 1}</div>
<div class="inline-block text-text">{misc.kills.kills[index].name}</div>
<div class="inline-block text-text/60">: {format(misc.kills.kills[index].amount)}</div>
</div>
</VirtualList>
</div>
<div class="flex min-w-96 flex-col gap-1 rounded-lg bg-background/30">
<div class="flex w-full items-center justify-center gap-1.5 border-b-2 border-icon py-2 text-center font-semibold uppercase">Deaths</div>
<VirtualList height={320} width="100%" itemCount={misc.kills.deaths.length} itemSize={misc.kills.deaths.length > 0 ? 20 : 0} scrollDirection="vertical">
<div slot="item" let:index let:style {style} class="px-4 font-semibold">
<div class="inline-block capitalize text-text/60">#{index + 1}</div>
<div class="inline-block text-text">{misc.kills.deaths[index].name}</div>
<div class="inline-block text-text/60">: {format(misc.kills.deaths[index].amount)}</div>
</div>
</VirtualList>
</div>
</div>
</div>
</div>
{/if}
Loading

0 comments on commit c8acb8b

Please sign in to comment.