Added warlords mode stats
This commit is contained in:
40
src/app/(stats)/player/[ign]/_stats/warlords/table.tsx
Normal file
40
src/app/(stats)/player/[ign]/_stats/warlords/table.tsx
Normal file
@@ -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<NonNullStats["Warlords"]> }) {
|
||||||
|
return (
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead>Mode</TableHead>
|
||||||
|
<TableHead>Wins</TableHead>
|
||||||
|
<TableHead>Kills</TableHead>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
<WarlordsModeStatsTableStat modeId="capturetheflag" stats={stats} />
|
||||||
|
<WarlordsModeStatsTableStat modeId="domination" stats={stats} />
|
||||||
|
<WarlordsModeStatsTableStat modeId="teamdeathmatch" stats={stats} />
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function WarlordsModeStatsTableStat(
|
||||||
|
{ modeId, stats }: { modeId: Parameters<typeof getWarlordsModeStats>[0], stats: NonNullable<NonNullStats["Warlords"]> }
|
||||||
|
) {
|
||||||
|
const modeStats = getWarlordsModeStats(modeId, stats)
|
||||||
|
const name = getWarlordsModeName(modeId)
|
||||||
|
const mostPlayed = getWarlordsMostPlayedMode(stats)?.id === modeId
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TableRow className={cn(mostPlayed && "text-mc-light-purple")}>
|
||||||
|
<TableCell>{name}</TableCell>
|
||||||
|
<TableCell>{formatNumber(modeStats.wins)}</TableCell>
|
||||||
|
<TableCell>{formatNumber(modeStats.kills)}</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import { NonNullStats } from "@/lib/schema/player"
|
|||||||
import GeneralStats from "../GeneralStats"
|
import GeneralStats from "../GeneralStats"
|
||||||
import { WarlordsWeaponsBar } from "./client"
|
import { WarlordsWeaponsBar } from "./client"
|
||||||
import WarlordsGeneralStats from "./stats"
|
import WarlordsGeneralStats from "./stats"
|
||||||
|
import { WarlordsModeStatsTable } from "./table"
|
||||||
|
|
||||||
export default function WarlordsStats({ stats }: { stats: NonNullStats["Warlords"] }) {
|
export default function WarlordsStats({ stats }: { stats: NonNullStats["Warlords"] }) {
|
||||||
if (!stats) return null
|
if (!stats) return null
|
||||||
@@ -43,6 +44,8 @@ export default function WarlordsStats({ stats }: { stats: NonNullStats["Warlords
|
|||||||
<Separator className="my-4" />
|
<Separator className="my-4" />
|
||||||
<WarlordsWeaponsBar stats={stats} />
|
<WarlordsWeaponsBar stats={stats} />
|
||||||
<Separator className="my-4" />
|
<Separator className="my-4" />
|
||||||
|
<WarlordsModeStatsTable stats={stats} />
|
||||||
|
<Separator className="my-4" />
|
||||||
</GeneralStats>
|
</GeneralStats>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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"
|
import { NonNullStats } from "@/lib/schema/player"
|
||||||
|
|
||||||
|
export function getWarlordsModeName(modeId: Exclude<typeof MODES[number]["id"], ""> | "all") {
|
||||||
|
if (modeId === "all") {
|
||||||
|
return MODES.find(m => m.id === "")!.name
|
||||||
|
}
|
||||||
|
return MODES.find(m => m.id === modeId)!.name
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getWarlordsMostPlayedMode(stats: NonNullable<NonNullStats["Warlords"]>) {
|
||||||
|
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<typeof MODES[number]["id"], ""> | "all", stats: NonNullable<NonNullStats["Warlords"]>) {
|
||||||
|
if (modeId === "all") {
|
||||||
|
return {
|
||||||
|
kills: stats.kills,
|
||||||
|
wins: stats.wins
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
kills: stats[`kills_${modeId}`],
|
||||||
|
wins: stats[`wins_${modeId}`]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function getWarlordsWeaponsRepaired(stats: NonNullable<NonNullStats["Warlords"]>) {
|
export function getWarlordsWeaponsRepaired(stats: NonNullable<NonNullStats["Warlords"]>) {
|
||||||
const val: { repaired: typeof RARITIES[number], num: number }[] = []
|
const val: { repaired: typeof RARITIES[number], num: number }[] = []
|
||||||
|
|
||||||
|
|||||||
@@ -26,5 +26,11 @@ export const warlordsStatsSchema = z.object({
|
|||||||
repaired_common: z.number().default(0),
|
repaired_common: z.number().default(0),
|
||||||
repaired_rare: z.number().default(0),
|
repaired_rare: z.number().default(0),
|
||||||
repaired_epic: 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)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user