From 1ac24b8a3027f99eecdb03222a20025febfa9396 Mon Sep 17 00:00:00 2001 From: Taken Date: Thu, 4 Sep 2025 23:00:24 +0200 Subject: [PATCH] Finished UHC stats --- .../(stats)/player/[ign]/_stats/uhc/table.tsx | 64 +++++++++++++++++++ .../(stats)/player/[ign]/_stats/uhc/uhc.tsx | 3 + src/lib/hypixel/uhc/general.ts | 39 +++++++++++ 3 files changed, 106 insertions(+) create mode 100644 src/app/(stats)/player/[ign]/_stats/uhc/table.tsx diff --git a/src/app/(stats)/player/[ign]/_stats/uhc/table.tsx b/src/app/(stats)/player/[ign]/_stats/uhc/table.tsx new file mode 100644 index 0000000..a88ce38 --- /dev/null +++ b/src/app/(stats)/player/[ign]/_stats/uhc/table.tsx @@ -0,0 +1,64 @@ +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" +import { formatNumber } from "@/lib/formatters" +import { getUHCModeName, getUHCModeStats } from "@/lib/hypixel/uhc/general" +import { NonNullStats } from "@/lib/schema/player" + +export default function UHCStatTable({ stats }: { stats: NonNullable }) { + return ( + + + + + + + + + + + + +
+ ) +} + +function UHCTableHeader() { + const headerElements = [ + "Mode", + "Kills", + "Deaths", + "KD", + "Wins", + "KW", + "Heads Eaten" + ] + + return ( + + + {headerElements.map((v, i) => { + return {v} + })} + + + ) +} + +function TableStat( + { modeId, stats }: { modeId: Exclude[0], ""> | "teams" | "all_modes", stats: NonNullable } +) { + const modeStats = getUHCModeStats(modeId === "teams" ? "" : modeId, stats) + const modeName = getUHCModeName(modeId === "teams" || modeId === "all_modes" ? "" : modeId) + + return ( + + {modeId === "all_modes" ? "Overall" : modeName} + {modeStats.map((v, i) => { + return ( + + {formatNumber(v)} + + ) + })} + + ) +} diff --git a/src/app/(stats)/player/[ign]/_stats/uhc/uhc.tsx b/src/app/(stats)/player/[ign]/_stats/uhc/uhc.tsx index 7083d98..e15751d 100644 --- a/src/app/(stats)/player/[ign]/_stats/uhc/uhc.tsx +++ b/src/app/(stats)/player/[ign]/_stats/uhc/uhc.tsx @@ -9,6 +9,7 @@ import { NonNullStats } from "@/lib/schema/player" import CollapsedStats from "../../_components/CollapsedStats" import UHCProgress from "./progress" import UHCGeneralStats from "./stats" +import UHCStatTable from "./table" export default function UHCStats({ stats }: { stats: NonNullStats["UHC"] }) { if (!stats) return null @@ -47,6 +48,8 @@ export default function UHCStats({ stats }: { stats: NonNullStats["UHC"] }) { + + diff --git a/src/lib/hypixel/uhc/general.ts b/src/lib/hypixel/uhc/general.ts index 39e676a..d145096 100644 --- a/src/lib/hypixel/uhc/general.ts +++ b/src/lib/hypixel/uhc/general.ts @@ -1,5 +1,6 @@ import { MODES } from "@/data/hypixel/uhc" import { NonNullStats } from "@/lib/schema/player" +import { devide } from "../general" export function getStatsCombined(stats: NonNullable) { return { @@ -10,6 +11,44 @@ export function getStatsCombined(stats: NonNullable) { } } +export function getUHCModeName(modeId: typeof MODES[number]["id"]) { + return MODES.find(m => m.id === modeId)!.name +} + +export function getUHCModeStats(modeId: typeof MODES[number]["id"] | "all_modes", stats: NonNullable) { + if (modeId === "all_modes") { + const statsCombined = getStatsCombined(stats) + return [ + statsCombined.kills, + statsCombined.deaths, + devide(statsCombined.kills, statsCombined.deaths), + statsCombined.wins, + devide(statsCombined.kills, statsCombined.kills), + statsCombined.heads + ] + } + + if (modeId === "") { + return [ + stats[`kills`], + stats[`deaths`], + devide(stats[`kills`], stats[`deaths`]), + stats[`wins`], + devide(stats[`kills`], stats[`wins`]), + stats[`heads_eaten`] + ] + } + + return [ + stats[`kills_${modeId}`], + stats[`deaths_${modeId}`], + devide(stats[`kills_${modeId}`], stats[`deaths_${modeId}`]), + stats[`wins_${modeId}`], + devide(stats[`kills_${modeId}`], stats[`wins_${modeId}`]), + stats[`heads_eaten_${modeId}`] + ] +} + function getUHCWins(stats: NonNullable) { let wins = 0 const ids = MODES.filter(m => m.id !== "").map(m => m.id)