Finished uhc progress
This commit is contained in:
22
src/app/(stats)/player/[ign]/_stats/uhc/progress.tsx
Normal file
22
src/app/(stats)/player/[ign]/_stats/uhc/progress.tsx
Normal 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>
|
||||
)
|
||||
}
|
||||
@@ -3,15 +3,16 @@ import { Card, CardContent } from "@/components/ui/card"
|
||||
import { Separator } from "@/components/ui/separator"
|
||||
import { formatNumber } from "@/lib/formatters"
|
||||
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 CollapsedStats from "../../_components/CollapsedStats"
|
||||
import UHCProgress from "./progress"
|
||||
|
||||
export default function UHCStats({ stats }: { stats: NonNullStats["UHC"] }) {
|
||||
if (!stats) return null
|
||||
|
||||
const kd = formatNumber(devide(stats.kills, stats.deaths))
|
||||
const star = getUhcStar(stats.score)
|
||||
const star = getUhcStarValue(stats.score)
|
||||
|
||||
return (
|
||||
<AccordionItem value="uhc">
|
||||
@@ -40,6 +41,7 @@ export default function UHCStats({ stats }: { stats: NonNullStats["UHC"] }) {
|
||||
</AccordionTrigger>
|
||||
<AccordionContent>
|
||||
<Separator className="my-4" />
|
||||
<UHCProgress score={stats.score} />
|
||||
</AccordionContent>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
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--) {
|
||||
if (score >= STARS[i].value) {
|
||||
return i + 1
|
||||
@@ -8,3 +8,16 @@ export function getUhcStar(score: number): number {
|
||||
}
|
||||
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)!
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user