Added blitz stat card
This commit is contained in:
46
src/app/(stats)/player/[ign]/_stats/blitz/blitz.tsx
Normal file
46
src/app/(stats)/player/[ign]/_stats/blitz/blitz.tsx
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Separator } from "@/components/ui/separator"
|
||||
import { formatNumber } from "@/lib/formatters"
|
||||
import { getBlitzMostPlayedKit } from "@/lib/hypixel/blitz/general"
|
||||
import { devide } from "@/lib/hypixel/general"
|
||||
import { NonNullStats } from "@/lib/schema/player"
|
||||
import { cn } from "@/lib/utils"
|
||||
import GeneralStats from "../GeneralStats"
|
||||
|
||||
export default function BlitzStats({ stats }: { stats: NonNullStats["Blitz"] }) {
|
||||
if (!stats) return null
|
||||
|
||||
const kd = formatNumber(devide(stats.kills, stats.deaths))
|
||||
const wins = stats.wins_solo_normal + stats.wins_team_normal
|
||||
const mostPlayedKit = getBlitzMostPlayedKit(stats)
|
||||
|
||||
return (
|
||||
<GeneralStats
|
||||
id="blitz"
|
||||
title="Blitz SG"
|
||||
collapsedStats={[
|
||||
{
|
||||
title: <p>Main</p>,
|
||||
stat: (
|
||||
<p className={cn(mostPlayedKit === null && "text-muted-foreground")}>
|
||||
{mostPlayedKit !== null ? mostPlayedKit.name : "Unknown"}
|
||||
</p>
|
||||
)
|
||||
},
|
||||
{
|
||||
title: <p>Kills</p>,
|
||||
stat: <p className="text-muted-foreground">{formatNumber(stats.kills)}</p>
|
||||
},
|
||||
{
|
||||
title: <p>KD</p>,
|
||||
stat: <p className="text-muted-foreground">{kd}</p>
|
||||
},
|
||||
{
|
||||
title: <p>Wins</p>,
|
||||
stat: <p className="text-muted-foreground">{wins}</p>
|
||||
}
|
||||
]}
|
||||
>
|
||||
<Separator className="my-4" />
|
||||
</GeneralStats>
|
||||
)
|
||||
}
|
||||
@@ -12,6 +12,7 @@ import { Suspense } from "react"
|
||||
import { PlayerPageLoadText } from "./_client"
|
||||
import Sidebar from "./_components/Sidebar"
|
||||
import BedwarsStats from "./_stats/bedwars/bedwars"
|
||||
import BlitzStats from "./_stats/blitz/blitz"
|
||||
import BuildBattleStats from "./_stats/build-battle/build-battle"
|
||||
import CopsAndCrimsStats from "./_stats/copsandcrims/copsandcrims"
|
||||
import DuelsStats from "./_stats/duels/duels"
|
||||
@@ -127,6 +128,7 @@ async function SuspendedPage({ params }: Pick<PageProps<"/player/[ign]">, "param
|
||||
<MegaWallsStats stats={player.stats.MegaWalls} />
|
||||
<CopsAndCrimsStats stats={player.stats.CopsAndCrims} />
|
||||
<WoolGamesStats stats={player.stats.WoolGames} />
|
||||
<BlitzStats stats={player.stats.Blitz} />
|
||||
</Accordion>
|
||||
</div>
|
||||
) :
|
||||
|
||||
46
src/data/hypixel/blitz.ts
Normal file
46
src/data/hypixel/blitz.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
export const KITS = [
|
||||
{ id: "arachnologist", name: "Arachnologist" },
|
||||
{ id: "archer", name: "Archer" },
|
||||
{ id: "armorer", name: "Armorer" },
|
||||
{ id: "astronaut", name: "Astronaut" },
|
||||
{ id: "baker", name: "Baker" },
|
||||
{ id: "blaze", name: "Blaze" },
|
||||
{ id: "creepertamer", name: "Creepertamer" },
|
||||
{ id: "diver", name: "Diver" },
|
||||
{ id: "donkeytamer", name: "Donkeytamer" },
|
||||
{ id: "farmer", name: "Farmer" },
|
||||
{ id: "florist", name: "Florist" },
|
||||
{ id: "golem", name: "Golem" },
|
||||
{ id: "guardian", name: "Guardian" },
|
||||
{ id: "horsetamer", name: "Horsetamer" },
|
||||
{ id: "hunter", name: "Hunter" },
|
||||
{ id: "hype train", name: "Hype Train" },
|
||||
{ id: "jockey", name: "Jockey" },
|
||||
{ id: "knight", name: "Knight" },
|
||||
{ id: "meatmaster", name: "Meatmaster" },
|
||||
{ id: "necromancer", name: "Necromancer" },
|
||||
{ id: "paladin", name: "Paladin" },
|
||||
{ id: "phoenix", name: "Phoenix" },
|
||||
{ id: "pigman", name: "Pigman" },
|
||||
{ id: "ranger", name: "Ranger" },
|
||||
{ id: "reaper", name: "Reaper" },
|
||||
{ id: "reddragon", name: "Red Dragon" },
|
||||
{ id: "rogue", name: "Rogue" },
|
||||
{ id: "scout", name: "Scout" },
|
||||
{ id: "shadow knight", name: "Shadow Knight" },
|
||||
{ id: "slimeyslime", name: "Slimey Slime" },
|
||||
{ id: "snowman", name: "Snowman" },
|
||||
{ id: "speleologist", name: "Speleologist" },
|
||||
{ id: "tim", name: "Tim" },
|
||||
{ id: "toxicologist", name: "Toxicologist" },
|
||||
{ id: "troll", name: "Troll" },
|
||||
{ id: "viking", name: "Viking" },
|
||||
{ id: "warlock", name: "Warlock" },
|
||||
{ id: "warrior", name: "Warrior" },
|
||||
{ id: "wolftamer", name: "Wolftamer" }
|
||||
] as const
|
||||
export const MODES = [
|
||||
{ id: "solo_normal", name: "Solo Normal" },
|
||||
{ id: "teams_normal", name: "Teams Normal" }
|
||||
] as const
|
||||
export const KITEXP = [0, 100, 250, 500, 1000, 1500, 2000, 2500, 5000, 10000] as const
|
||||
17
src/lib/hypixel/blitz/general.ts
Normal file
17
src/lib/hypixel/blitz/general.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { KITS } from "@/data/hypixel/blitz"
|
||||
import { NonNullStats } from "@/lib/schema/player"
|
||||
|
||||
export function getBlitzMostPlayedKit(stats: NonNullable<NonNullStats["Blitz"]>) {
|
||||
let mostPlayedKit: typeof KITS[number] | null = null
|
||||
let maxTimePlayed = 0
|
||||
|
||||
for (const kit of KITS) {
|
||||
const timePlayed = stats[`time_played_${kit.id}`]
|
||||
if (timePlayed > maxTimePlayed) {
|
||||
maxTimePlayed = timePlayed
|
||||
mostPlayedKit = kit
|
||||
}
|
||||
}
|
||||
|
||||
return mostPlayedKit
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import z from "zod"
|
||||
import {
|
||||
bedwarsStatsSchema,
|
||||
blitzStatsSchema,
|
||||
buildBattleStatsSchema,
|
||||
copsAndCrimsStatsSchema,
|
||||
duelsStatsSchema,
|
||||
@@ -36,11 +37,13 @@ export const playerSchema = z.looseObject({
|
||||
TNTGames: tntGamesStatsSchema.optional(),
|
||||
Walls3: megawallsStats.optional(),
|
||||
MCGO: copsAndCrimsStatsSchema.optional(),
|
||||
WoolGames: woolGamesStatsSchema.optional()
|
||||
}).transform(({ Walls3, MCGO, ...rest }) => {
|
||||
WoolGames: woolGamesStatsSchema.optional(),
|
||||
HungerGames: blitzStatsSchema.optional()
|
||||
}).transform(({ Walls3, MCGO, HungerGames, ...rest }) => {
|
||||
return {
|
||||
MegaWalls: Walls3,
|
||||
CopsAndCrims: MCGO,
|
||||
Blitz: HungerGames,
|
||||
...rest
|
||||
}
|
||||
}).optional(),
|
||||
|
||||
@@ -789,3 +789,69 @@ export const woolGamesStatsSchema = z.object({
|
||||
}).optional()
|
||||
}).optional()
|
||||
})
|
||||
|
||||
function blitzKitPlayedStats() {
|
||||
const ids = [
|
||||
"arachnologist",
|
||||
"archer",
|
||||
"armorer",
|
||||
"astronaut",
|
||||
"baker",
|
||||
"blaze",
|
||||
"creepertamer",
|
||||
"diver",
|
||||
"donkeytamer",
|
||||
"farmer",
|
||||
"florist",
|
||||
"golem",
|
||||
"guardian",
|
||||
"horsetamer",
|
||||
"hunter",
|
||||
"hype train",
|
||||
"jockey",
|
||||
"knight",
|
||||
"meatmaster",
|
||||
"necromancer",
|
||||
"paladin",
|
||||
"phoenix",
|
||||
"pigman",
|
||||
"ranger",
|
||||
"reaper",
|
||||
"reddragon",
|
||||
"rogue",
|
||||
"scout",
|
||||
"shadow knight",
|
||||
"slimeyslime",
|
||||
"snowman",
|
||||
"speleologist",
|
||||
"tim",
|
||||
"toxicologist",
|
||||
"troll",
|
||||
"viking",
|
||||
"warlock",
|
||||
"warrior",
|
||||
"wolftamer"
|
||||
] as const
|
||||
|
||||
const stats = [
|
||||
"time_played"
|
||||
] as const
|
||||
|
||||
const entries = new Map<string, z.ZodDefault<z.ZodNumber>>()
|
||||
|
||||
for (const id of ids) {
|
||||
for (const stat of stats) {
|
||||
entries.set(`${stat}_${id}`, z.number().default(0))
|
||||
}
|
||||
}
|
||||
|
||||
return Object.fromEntries(entries) as Record<`${typeof stats[number]}_${typeof ids[number]}`, z.ZodDefault<z.ZodNumber>>
|
||||
}
|
||||
|
||||
export const blitzStatsSchema = z.object({
|
||||
kills: z.number().default(0),
|
||||
deaths: z.number().default(0),
|
||||
wins_solo_normal: z.number().default(0),
|
||||
wins_team_normal: z.number().default(0),
|
||||
...blitzKitPlayedStats()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user