Finished uhc progress

This commit is contained in:
2025-09-04 20:17:15 +02:00
parent 6f90d0caa5
commit 1646cb7492
3 changed files with 40 additions and 3 deletions

View File

@@ -0,0 +1,22 @@
import { formatNumber } from "@/lib/formatters"
import { getProgress } from "@/lib/hypixel/general"
import { getNextUhcStar, getUhcStar } from "@/lib/hypixel/uhc/level"
import GenericProgress from "../../_components/GenericProgress"
export default function UHCProgress({ score }: { score: number }) {
const current = getUhcStar(score)
const next = getNextUhcStar(score)
const percent = getProgress(0, score, next.value)
return (
<div className="flex gap-2 items-center">
<GenericProgress
percent={percent}
tooltipId="uhc-progress"
tooltipContent={`${formatNumber(score)}/${formatNumber(next.value)} Score`}
className={`bg-mc-${current.color}`}
/>
<p className={`text-mc-${next.color}`}>{next.name}</p>
</div>
)
}

View File

@@ -3,15 +3,16 @@ import { Card, CardContent } from "@/components/ui/card"
import { Separator } from "@/components/ui/separator" import { Separator } from "@/components/ui/separator"
import { formatNumber } from "@/lib/formatters" import { formatNumber } from "@/lib/formatters"
import { devide } from "@/lib/hypixel/general" import { devide } from "@/lib/hypixel/general"
import { getUhcStar } from "@/lib/hypixel/uhc/level" import { getUhcStarValue } from "@/lib/hypixel/uhc/level"
import { NonNullStats } from "@/lib/schema/player" import { NonNullStats } from "@/lib/schema/player"
import CollapsedStats from "../../_components/CollapsedStats" import CollapsedStats from "../../_components/CollapsedStats"
import UHCProgress from "./progress"
export default function UHCStats({ stats }: { stats: NonNullStats["UHC"] }) { export default function UHCStats({ stats }: { stats: NonNullStats["UHC"] }) {
if (!stats) return null if (!stats) return null
const kd = formatNumber(devide(stats.kills, stats.deaths)) const kd = formatNumber(devide(stats.kills, stats.deaths))
const star = getUhcStar(stats.score) const star = getUhcStarValue(stats.score)
return ( return (
<AccordionItem value="uhc"> <AccordionItem value="uhc">
@@ -40,6 +41,7 @@ export default function UHCStats({ stats }: { stats: NonNullStats["UHC"] }) {
</AccordionTrigger> </AccordionTrigger>
<AccordionContent> <AccordionContent>
<Separator className="my-4" /> <Separator className="my-4" />
<UHCProgress score={stats.score} />
</AccordionContent> </AccordionContent>
</CardContent> </CardContent>
</Card> </Card>

View File

@@ -1,6 +1,6 @@
import { STARS } from "@/data/hypixel/uhc" import { STARS } from "@/data/hypixel/uhc"
export function getUhcStar(score: number): number { export function getUhcStarValue(score: number): number {
for (let i = STARS.length - 1; i >= 0; i--) { for (let i = STARS.length - 1; i >= 0; i--) {
if (score >= STARS[i].value) { if (score >= STARS[i].value) {
return i + 1 return i + 1
@@ -8,3 +8,16 @@ export function getUhcStar(score: number): number {
} }
return 1 return 1
} }
export function getUhcStar(score: number) {
const current = getUhcStarValue(score)
return STARS.at(current - 1)!
}
export function getNextUhcStar(score: number) {
const current = getUhcStarValue(score)
if (current === 15) return STARS.at(-1)!
return STARS.at(current)!
}