diff --git a/src/app/(stats)/player/[ign]/_client.tsx b/src/app/(stats)/player/[ign]/_client.tsx index d39133b..3f40826 100644 --- a/src/app/(stats)/player/[ign]/_client.tsx +++ b/src/app/(stats)/player/[ign]/_client.tsx @@ -94,7 +94,7 @@ export function PlayerStats( "woolgames": , "blitz": , "arcade": , - "speeduhc": + "speeduhc": } as const const defaultOrder = Object.keys(statsComponents) diff --git a/src/app/(stats)/player/[ign]/_stats/speeduhc/speeduhc.tsx b/src/app/(stats)/player/[ign]/_stats/speeduhc/speeduhc.tsx index 09352a4..4a28057 100644 --- a/src/app/(stats)/player/[ign]/_stats/speeduhc/speeduhc.tsx +++ b/src/app/(stats)/player/[ign]/_stats/speeduhc/speeduhc.tsx @@ -5,8 +5,10 @@ import { getSpeedUHCStar } from "@/lib/hypixel/speeduhc/general" import { NonNullStats } from "@/lib/schema/player" import GeneralStats from "../GeneralStats" import SpeedUHCProgress from "./progress" +import SpeedUHCGeneralStats from "./stats" +import { SpeedUHCModeStatsTable } from "./table" -export default function SpeedUHCStats({ stats }: { stats: NonNullStats["SpeedUHC"] }) { +export default function SpeedUHCStats({ stats, uhcCoins }: { stats: NonNullStats["SpeedUHC"], uhcCoins: number | undefined }) { if (!stats) return null const kd = formatNumber(devide(stats.kills, stats.deaths)) @@ -38,6 +40,11 @@ export default function SpeedUHCStats({ stats }: { stats: NonNullStats["SpeedUHC > + + + + + ) } diff --git a/src/app/(stats)/player/[ign]/_stats/speeduhc/stats.tsx b/src/app/(stats)/player/[ign]/_stats/speeduhc/stats.tsx new file mode 100644 index 0000000..a3ac845 --- /dev/null +++ b/src/app/(stats)/player/[ign]/_stats/speeduhc/stats.tsx @@ -0,0 +1,32 @@ +import { formatNumber } from "@/lib/formatters" +import { devide } from "@/lib/hypixel/general" +import { getSpeedUHCStar, getSpeedUHCTitle } from "@/lib/hypixel/speeduhc/general" +import { NonNullStats } from "@/lib/schema/player" +import { BasicStat } from "../../_components/Stats" + +export default function SpeedUHCGeneralStats({ stats, uhcCoins }: { stats: NonNullable, uhcCoins: number | undefined }) { + const star = getSpeedUHCStar(stats.score) + const currentTitle = getSpeedUHCTitle(Math.floor(star)) + const kd = formatNumber(devide(stats.kills, stats.deaths)) + const wl = formatNumber(devide(stats.wins, stats.losses)) + + return ( +
+
+ + + +
+
+ + + +
+
+ + + +
+
+ ) +} diff --git a/src/app/(stats)/player/[ign]/_stats/speeduhc/table.tsx b/src/app/(stats)/player/[ign]/_stats/speeduhc/table.tsx new file mode 100644 index 0000000..a81c414 --- /dev/null +++ b/src/app/(stats)/player/[ign]/_stats/speeduhc/table.tsx @@ -0,0 +1,57 @@ +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" +import { formatNumber } from "@/lib/formatters" +import { getSpeedUHCBestMode, getSpeedUHCModeName, getSpeedUHCModeStats } from "@/lib/hypixel/speeduhc/general" +import { NonNullStats } from "@/lib/schema/player" +import { cn } from "@/lib/utils" + +export function SpeedUHCModeStatsTable({ stats }: { stats: NonNullable }) { + return ( + + + + + + + + + +
+ ) +} + +function SpeedUHCStatRow({ modeId, stats }: { modeId: Parameters[0], stats: NonNullable }) { + const modeStats = getSpeedUHCModeStats(modeId, stats) + const modeName = getSpeedUHCModeName(modeId) + const isBest = getSpeedUHCBestMode(stats) === modeId + + return ( + + {modeName} + {modeStats.map((v, i) => { + return {formatNumber(v)} + })} + + ) +} + +function SpeedUHCModeStatsTableHeader() { + const headerElements = [ + "Mode", + "Kills", + "Deaths", + "KD", + "Wins", + "Losses", + "WL" + ] + + return ( + + + {headerElements.map((v, i) => { + return {v} + })} + + + ) +} diff --git a/src/lib/hypixel/speeduhc/general.ts b/src/lib/hypixel/speeduhc/general.ts index 9188122..3fb620c 100644 --- a/src/lib/hypixel/speeduhc/general.ts +++ b/src/lib/hypixel/speeduhc/general.ts @@ -1,4 +1,68 @@ -import { TITLES } from "@/data/hypixel/speeduhc" +import { MODES, TITLES } from "@/data/hypixel/speeduhc" +import { NonNullStats } from "@/lib/schema/player" +import { devide } from "../general" + +export function getSpeedUHCModeName(modeId: Exclude | "all_modes") { + if (modeId === "all_modes") { + return MODES.find(m => m.id === "")!.name + } + + return MODES.find(m => m.id === modeId)!.name +} + +export function getSpeedUHCBestMode(stats: NonNullable) { + let bestMode: typeof MODES[number]["id"] | null = null + let maxGames = 0 + + for (const mode of MODES) { + if (mode.id === "") continue + + const wins = stats[`wins_${mode.id}`] + const losses = stats[`losses_${mode.id}`] + const totalGames = wins + losses + + if (totalGames > maxGames) { + maxGames = totalGames + bestMode = mode.id + } + } + + return bestMode +} + +export function getSpeedUHCModeStats(modeId: Exclude | "all_modes", stats: NonNullable) { + if (modeId === "all_modes") { + const bestMode = getSpeedUHCBestMode(stats) + if (!bestMode) { + return [ + stats.kills, + stats.deaths, + devide(stats.kills, stats.deaths), + stats.wins, + stats.losses, + devide(stats.wins, stats.losses) + ] + } + + return [ + stats[`kills_${bestMode}`], + stats[`deaths_${bestMode}`], + devide(stats[`kills_${bestMode}`], stats[`deaths_${bestMode}`]), + stats[`wins_${bestMode}`], + stats[`losses_${bestMode}`], + devide(stats[`wins_${bestMode}`], stats[`losses_${bestMode}`]) + ] + } + + return [ + stats[`kills_${modeId}`], + stats[`deaths_${modeId}`], + devide(stats[`kills_${modeId}`], stats[`deaths_${modeId}`]), + stats[`wins_${modeId}`], + stats[`losses_${modeId}`], + devide(stats[`wins_${modeId}`], stats[`losses_${modeId}`]) + ] +} export function getSpeedUHCStar(score: number) { for (let i = 0; i < TITLES.length; i++) { diff --git a/src/lib/schema/stats.ts b/src/lib/schema/stats.ts index 3b15df7..34eee1c 100644 --- a/src/lib/schema/stats.ts +++ b/src/lib/schema/stats.ts @@ -1053,5 +1053,22 @@ export const speedUhcStatsSchema = z.object({ deaths: z.number().default(0), wins: z.number().default(0), losses: z.number().default(0), - score: z.number().default(0) + score: z.number().default(0), + coins: z.number().default(0), + kills_solo_normal: z.number().default(0), + deaths_solo_normal: z.number().default(0), + wins_solo_normal: z.number().default(0), + losses_solo_normal: z.number().default(0), + kills_solo_insane: z.number().default(0), + deaths_solo_insane: z.number().default(0), + wins_solo_insane: z.number().default(0), + losses_solo_insane: z.number().default(0), + kills_team_normal: z.number().default(0), + deaths_team_normal: z.number().default(0), + wins_team_normal: z.number().default(0), + losses_team_normal: z.number().default(0), + kills_team_insane: z.number().default(0), + deaths_team_insane: z.number().default(0), + wins_team_insane: z.number().default(0), + losses_team_insane: z.number().default(0) })