diff --git a/src/app/(stats)/player/[ign]/_stats/smashheros/smashheros.tsx b/src/app/(stats)/player/[ign]/_stats/smashheros/smashheros.tsx index dd50eb1..a4f929a 100644 --- a/src/app/(stats)/player/[ign]/_stats/smashheros/smashheros.tsx +++ b/src/app/(stats)/player/[ign]/_stats/smashheros/smashheros.tsx @@ -5,6 +5,7 @@ import { getSmashHerosDifficultyColor, getSmashHerosMostPlayedHero } from "@/lib import { NonNullStats } from "@/lib/schema/player" import GeneralStats from "../GeneralStats" import SmashHerosGeneralStats from "./stats" +import { SmashHerosModeTable } from "./table" export default function SmashHerosStats({ stats }: { stats: NonNullStats["SmashHeros"] }) { if (!stats) return null @@ -49,6 +50,8 @@ export default function SmashHerosStats({ stats }: { stats: NonNullStats["SmashH + + ) } diff --git a/src/app/(stats)/player/[ign]/_stats/smashheros/table.tsx b/src/app/(stats)/player/[ign]/_stats/smashheros/table.tsx new file mode 100644 index 0000000..d608adc --- /dev/null +++ b/src/app/(stats)/player/[ign]/_stats/smashheros/table.tsx @@ -0,0 +1,58 @@ +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" +import { formatNumber } from "@/lib/formatters" +import { getSmashHerosModeName, getSmashHerosModeStats, getSmashHerosMostPlayedMode } from "@/lib/hypixel/smashhero/general" +import { NonNullStats } from "@/lib/schema/player" +import { cn } from "@/lib/utils" + +export function SmashHerosModeTable({ stats }: { stats: NonNullable }) { + return ( + + + + + + + + +
+ ) +} + +function SmashHerosModeTableStat( + { modeId, stats }: { modeId: Parameters[0], stats: NonNullable } +) { + const modeStats = getSmashHerosModeStats(modeId, stats) + const modeName = getSmashHerosModeName(modeId) + const mostPlayed = getSmashHerosMostPlayedMode(stats) === modeId + + return ( + + {modeName} + {modeStats.map((v, i) => { + return {formatNumber(v)} + })} + + ) +} + +function SmashHerosModeTableHeader() { + const headerElements = [ + "Mode", + "Kills", + "Deaths", + "KD", + "Wins", + "Losses", + "WL" + ] + + return ( + + + {headerElements.map((v, i) => { + return {v} + })} + + + ) +} diff --git a/src/lib/hypixel/smashhero/general.ts b/src/lib/hypixel/smashhero/general.ts index 0a3c7ce..92ae11c 100644 --- a/src/lib/hypixel/smashhero/general.ts +++ b/src/lib/hypixel/smashhero/general.ts @@ -1,5 +1,53 @@ -import { DIFFICULTY, HEROES } from "@/data/hypixel/smashheros" +import { DIFFICULTY, HEROES, MODES } from "@/data/hypixel/smashheros" import { NonNullStats } from "@/lib/schema/player" +import { devide } from "../general" + +export function getSmashHerosModeName(modeId: Exclude | "all") { + if (modeId === "all") return MODES.find(m => m.id === "")!.name + return MODES.find(m => m.id === modeId)!.name +} + +export function getSmashHerosMostPlayedMode(stats: NonNullable) { + const modes: { mode: Exclude, games: number }[] = [ + { mode: "normal", games: stats.wins_normal + stats.losses_normal }, + { mode: "2v2", games: stats.wins_2v2 + stats.losses_2v2 }, + { mode: "teams", games: stats.wins_teams + stats.losses_teams } + ] + + let maxGames = 0 + let mostPlayedMode: Exclude | null = null + + for (const { mode, games } of modes) { + if (games > maxGames) { + maxGames = games + mostPlayedMode = mode + } + } + + return mostPlayedMode +} + +export function getSmashHerosModeStats(modeId: Exclude | "all", stats: NonNullable) { + if (modeId === "all") { + return [ + stats.kills, + stats.deaths, + devide(stats.kills, stats.deaths), + stats.wins, + stats.losses, + devide(stats.wins, stats.losses) + ] + } + + 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 getSmashHerosDifficultyColor(difficulty: number) { if (difficulty < 1) return DIFFICULTY.at(0)! diff --git a/src/lib/schema/stats/smashheros.ts b/src/lib/schema/stats/smashheros.ts index 1437438..0c1332d 100644 --- a/src/lib/schema/stats/smashheros.ts +++ b/src/lib/schema/stats/smashheros.ts @@ -29,5 +29,17 @@ export const smashHerosStats = z.object({ SPODERMAN: classStats, TINMAN: classStats, DUSK_CRAWLER: classStats - }).optional() + }).optional(), + kills_normal: z.number().default(0), + deaths_normal: z.number().default(0), + wins_normal: z.number().default(0), + losses_normal: z.number().default(0), + kills_2v2: z.number().default(0), + deaths_2v2: z.number().default(0), + wins_2v2: z.number().default(0), + losses_2v2: z.number().default(0), + kills_teams: z.number().default(0), + deaths_teams: z.number().default(0), + wins_teams: z.number().default(0), + losses_teams: z.number().default(0) })