diff --git a/src/app/(stats)/player/[ign]/_stats/warlords/table.tsx b/src/app/(stats)/player/[ign]/_stats/warlords/table.tsx new file mode 100644 index 0000000..f051cc9 --- /dev/null +++ b/src/app/(stats)/player/[ign]/_stats/warlords/table.tsx @@ -0,0 +1,40 @@ +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" +import { formatNumber } from "@/lib/formatters" +import { getWarlordsModeName, getWarlordsModeStats, getWarlordsMostPlayedMode } from "@/lib/hypixel/warlords/general" +import { NonNullStats } from "@/lib/schema/player" +import { cn } from "@/lib/utils" + +export function WarlordsModeStatsTable({ stats }: { stats: NonNullable }) { + return ( + + + + Mode + Wins + Kills + + + + + + + +
+ ) +} + +function WarlordsModeStatsTableStat( + { modeId, stats }: { modeId: Parameters[0], stats: NonNullable } +) { + const modeStats = getWarlordsModeStats(modeId, stats) + const name = getWarlordsModeName(modeId) + const mostPlayed = getWarlordsMostPlayedMode(stats)?.id === modeId + + return ( + + {name} + {formatNumber(modeStats.wins)} + {formatNumber(modeStats.kills)} + + ) +} diff --git a/src/app/(stats)/player/[ign]/_stats/warlords/warlords.tsx b/src/app/(stats)/player/[ign]/_stats/warlords/warlords.tsx index c943d02..b4a301e 100644 --- a/src/app/(stats)/player/[ign]/_stats/warlords/warlords.tsx +++ b/src/app/(stats)/player/[ign]/_stats/warlords/warlords.tsx @@ -6,6 +6,7 @@ import { NonNullStats } from "@/lib/schema/player" import GeneralStats from "../GeneralStats" import { WarlordsWeaponsBar } from "./client" import WarlordsGeneralStats from "./stats" +import { WarlordsModeStatsTable } from "./table" export default function WarlordsStats({ stats }: { stats: NonNullStats["Warlords"] }) { if (!stats) return null @@ -43,6 +44,8 @@ export default function WarlordsStats({ stats }: { stats: NonNullStats["Warlords + + ) } diff --git a/src/lib/hypixel/warlords/general.ts b/src/lib/hypixel/warlords/general.ts index fc91603..633777f 100644 --- a/src/lib/hypixel/warlords/general.ts +++ b/src/lib/hypixel/warlords/general.ts @@ -1,6 +1,45 @@ -import { CLASSES, RARITIES } from "@/data/hypixel/warlords" +import { CLASSES, MODES, RARITIES } from "@/data/hypixel/warlords" import { NonNullStats } from "@/lib/schema/player" +export function getWarlordsModeName(modeId: Exclude | "all") { + if (modeId === "all") { + return MODES.find(m => m.id === "")!.name + } + return MODES.find(m => m.id === modeId)!.name +} + +export function getWarlordsMostPlayedMode(stats: NonNullable) { + let mostPlayedMode: typeof MODES[number] | null = null + let maxWins = 0 + + for (const mode of MODES) { + if (mode.id === "") continue + + const wins = stats[`wins_${mode.id}`] + + if (wins > maxWins) { + maxWins = wins + mostPlayedMode = mode + } + } + + return mostPlayedMode +} + +export function getWarlordsModeStats(modeId: Exclude | "all", stats: NonNullable) { + if (modeId === "all") { + return { + kills: stats.kills, + wins: stats.wins + } + } + + return { + kills: stats[`kills_${modeId}`], + wins: stats[`wins_${modeId}`] + } +} + export function getWarlordsWeaponsRepaired(stats: NonNullable) { const val: { repaired: typeof RARITIES[number], num: number }[] = [] diff --git a/src/lib/schema/stats/warlords.ts b/src/lib/schema/stats/warlords.ts index b9d1d0a..8c9e270 100644 --- a/src/lib/schema/stats/warlords.ts +++ b/src/lib/schema/stats/warlords.ts @@ -26,5 +26,11 @@ export const warlordsStatsSchema = z.object({ repaired_common: z.number().default(0), repaired_rare: z.number().default(0), repaired_epic: z.number().default(0), - repaired_legendary: z.number().default(0) + repaired_legendary: z.number().default(0), + wins_capturetheflag: z.number().default(0), + wins_domination: z.number().default(0), + wins_teamdeathmatch: z.number().default(0), + kills_capturetheflag: z.number().default(0), + kills_domination: z.number().default(0), + kills_teamdeathmatch: z.number().default(0) })