From f5a5a989d3626a1d80ae5931104cf24b09177a9a Mon Sep 17 00:00:00 2001 From: Taken Date: Mon, 8 Sep 2025 20:51:17 +0200 Subject: [PATCH] Added cc table --- .../_stats/copsandcrims/copsandcrims.tsx | 3 + .../[ign]/_stats/copsandcrims/table.tsx | 57 +++++++++++++++++++ src/lib/hypixel/copsandcrims/general.ts | 30 +++++++++- src/lib/schema/stats.ts | 6 ++ 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 src/app/(stats)/player/[ign]/_stats/copsandcrims/table.tsx diff --git a/src/app/(stats)/player/[ign]/_stats/copsandcrims/copsandcrims.tsx b/src/app/(stats)/player/[ign]/_stats/copsandcrims/copsandcrims.tsx index d35d7a9..3125208 100644 --- a/src/app/(stats)/player/[ign]/_stats/copsandcrims/copsandcrims.tsx +++ b/src/app/(stats)/player/[ign]/_stats/copsandcrims/copsandcrims.tsx @@ -7,6 +7,7 @@ import { devide } from "@/lib/hypixel/general" import { NonNullStats } from "@/lib/schema/player" import CollapsedStats from "../../_components/CollapsedStats" import CopsAndCrimsGeneralStats from "./stats" +import CopsAndCrimsStatTable from "./table" export default function CopsAndCrimsStats({ stats }: { stats: NonNullStats["CopsAndCrims"] }) { if (!stats) return null @@ -52,6 +53,8 @@ export default function CopsAndCrimsStats({ stats }: { stats: NonNullStats["Cops + + diff --git a/src/app/(stats)/player/[ign]/_stats/copsandcrims/table.tsx b/src/app/(stats)/player/[ign]/_stats/copsandcrims/table.tsx new file mode 100644 index 0000000..a91a71a --- /dev/null +++ b/src/app/(stats)/player/[ign]/_stats/copsandcrims/table.tsx @@ -0,0 +1,57 @@ +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" +import { formatNumber } from "@/lib/formatters" +import { getCopsAndCrimsModeName, getCopsAndCrimsModeStats } from "@/lib/hypixel/copsandcrims/general" +import { NonNullStats } from "@/lib/schema/player" + +export default function CopsAndCrimsStatTable({ stats }: { stats: NonNullable }) { + return ( + + + + + + + +
+ ) +} + +function CopsAndCrimsTableHeader() { + const headerElements = [ + "Mode", + "Kills", + "Deaths", + "KD", + "Cop Kills", + "Criminal Kills", + "Wins" + ] + + return ( + + + {headerElements.map((v, i) => { + return {v} + })} + + + ) +} + +function CopsAndCrimsTableStat( + { modeId, stats }: { + modeId: Exclude[0], ""> | "regular" + stats: NonNullable + } +) { + const modeStats = getCopsAndCrimsModeStats(modeId === "regular" ? "" : modeId, stats) + const name = getCopsAndCrimsModeName(modeId === "regular" ? "" : modeId) + return ( + + {name} + {modeStats.map((v, i) => { + return {formatNumber(v)} + })} + + ) +} diff --git a/src/lib/hypixel/copsandcrims/general.ts b/src/lib/hypixel/copsandcrims/general.ts index dbac303..4d1cd1c 100644 --- a/src/lib/hypixel/copsandcrims/general.ts +++ b/src/lib/hypixel/copsandcrims/general.ts @@ -1,4 +1,10 @@ -import { SCORE } from "@/data/hypixel/copsandcrims" +import { MODES, SCORE } from "@/data/hypixel/copsandcrims" +import { NonNullStats } from "@/lib/schema/player" +import { devide } from "../general" + +export function getCopsAndCrimsModeName(modeId: typeof MODES[number]["id"]) { + return MODES.find(m => m.id === modeId)!.name +} export function getScoreColor(score: number) { for (const scoreThreshold of SCORE.slice().reverse()) { @@ -7,3 +13,25 @@ export function getScoreColor(score: number) { return SCORE.at(0)!.color } + +export function getCopsAndCrimsModeStats(modeId: typeof MODES[number]["id"], stats: NonNullable) { + if (modeId === "") { + return [ + stats["kills"], + stats["deaths"], + devide(stats["kills"], stats["deaths"]), + stats["cop_kills"], + stats["criminal_kills"], + stats["game_wins"] + ] + } + + return [ + stats[`kills_${modeId}`], + stats[`deaths_${modeId}`], + devide(stats[`kills_${modeId}`], stats[`deaths_${modeId}`]), + stats[`cop_kills_${modeId}`], + stats[`criminal_kills_${modeId}`], + stats[`game_wins_${modeId}`] + ] +} diff --git a/src/lib/schema/stats.ts b/src/lib/schema/stats.ts index b67c117..cafe92c 100644 --- a/src/lib/schema/stats.ts +++ b/src/lib/schema/stats.ts @@ -665,14 +665,20 @@ export const copsAndCrimsStatsSchema = z.looseObject({ assists: z.number().default(0), deaths: z.number().default(0), game_wins: z.number().default(0), + cop_kills: z.number().default(0), + criminal_kills: z.number().default(0), kills_deathmatch: z.number().default(0), assists_deathmatch: z.number().default(0), deaths_deathmatch: z.number().default(0), game_wins_deathmatch: z.number().default(0), + cop_kills_deathmatch: z.number().default(0), + criminal_kills_deathmatch: z.number().default(0), kills_gungame: z.number().default(0), assists_gungame: z.number().default(0), deaths_gungame: z.number().default(0), game_wins_gungame: z.number().default(0), + cop_kills_gungame: z.number().default(0), + criminal_kills_gungame: z.number().default(0), bombs_planted: z.number().default(0), bombs_defused: z.number().default(0), shots_fired: z.number().default(0),