Refactored bedwars table

This commit is contained in:
2025-09-02 14:03:34 +02:00
parent 2b262025df
commit 6d94e46d67

View File

@@ -4,31 +4,111 @@ import { _BedwarsStats, concatBedwarsStats, getBedwarsModeStats, getBestMode } f
import { NonNullStats } from "@/lib/schema/player"
import { cn } from "@/lib/utils"
type BedwarsModeKey =
| "solo"
| "doubles"
| "3s"
| "4s"
| "4v4"
| "rush_2s"
| "rush_4s"
| "ultimate_2s"
| "ultimate_4s"
| "lucky_2s"
| "lucky_4s"
| "voidless_2s"
| "voidless_4s"
| "armed_2s"
| "armed_4s"
| "swap_4s"
| "underworld_4s"
| "castle"
interface RowConfig {
label: string
key?: BedwarsModeKey
aggregateOf?: BedwarsModeKey[]
highlightBest?: boolean
bold?: boolean
}
const SIMPLE_MODE_KEYS: BedwarsModeKey[] = [
"solo",
"doubles",
"3s",
"4s",
"4v4",
"rush_2s",
"rush_4s",
"ultimate_2s",
"ultimate_4s",
"lucky_2s",
"lucky_4s",
"voidless_2s",
"voidless_4s",
"armed_2s",
"armed_4s",
"swap_4s",
"underworld_4s",
"castle"
]
const ROWS: RowConfig[] = [
{ label: "Solo", key: "solo", highlightBest: true },
{ label: "Doubles", key: "doubles", highlightBest: true },
{ label: "3v3v3v3", key: "3s", highlightBest: true },
{ label: "4v4v4v4", key: "4s", highlightBest: true },
{ label: "Core Modes", aggregateOf: ["solo", "doubles", "3s", "4s"], bold: true },
{ label: "4v4", key: "4v4" },
{ label: "Rush Doubles", key: "rush_2s" },
{ label: "Rush 4v4v4v4", key: "rush_4s" },
{ label: "Ultimate Doubles", key: "ultimate_2s" },
{ label: "Ultimate 4v4v4v4", key: "ultimate_4s" },
{ label: "Lucky Doubles", key: "lucky_2s" },
{ label: "Lucky 4v4v4v4", key: "lucky_4s" },
{ label: "Voidless Doubles", key: "voidless_2s" },
{ label: "Voidless 4v4v4v4", key: "voidless_4s" },
{ label: "Armed Doubles", key: "armed_2s" },
{ label: "Armed 4v4v4v4", key: "armed_4s" },
{ label: "Swap 4v4v4v4", key: "swap_4s" },
{ label: "Underworld 4v4v4v4", key: "underworld_4s" },
{ label: "Castle", key: "castle" },
{ label: "All Modes", aggregateOf: SIMPLE_MODE_KEYS, bold: true }
]
function StatRow({ cfg, stats }: { cfg: RowConfig, stats: NonNullStats["Bedwars"] }) {
const bedwars = stats as _BedwarsStats
let values: (number | string)[] = []
if (cfg.key) {
values = getBedwarsModeStats(cfg.key, bedwars) as (number | string)[]
} else if (cfg.aggregateOf) {
const rawArrays = cfg.aggregateOf.map(k => getBedwarsModeStats(k, bedwars, true))
values = concatBedwarsStats(...rawArrays)
}
const isBest = cfg.highlightBest && cfg.key && getBestMode(bedwars) === cfg.key
const className = cn(
cfg.bold && "font-bold",
isBest && "font-bold text-mc-light-purple"
)
return (
<TableRow className={className}>
<TableCell>{cfg.label}</TableCell>
{values.map((v, i) => <TableCell key={i}>{typeof v === "number" ? formatNumber(v) : v}</TableCell>)}
</TableRow>
)
}
export default function BedwarsStatTable({ stats }: { stats: NonNullStats["Bedwars"] }) {
return (
<Table>
<BedwarsTableHeader />
<TableBody>
<SoloStats stats={stats} />
<DoublesStats stats={stats} />
<ThreesStats stats={stats} />
<FoursStats stats={stats} />
<CoreModeStats stats={stats} />
<FourVFourStats stats={stats} />
<RushDoublesStats stats={stats} />
<Rush4sStats stats={stats} />
<UltimateDoublesStats stats={stats} />
<Ultimate4sStats stats={stats} />
<LuckyDoublesStats stats={stats} />
<Lucky4sStats stats={stats} />
<VoidlessDoublesStats stats={stats} />
<Voidless4sStats stats={stats} />
<ArmedDoublesStats stats={stats} />
<Armed4sStats stats={stats} />
<Swap4sStats stats={stats} />
<Underworld4sStats stats={stats} />
<CastleStats stats={stats} />
<AllModeStats stats={stats} />
{ROWS.map((cfg, i) => <StatRow key={i} cfg={cfg} stats={stats} />)}
</TableBody>
</Table>
)
@@ -60,317 +140,8 @@ function BedwarsTableHeader() {
<TableHead colSpan={3} className="font-bold">Finals</TableHead>
</TableRow>
<TableRow>
{headerElements.map((v, i) => {
return <TableHead key={i} className="font-bold">{v}</TableHead>
})}
{headerElements.map((v, i) => <TableHead key={i} className="font-bold">{v}</TableHead>)}
</TableRow>
</TableHeader>
)
}
function SoloStats({ stats }: { stats: NonNullStats["Bedwars"] }) {
const modeStats = getBedwarsModeStats("solo", stats as _BedwarsStats)
const isBest = getBestMode(stats as _BedwarsStats) === "solo"
return (
<TableRow className={cn(isBest ? "font-bold text-mc-light-purple" : undefined)}>
<TableCell>Solo</TableCell>
{modeStats.map((v, i) => {
return <TableCell key={i}>{typeof v === "number" ? formatNumber(v) : v}</TableCell>
})}
</TableRow>
)
}
function DoublesStats({ stats }: { stats: NonNullStats["Bedwars"] }) {
const modeStats = getBedwarsModeStats("doubles", stats as _BedwarsStats)
const isBest = getBestMode(stats as _BedwarsStats) === "doubles"
return (
<TableRow className={cn(isBest ? "font-bold text-mc-light-purple" : undefined)}>
<TableCell>Doubles</TableCell>
{modeStats.map((v, i) => {
return <TableCell key={i}>{typeof v === "number" ? formatNumber(v) : v}</TableCell>
})}
</TableRow>
)
}
function ThreesStats({ stats }: { stats: NonNullStats["Bedwars"] }) {
const modeStats = getBedwarsModeStats("3s", stats as _BedwarsStats)
const isBest = getBestMode(stats as _BedwarsStats) === "3s"
return (
<TableRow className={cn(isBest ? "font-bold text-mc-light-purple" : undefined)}>
<TableCell>3v3v3v3</TableCell>
{modeStats.map((v, i) => {
return <TableCell key={i}>{typeof v === "number" ? formatNumber(v) : v}</TableCell>
})}
</TableRow>
)
}
function FoursStats({ stats }: { stats: NonNullStats["Bedwars"] }) {
const modeStats = getBedwarsModeStats("4s", stats as _BedwarsStats)
const isBest = getBestMode(stats as _BedwarsStats) === "4s"
return (
<TableRow className={cn(isBest ? "font-bold text-mc-light-purple" : undefined)}>
<TableCell>4v4v4v4</TableCell>
{modeStats.map((v, i) => {
return <TableCell key={i}>{typeof v === "number" ? formatNumber(v) : v}</TableCell>
})}
</TableRow>
)
}
function CoreModeStats({ stats }: { stats: NonNullStats["Bedwars"] }) {
const soloStats = getBedwarsModeStats("solo", stats as _BedwarsStats, true)
const doublesStats = getBedwarsModeStats("doubles", stats as _BedwarsStats, true)
const threesStats = getBedwarsModeStats("3s", stats as _BedwarsStats, true)
const foursStats = getBedwarsModeStats("4s", stats as _BedwarsStats, true)
const combinedStats = concatBedwarsStats(soloStats, doublesStats, threesStats, foursStats)
return (
<TableRow className="font-bold">
<TableCell>Core Modes</TableCell>
{combinedStats.map((v, i) => {
return <TableCell key={i}>{typeof v === "number" ? formatNumber(v) : v}</TableCell>
})}
</TableRow>
)
}
function FourVFourStats({ stats }: { stats: NonNullStats["Bedwars"] }) {
const modeStats = getBedwarsModeStats("4v4", stats as _BedwarsStats)
return (
<TableRow>
<TableCell>4v4</TableCell>
{modeStats.map((v, i) => {
return <TableCell key={i}>{typeof v === "number" ? formatNumber(v) : v}</TableCell>
})}
</TableRow>
)
}
function RushDoublesStats({ stats }: { stats: NonNullStats["Bedwars"] }) {
const modeStats = getBedwarsModeStats("rush_2s", stats as _BedwarsStats)
return (
<TableRow>
<TableCell>Rush Doubles</TableCell>
{modeStats.map((v, i) => {
return <TableCell key={i}>{typeof v === "number" ? formatNumber(v) : v}</TableCell>
})}
</TableRow>
)
}
function Rush4sStats({ stats }: { stats: NonNullStats["Bedwars"] }) {
const modeStats = getBedwarsModeStats("rush_4s", stats as _BedwarsStats)
return (
<TableRow>
<TableCell>Rush 4v4v4v4</TableCell>
{modeStats.map((v, i) => {
return <TableCell key={i}>{typeof v === "number" ? formatNumber(v) : v}</TableCell>
})}
</TableRow>
)
}
function UltimateDoublesStats({ stats }: { stats: NonNullStats["Bedwars"] }) {
const modeStats = getBedwarsModeStats("ultimate_2s", stats as _BedwarsStats)
return (
<TableRow>
<TableCell>Ultimate Doubles</TableCell>
{modeStats.map((v, i) => {
return <TableCell key={i}>{typeof v === "number" ? formatNumber(v) : v}</TableCell>
})}
</TableRow>
)
}
function Ultimate4sStats({ stats }: { stats: NonNullStats["Bedwars"] }) {
const modeStats = getBedwarsModeStats("ultimate_4s", stats as _BedwarsStats)
return (
<TableRow>
<TableCell>Ultimate 4v4v4v4</TableCell>
{modeStats.map((v, i) => {
return <TableCell key={i}>{typeof v === "number" ? formatNumber(v) : v}</TableCell>
})}
</TableRow>
)
}
function LuckyDoublesStats({ stats }: { stats: NonNullStats["Bedwars"] }) {
const modeStats = getBedwarsModeStats("lucky_2s", stats as _BedwarsStats)
return (
<TableRow>
<TableCell>Lucky Doubles</TableCell>
{modeStats.map((v, i) => {
return <TableCell key={i}>{typeof v === "number" ? formatNumber(v) : v}</TableCell>
})}
</TableRow>
)
}
function Lucky4sStats({ stats }: { stats: NonNullStats["Bedwars"] }) {
const modeStats = getBedwarsModeStats("lucky_4s", stats as _BedwarsStats)
return (
<TableRow>
<TableCell>Lucky 4v4v4v4</TableCell>
{modeStats.map((v, i) => {
return <TableCell key={i}>{typeof v === "number" ? formatNumber(v) : v}</TableCell>
})}
</TableRow>
)
}
function VoidlessDoublesStats({ stats }: { stats: NonNullStats["Bedwars"] }) {
const modeStats = getBedwarsModeStats("voidless_2s", stats as _BedwarsStats)
return (
<TableRow>
<TableCell>Voidless Doubles</TableCell>
{modeStats.map((v, i) => {
return <TableCell key={i}>{typeof v === "number" ? formatNumber(v) : v}</TableCell>
})}
</TableRow>
)
}
function Voidless4sStats({ stats }: { stats: NonNullStats["Bedwars"] }) {
const modeStats = getBedwarsModeStats("voidless_4s", stats as _BedwarsStats)
return (
<TableRow>
<TableCell>Voidless 4v4v4v4</TableCell>
{modeStats.map((v, i) => {
return <TableCell key={i}>{typeof v === "number" ? formatNumber(v) : v}</TableCell>
})}
</TableRow>
)
}
function ArmedDoublesStats({ stats }: { stats: NonNullStats["Bedwars"] }) {
const modeStats = getBedwarsModeStats("armed_2s", stats as _BedwarsStats)
return (
<TableRow>
<TableCell>Armed Doubles</TableCell>
{modeStats.map((v, i) => {
return <TableCell key={i}>{typeof v === "number" ? formatNumber(v) : v}</TableCell>
})}
</TableRow>
)
}
function Armed4sStats({ stats }: { stats: NonNullStats["Bedwars"] }) {
const modeStats = getBedwarsModeStats("armed_4s", stats as _BedwarsStats)
return (
<TableRow>
<TableCell>Armed 4v4v4v4</TableCell>
{modeStats.map((v, i) => {
return <TableCell key={i}>{typeof v === "number" ? formatNumber(v) : v}</TableCell>
})}
</TableRow>
)
}
function Swap4sStats({ stats }: { stats: NonNullStats["Bedwars"] }) {
const modeStats = getBedwarsModeStats("swap_4s", stats as _BedwarsStats)
return (
<TableRow>
<TableCell>Swap 4v4v4v4</TableCell>
{modeStats.map((v, i) => {
return <TableCell key={i}>{typeof v === "number" ? formatNumber(v) : v}</TableCell>
})}
</TableRow>
)
}
function Underworld4sStats({ stats }: { stats: NonNullStats["Bedwars"] }) {
const modeStats = getBedwarsModeStats("underworld_4s", stats as _BedwarsStats)
return (
<TableRow>
<TableCell>Underworld 4v4v4v4</TableCell>
{modeStats.map((v, i) => {
return <TableCell key={i}>{typeof v === "number" ? formatNumber(v) : v}</TableCell>
})}
</TableRow>
)
}
function CastleStats({ stats }: { stats: NonNullStats["Bedwars"] }) {
const modeStats = getBedwarsModeStats("castle", stats as _BedwarsStats)
return (
<TableRow>
<TableCell>Castle</TableCell>
{modeStats.map((v, i) => {
return <TableCell key={i}>{typeof v === "number" ? formatNumber(v) : v}</TableCell>
})}
</TableRow>
)
}
function AllModeStats({ stats }: { stats: NonNullStats["Bedwars"] }) {
const soloStats = getBedwarsModeStats("solo", stats as _BedwarsStats, true)
const doublesStats = getBedwarsModeStats("doubles", stats as _BedwarsStats, true)
const threesStats = getBedwarsModeStats("3s", stats as _BedwarsStats, true)
const foursStats = getBedwarsModeStats("4s", stats as _BedwarsStats, true)
const fourVFourStats = getBedwarsModeStats("4v4", stats as _BedwarsStats, true)
const rushDoublesStats = getBedwarsModeStats("rush_2s", stats as _BedwarsStats, true)
const rush4sStats = getBedwarsModeStats("rush_4s", stats as _BedwarsStats, true)
const ultimateDoublesStats = getBedwarsModeStats("ultimate_2s", stats as _BedwarsStats, true)
const ultimate4sStats = getBedwarsModeStats("ultimate_4s", stats as _BedwarsStats, true)
const luckyDoublesStats = getBedwarsModeStats("lucky_2s", stats as _BedwarsStats, true)
const lucky4sStats = getBedwarsModeStats("lucky_4s", stats as _BedwarsStats, true)
const voidlessDoublesStats = getBedwarsModeStats("voidless_2s", stats as _BedwarsStats, true)
const voidless4sStats = getBedwarsModeStats("voidless_4s", stats as _BedwarsStats, true)
const armedDoublesStats = getBedwarsModeStats("armed_2s", stats as _BedwarsStats, true)
const armed4sStats = getBedwarsModeStats("armed_4s", stats as _BedwarsStats, true)
const swap4sStats = getBedwarsModeStats("swap_4s", stats as _BedwarsStats, true)
const underworld4sStats = getBedwarsModeStats("underworld_4s", stats as _BedwarsStats, true)
const castleStats = getBedwarsModeStats("castle", stats as _BedwarsStats, true)
const finalStats = concatBedwarsStats(
soloStats,
doublesStats,
threesStats,
foursStats,
fourVFourStats,
rushDoublesStats,
rush4sStats,
ultimateDoublesStats,
ultimate4sStats,
luckyDoublesStats,
lucky4sStats,
voidlessDoublesStats,
voidless4sStats,
armedDoublesStats,
armed4sStats,
swap4sStats,
underworld4sStats,
castleStats
)
return (
<TableRow className="font-bold">
<TableCell>All Modes</TableCell>
{finalStats.map((v, i) => {
return <TableCell key={i}>{typeof v === "number" ? formatNumber(v) : v}</TableCell>
})}
</TableRow>
)
}