Added wool games table
This commit is contained in:
@@ -1,11 +1,20 @@
|
||||
import { Table, TableBody, TableHead, TableHeader, TableRow } from "@/components/ui/table"
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
|
||||
import { formatNumber } from "@/lib/formatters"
|
||||
import { getWoolGamesWoolWarsClass, getWoolGamesWoolWarsClassColor, getWoolGamesWoolWarsClassStats } from "@/lib/hypixel/woolgames/general"
|
||||
import { NonNullStats } from "@/lib/schema/player"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
export default function WoolGamesStatTable({ stats }: { stats: NonNullable<NonNullStats["WoolGames"]> }) {
|
||||
export default function WoolGamesWoolWarsStatTable({ stats }: { stats: NonNullable<NonNullStats["WoolGames"]>["wool_wars"] }) {
|
||||
return (
|
||||
<Table>
|
||||
<WoolGamesTableHeader />
|
||||
<TableBody>
|
||||
<StatRow classId="tank" stats={stats} />
|
||||
<StatRow classId="archer" stats={stats} />
|
||||
<StatRow classId="swordsman" stats={stats} />
|
||||
<StatRow classId="engineer" stats={stats} />
|
||||
<StatRow classId="golem" stats={stats} />
|
||||
<StatRow classId="assault" stats={stats} />
|
||||
</TableBody>
|
||||
</Table>
|
||||
)
|
||||
@@ -33,3 +42,23 @@ function WoolGamesTableHeader() {
|
||||
</TableHeader>
|
||||
)
|
||||
}
|
||||
|
||||
function StatRow(
|
||||
{ classId, stats }: {
|
||||
classId: Parameters<typeof getWoolGamesWoolWarsClassStats>[0]
|
||||
stats: NonNullable<NonNullStats["WoolGames"]>["wool_wars"]
|
||||
}
|
||||
) {
|
||||
const classStats = getWoolGamesWoolWarsClassStats(classId, stats)
|
||||
const klass = getWoolGamesWoolWarsClass(classId)
|
||||
const classColor = getWoolGamesWoolWarsClassColor(klass?.difficulty)
|
||||
|
||||
return (
|
||||
<TableRow>
|
||||
<TableCell className={cn(classColor && `text-mc-${classColor}`)}>{klass !== null ? klass.name : "Unknown"}</TableCell>
|
||||
{classStats.map((v, i) => {
|
||||
return <TableCell key={i}>{formatNumber(v)}</TableCell>
|
||||
})}
|
||||
</TableRow>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import GeneralStats from "../GeneralStats"
|
||||
import { WoolGamesCaptureTheWool, WoolGamesSheepWars, WoolGamesWoolWars } from "./modes"
|
||||
import WoolGamesProgress from "./progress"
|
||||
import WoolGamesGeneralStats from "./stats"
|
||||
import WoolGamesStatTable from "./table"
|
||||
import WoolGamesWoolWarsStatTable from "./table"
|
||||
|
||||
export default function WoolGamesStats({ stats }: { stats: NonNullStats["WoolGames"] }) {
|
||||
if (!stats) return null
|
||||
@@ -47,7 +47,7 @@ export default function WoolGamesStats({ stats }: { stats: NonNullStats["WoolGam
|
||||
<WoolGamesSheepWars sw={stats.sheep_wars} />
|
||||
<Separator className="my-4" />
|
||||
<WoolGamesWoolWars ww={stats.wool_wars} />
|
||||
<WoolGamesStatTable stats={stats} />
|
||||
<WoolGamesWoolWarsStatTable stats={stats.wool_wars} />
|
||||
<Separator className="my-4" />
|
||||
</GeneralStats>
|
||||
)
|
||||
|
||||
@@ -1,6 +1,29 @@
|
||||
import { CLASSES, DIFFICULTIES, EASY_XP, ICONS, NORMAL_XP, PRESTIGES } from "@/data/hypixel/woolgames"
|
||||
import { getColorFromCode } from "@/lib/colors"
|
||||
import { floorLevel } from "../general"
|
||||
import { NonNullStats } from "@/lib/schema/player"
|
||||
import { devide, floorLevel } from "../general"
|
||||
|
||||
export function getWoolGamesWoolWarsClassStats(
|
||||
classId: typeof CLASSES[number]["id"],
|
||||
stats: NonNullable<NonNullStats["WoolGames"]>["wool_wars"]
|
||||
) {
|
||||
const nums: number[] = []
|
||||
for (let i = 0; i++; i < 7) {
|
||||
nums.push(0)
|
||||
}
|
||||
|
||||
if (!stats) return nums
|
||||
|
||||
return [
|
||||
stats.stats?.classes[classId]?.kills || 0,
|
||||
stats.stats?.classes[classId]?.assists || 0,
|
||||
stats.stats?.classes[classId]?.deaths || 0,
|
||||
devide(stats.stats?.classes[classId]?.kills || 0, stats.stats?.classes[classId]?.deaths || 0),
|
||||
stats.stats?.classes[classId]?.wool_placed || 0,
|
||||
stats.stats?.classes[classId]?.blocks_broken || 0,
|
||||
stats.stats?.classes[classId]?.powerups_gotten || 0
|
||||
]
|
||||
}
|
||||
|
||||
export function getWoolGamesWoolWarsClass(val?: string) {
|
||||
const klass = CLASSES.find(c => c.id === val?.toLowerCase())
|
||||
|
||||
@@ -785,7 +785,7 @@ export const woolGamesStatsSchema = z.object({
|
||||
engineer: woolGamesClassStats.optional(),
|
||||
golem: woolGamesClassStats.optional(),
|
||||
assault: woolGamesClassStats.optional()
|
||||
}).optional()
|
||||
}).default({})
|
||||
}).optional()
|
||||
}).optional()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user