UPdated mode stats types
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
|
||||
import { formatNumber } from "@/lib/formatters"
|
||||
import { _BedwarsStats, concatBedwarsStats, getBedwarsModeStats, getBestMode } from "@/lib/hypixel/bedwars/bedwars"
|
||||
import { concatBedwarsStats, getBedwarsModeStats, getBestMode } from "@/lib/hypixel/bedwars/bedwars"
|
||||
import { NonNullStats } from "@/lib/schema/player"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
@@ -77,18 +77,16 @@ const ROWS: RowConfig[] = [
|
||||
]
|
||||
|
||||
function StatRow({ cfg, stats }: { cfg: RowConfig, stats: NonNullable<NonNullStats["Bedwars"]> }) {
|
||||
const bedwars = stats as _BedwarsStats
|
||||
|
||||
let values: (number | string)[] = []
|
||||
|
||||
if (cfg.key) {
|
||||
values = getBedwarsModeStats(cfg.key, bedwars) as (number | string)[]
|
||||
values = getBedwarsModeStats(cfg.key, stats) as (number | string)[]
|
||||
} else if (cfg.aggregateOf) {
|
||||
const rawArrays = cfg.aggregateOf.map(k => getBedwarsModeStats(k, bedwars, true))
|
||||
const rawArrays = cfg.aggregateOf.map(k => getBedwarsModeStats(k, stats, true))
|
||||
values = concatBedwarsStats(...rawArrays)
|
||||
}
|
||||
|
||||
const isBest = cfg.highlightBest && cfg.key && getBestMode(bedwars) === cfg.key
|
||||
const isBest = cfg.highlightBest && cfg.key && getBestMode(stats) === cfg.key
|
||||
|
||||
const className = cn(
|
||||
cfg.bold && "font-bold",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
|
||||
import { formatNumber } from "@/lib/formatters"
|
||||
import { _SkywarsStats, concatSkywarsStats, getBestSkywarsMode, getSkywarsModeStats } from "@/lib/hypixel/skywars/skywars"
|
||||
import { concatSkywarsStats, getBestSkywarsMode, getSkywarsModeStats } from "@/lib/hypixel/skywars/skywars"
|
||||
import { NonNullStats } from "@/lib/schema/player"
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
@@ -44,9 +44,9 @@ function SkywarsTableHeader() {
|
||||
)
|
||||
}
|
||||
|
||||
function Normal({ stats }: { stats: NonNullStats["SkyWars"] }) {
|
||||
const modeStats = getSkywarsModeStats("normal", stats as _SkywarsStats)
|
||||
const isBest = getBestSkywarsMode(stats as _SkywarsStats) === "normal"
|
||||
function Normal({ stats }: { stats: NonNullable<NonNullStats["SkyWars"]> }) {
|
||||
const modeStats = getSkywarsModeStats("normal", stats)
|
||||
const isBest = getBestSkywarsMode(stats) === "normal"
|
||||
|
||||
return (
|
||||
<TableRow className={cn(isBest ? "font-bold text-mc-light-purple" : undefined)}>
|
||||
@@ -58,9 +58,9 @@ function Normal({ stats }: { stats: NonNullStats["SkyWars"] }) {
|
||||
)
|
||||
}
|
||||
|
||||
function Insane({ stats }: { stats: NonNullStats["SkyWars"] }) {
|
||||
const modeStats = getSkywarsModeStats("insane", stats as _SkywarsStats)
|
||||
const isBest = getBestSkywarsMode(stats as _SkywarsStats) === "insane"
|
||||
function Insane({ stats }: { stats: NonNullable<NonNullStats["SkyWars"]> }) {
|
||||
const modeStats = getSkywarsModeStats("insane", stats)
|
||||
const isBest = getBestSkywarsMode(stats) === "insane"
|
||||
|
||||
return (
|
||||
<TableRow className={cn(isBest ? "font-bold text-mc-light-purple" : undefined)}>
|
||||
@@ -72,9 +72,9 @@ function Insane({ stats }: { stats: NonNullStats["SkyWars"] }) {
|
||||
)
|
||||
}
|
||||
|
||||
function TeamsNormal({ stats }: { stats: NonNullStats["SkyWars"] }) {
|
||||
const modeStats = getSkywarsModeStats("teams_normal", stats as _SkywarsStats)
|
||||
const isBest = getBestSkywarsMode(stats as _SkywarsStats) === "teams_normal"
|
||||
function TeamsNormal({ stats }: { stats: NonNullable<NonNullStats["SkyWars"]> }) {
|
||||
const modeStats = getSkywarsModeStats("teams_normal", stats)
|
||||
const isBest = getBestSkywarsMode(stats) === "teams_normal"
|
||||
|
||||
return (
|
||||
<TableRow className={cn(isBest ? "font-bold text-mc-light-purple" : undefined)}>
|
||||
@@ -86,9 +86,9 @@ function TeamsNormal({ stats }: { stats: NonNullStats["SkyWars"] }) {
|
||||
)
|
||||
}
|
||||
|
||||
function TeamsInsane({ stats }: { stats: NonNullStats["SkyWars"] }) {
|
||||
const modeStats = getSkywarsModeStats("teams_insane", stats as _SkywarsStats)
|
||||
const isBest = getBestSkywarsMode(stats as _SkywarsStats) === "teams_insane"
|
||||
function TeamsInsane({ stats }: { stats: NonNullable<NonNullStats["SkyWars"]> }) {
|
||||
const modeStats = getSkywarsModeStats("teams_insane", stats)
|
||||
const isBest = getBestSkywarsMode(stats) === "teams_insane"
|
||||
|
||||
return (
|
||||
<TableRow className={cn(isBest ? "font-bold text-mc-light-purple" : undefined)}>
|
||||
@@ -100,9 +100,9 @@ function TeamsInsane({ stats }: { stats: NonNullStats["SkyWars"] }) {
|
||||
)
|
||||
}
|
||||
|
||||
function Mega({ stats }: { stats: NonNullStats["SkyWars"] }) {
|
||||
const modeStats = getSkywarsModeStats("mega", stats as _SkywarsStats)
|
||||
const isBest = getBestSkywarsMode(stats as _SkywarsStats) === "mega"
|
||||
function Mega({ stats }: { stats: NonNullable<NonNullStats["SkyWars"]> }) {
|
||||
const modeStats = getSkywarsModeStats("mega", stats)
|
||||
const isBest = getBestSkywarsMode(stats) === "mega"
|
||||
|
||||
return (
|
||||
<TableRow className={cn(isBest ? "font-bold text-mc-light-purple" : undefined)}>
|
||||
@@ -114,9 +114,9 @@ function Mega({ stats }: { stats: NonNullStats["SkyWars"] }) {
|
||||
)
|
||||
}
|
||||
|
||||
function MegaDoubles({ stats }: { stats: NonNullStats["SkyWars"] }) {
|
||||
const modeStats = getSkywarsModeStats("mega_doubles", stats as _SkywarsStats)
|
||||
const isBest = getBestSkywarsMode(stats as _SkywarsStats) === "mega_doubles"
|
||||
function MegaDoubles({ stats }: { stats: NonNullable<NonNullStats["SkyWars"]> }) {
|
||||
const modeStats = getSkywarsModeStats("mega_doubles", stats)
|
||||
const isBest = getBestSkywarsMode(stats) === "mega_doubles"
|
||||
|
||||
return (
|
||||
<TableRow className={cn(isBest ? "font-bold text-mc-light-purple" : undefined)}>
|
||||
@@ -128,9 +128,9 @@ function MegaDoubles({ stats }: { stats: NonNullStats["SkyWars"] }) {
|
||||
)
|
||||
}
|
||||
|
||||
function Ranked({ stats }: { stats: NonNullStats["SkyWars"] }) {
|
||||
const modeStats = getSkywarsModeStats("ranked", stats as _SkywarsStats)
|
||||
const isBest = getBestSkywarsMode(stats as _SkywarsStats) === "ranked"
|
||||
function Ranked({ stats }: { stats: NonNullable<NonNullStats["SkyWars"]> }) {
|
||||
const modeStats = getSkywarsModeStats("ranked", stats)
|
||||
const isBest = getBestSkywarsMode(stats) === "ranked"
|
||||
|
||||
return (
|
||||
<TableRow className={cn(isBest ? "font-bold text-mc-light-purple" : undefined)}>
|
||||
@@ -142,14 +142,14 @@ function Ranked({ stats }: { stats: NonNullStats["SkyWars"] }) {
|
||||
)
|
||||
}
|
||||
|
||||
function OverallModeStats({ stats }: { stats: NonNullStats["SkyWars"] }) {
|
||||
const normal = getSkywarsModeStats("normal", stats as _SkywarsStats, true)
|
||||
const insane = getSkywarsModeStats("insane", stats as _SkywarsStats, true)
|
||||
const teams_normal = getSkywarsModeStats("teams_normal", stats as _SkywarsStats, true)
|
||||
const teams_insane = getSkywarsModeStats("teams_insane", stats as _SkywarsStats, true)
|
||||
const mega = getSkywarsModeStats("mega", stats as _SkywarsStats, true)
|
||||
const mega_doubles = getSkywarsModeStats("mega_doubles", stats as _SkywarsStats, true)
|
||||
const ranked = getSkywarsModeStats("ranked", stats as _SkywarsStats, true)
|
||||
function OverallModeStats({ stats }: { stats: NonNullable<NonNullStats["SkyWars"]> }) {
|
||||
const normal = getSkywarsModeStats("normal", stats, true)
|
||||
const insane = getSkywarsModeStats("insane", stats, true)
|
||||
const teams_normal = getSkywarsModeStats("teams_normal", stats, true)
|
||||
const teams_insane = getSkywarsModeStats("teams_insane", stats, true)
|
||||
const mega = getSkywarsModeStats("mega", stats, true)
|
||||
const mega_doubles = getSkywarsModeStats("mega_doubles", stats, true)
|
||||
const ranked = getSkywarsModeStats("ranked", stats, true)
|
||||
|
||||
const combinedStats = concatSkywarsStats(normal, insane, teams_normal, teams_insane, mega, mega_doubles, ranked)
|
||||
|
||||
|
||||
@@ -58,28 +58,24 @@ export const PRESTIGE_ICONS = [
|
||||
{ level: 3100, symbol: "✥" }
|
||||
] as const
|
||||
export const MODES = [
|
||||
{ id: "eight_one_", name: "Solo" },
|
||||
{ id: "eight_two_", name: "Doubles" },
|
||||
{ id: "four_three_", name: "3v3v3v3" },
|
||||
{ id: "four_four_", name: "4v4v4v4" },
|
||||
{ id: "two_four_", name: "4v4" },
|
||||
{ id: "eight_one_rush_", name: "Rush Solo" },
|
||||
{ id: "eight_two_rush_", name: "Rush Doubles" },
|
||||
{ id: "four_four_rush_", name: "Rush 4v4v4v4" },
|
||||
{ id: "eight_one_ultimate_", name: "Ultimate Solo" },
|
||||
{ id: "eight_two_ultimate_", name: "Ultimate Doubles" },
|
||||
{ id: "four_four_ultimate_", name: "Ultimate 4v4v4v4" },
|
||||
{ id: "eight_two_lucky_", name: "Lucky Doubles" },
|
||||
{ id: "four_four_lucky_", name: "Lucky 4v4v4v4" },
|
||||
{ id: "eight_two_voidless_", name: "Voidless Doubles" },
|
||||
{ id: "four_four_voidless_", name: "Voidless 4v4v4v4" },
|
||||
{ id: "eight_two_armed_", name: "Armed Doubles" },
|
||||
{ id: "four_four_armed_", name: "Armed 4v4v4v4" },
|
||||
{ id: "eight_two_swap_", name: "Swappage Doubles" },
|
||||
{ id: "four_four_swap_", name: "Swappage 4v4v4v4" },
|
||||
{ id: "eight_two_underworld_", name: "Underworld Doubles" },
|
||||
{ id: "four_four_underworld_", name: "Underworld 4v4v4v4" },
|
||||
{ id: "castle_", name: "Castle" },
|
||||
{ id: "eight_one", name: "Solo" },
|
||||
{ id: "eight_two", name: "Doubles" },
|
||||
{ id: "four_three", name: "3v3v3v3" },
|
||||
{ id: "four_four", name: "4v4v4v4" },
|
||||
{ id: "two_four", name: "4v4" },
|
||||
{ id: "eight_two_rush", name: "Rush Doubles" },
|
||||
{ id: "four_four_rush", name: "Rush 4v4v4v4" },
|
||||
{ id: "eight_two_ultimate", name: "Ultimate Doubles" },
|
||||
{ id: "four_four_ultimate", name: "Ultimate 4v4v4v4" },
|
||||
{ id: "eight_two_lucky", name: "Lucky Doubles" },
|
||||
{ id: "four_four_lucky", name: "Lucky 4v4v4v4" },
|
||||
{ id: "eight_two_voidless", name: "Voidless Doubles" },
|
||||
{ id: "four_four_voidless", name: "Voidless 4v4v4v4" },
|
||||
{ id: "eight_two_armed", name: "Armed Doubles" },
|
||||
{ id: "four_four_armed", name: "Armed 4v4v4v4" },
|
||||
{ id: "four_four_swap", name: "Swappage 4v4v4v4" },
|
||||
{ id: "four_four_underworld", name: "Underworld 4v4v4v4" },
|
||||
{ id: "castle", name: "Castle" },
|
||||
{ id: "", name: "Overall" }
|
||||
] as const
|
||||
export const PRACTICEMODES = [
|
||||
|
||||
@@ -251,13 +251,13 @@ export const ICONS = {
|
||||
} as const
|
||||
|
||||
export const MODES = [
|
||||
{ id: "_ranked", name: "Ranked" },
|
||||
{ id: "_solo_normal", name: "Solo Normal" },
|
||||
{ id: "_solo_insane", name: "Solo Insane" },
|
||||
{ id: "_team_normal", name: "Teams Normal" },
|
||||
{ id: "_team_insane", name: "Teams Insane" },
|
||||
{ id: "_mega_normal", name: "Mega" },
|
||||
{ id: "_mega_doubles", name: "Mega Doubles" },
|
||||
{ id: "ranked_normal", name: "Ranked" },
|
||||
{ id: "solo_normal", name: "Solo Normal" },
|
||||
{ id: "solo_insane", name: "Solo Insane" },
|
||||
{ id: "team_normal", name: "Teams Normal" },
|
||||
{ id: "team_insane", name: "Teams Insane" },
|
||||
{ id: "mega", name: "Mega" },
|
||||
{ id: "mega_doubles", name: "Mega Doubles" },
|
||||
{ id: "", name: "Overall" }
|
||||
] as const
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { PRESTIGE_ICONS, PRESTIGES, SLUMBER_ROOMS, SLUMBER_WALLETS } from "@/data/hypixel/bedwars"
|
||||
import { MODES, PRESTIGE_ICONS, PRESTIGES, SLUMBER_ROOMS, SLUMBER_WALLETS } from "@/data/hypixel/bedwars"
|
||||
import { getColorFromCode } from "@/lib/colors"
|
||||
import { formatNumber } from "@/lib/formatters"
|
||||
import { NonNullStats } from "@/lib/schema/player"
|
||||
import { concatStatsArray, devide, floorLevel } from "../general"
|
||||
|
||||
export function getBedwarsStar(level: number) {
|
||||
@@ -122,7 +123,6 @@ export function getBedwarsLatestRoom(rooms?: Record<string, boolean>) {
|
||||
return latestRoom
|
||||
}
|
||||
|
||||
export type _BedwarsStats = Record<string, number> & { [key: `${string}_winstreak`]: number | undefined }
|
||||
type Mode =
|
||||
| "solo"
|
||||
| "doubles"
|
||||
@@ -155,7 +155,7 @@ export type BedwarsModeStats = {
|
||||
beds_lost_bedwars: number
|
||||
}
|
||||
|
||||
export function getBestMode(stats: _BedwarsStats): "solo" | "doubles" | "3s" | "4s" | null {
|
||||
export function getBestMode(stats: NonNullable<NonNullStats["Bedwars"]>): "solo" | "doubles" | "3s" | "4s" | null {
|
||||
const { wins_bedwars: solo } = getBedwarsModeStats("solo", stats, true)
|
||||
const { wins_bedwars: doubles } = getBedwarsModeStats("doubles", stats, true)
|
||||
const { wins_bedwars: threes } = getBedwarsModeStats("3s", stats, true)
|
||||
@@ -177,9 +177,9 @@ export function getBestMode(stats: _BedwarsStats): "solo" | "doubles" | "3s" | "
|
||||
}
|
||||
}
|
||||
|
||||
export function getBedwarsModeStats(mode: Mode, stats: _BedwarsStats, raw: true): BedwarsModeStats
|
||||
export function getBedwarsModeStats(mode: Mode, stats: _BedwarsStats, raw?: false): (string | number)[]
|
||||
export function getBedwarsModeStats(mode: Mode, stats: _BedwarsStats, raw = false) {
|
||||
export function getBedwarsModeStats(mode: Mode, stats: NonNullable<NonNullStats["Bedwars"]>, raw: true): BedwarsModeStats
|
||||
export function getBedwarsModeStats(mode: Mode, stats: NonNullable<NonNullStats["Bedwars"]>, raw?: false): (string | number)[]
|
||||
export function getBedwarsModeStats(mode: Mode, stats: NonNullable<NonNullStats["Bedwars"]>, raw = false) {
|
||||
switch (mode) {
|
||||
case "solo":
|
||||
return bedwarsModeStats("eight_one", stats, raw)
|
||||
@@ -222,7 +222,7 @@ export function getBedwarsModeStats(mode: Mode, stats: _BedwarsStats, raw = fals
|
||||
}
|
||||
}
|
||||
|
||||
function bedwarsModeStats(prefix: string, stats: _BedwarsStats, raw = false) {
|
||||
function bedwarsModeStats(prefix: Exclude<typeof MODES[number]["id"], "">, stats: NonNullable<NonNullStats["Bedwars"]>, raw = false) {
|
||||
if (raw) {
|
||||
return {
|
||||
kills_bedwars: stats[`${prefix}_kills_bedwars`],
|
||||
|
||||
@@ -9,6 +9,7 @@ export type Div = {
|
||||
color: typeof DIVISIONS[number]["color"]
|
||||
}
|
||||
type Mode = typeof MODES[number]["id"]
|
||||
type BridgeMode = Extract<Mode, `bridge_${string}`>
|
||||
type Devisions = typeof MODES[number]["divisionId"]
|
||||
|
||||
export function getDuelsMode(id: typeof MODES[number]["id"]) {
|
||||
@@ -84,23 +85,24 @@ export function getDuelsModeStats(mode: Mode, stats: NonNullable<NonNullStats["D
|
||||
return duelsModeStats(mode, stats)
|
||||
}
|
||||
|
||||
function duelsModeStats(index: typeof MODES[number]["id"], stats: NonNullable<NonNullStats["Duels"]>) {
|
||||
function duelsModeStats(index: Mode, stats: NonNullable<NonNullStats["Duels"]>) {
|
||||
if (index.startsWith("bridge_")) {
|
||||
const kills = (stats[`${index}_kills`] as number) + (stats[`${index}_bridge_kills`] as number)
|
||||
const deaths = (stats[`${index}_deaths`] as number) + (stats[`${index}_bridge_deaths`] as number)
|
||||
const bIndex = index as BridgeMode
|
||||
const kills = (stats[`${bIndex}_kills`]) + (stats[`${bIndex}_bridge_kills`])
|
||||
const deaths = (stats[`${bIndex}_deaths`]) + (stats[`${bIndex}_bridge_deaths`])
|
||||
|
||||
return [
|
||||
kills,
|
||||
deaths,
|
||||
formatNumber(devide(kills, deaths)),
|
||||
stats[`${index}_wins`],
|
||||
stats[`${index}_losses`],
|
||||
formatNumber(devide(stats[`${index}_wins`], stats[`${index}_losses`])),
|
||||
stats[`current_winstreak_mode_${index}`] ?? "?",
|
||||
stats[`best_winstreak_mode_${index}`] ?? "?",
|
||||
formatNumber(devide(stats[`${index}_melee_hits`], stats[`${index}_melee_swings`])),
|
||||
formatNumber(devide(stats[`${index}_bow_hits`], stats[`${index}_bow_shots`])),
|
||||
formatNumber(stats[`${index}_goals`] as number)
|
||||
stats[`${bIndex}_wins`],
|
||||
stats[`${bIndex}_losses`],
|
||||
formatNumber(devide(stats[`${bIndex}_wins`], stats[`${bIndex}_losses`])),
|
||||
stats[`current_winstreak_mode_${bIndex}`] ?? "?",
|
||||
stats[`best_winstreak_mode_${bIndex}`] ?? "?",
|
||||
formatNumber(devide(stats[`${bIndex}_melee_hits`], stats[`${bIndex}_melee_swings`])),
|
||||
formatNumber(devide(stats[`${bIndex}_bow_hits`], stats[`${bIndex}_bow_shots`])),
|
||||
formatNumber(stats[`${bIndex}_goals`])
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { HEADS, ICONS, PRESTIGES } from "@/data/hypixel/skywars"
|
||||
import { HEADS, ICONS, MODES, PRESTIGES } from "@/data/hypixel/skywars"
|
||||
import { formatNumber } from "@/lib/formatters"
|
||||
import { NonNullStats } from "@/lib/schema/player"
|
||||
import { concatStatsArray, devide, floorLevel } from "../general"
|
||||
|
||||
export function getSkywarsHeads(key: string) {
|
||||
@@ -52,7 +53,6 @@ export function getSkyWarsIcon(icon?: string) {
|
||||
return icons[icon] ?? ICONS.default
|
||||
}
|
||||
|
||||
export type _SkywarsStats = Record<string, number>
|
||||
type Mode =
|
||||
| "normal"
|
||||
| "insane"
|
||||
@@ -69,7 +69,7 @@ export type SkywarsModeStats = {
|
||||
losses: number
|
||||
}
|
||||
|
||||
export function getBestSkywarsMode(stats: _SkywarsStats): Mode | null {
|
||||
export function getBestSkywarsMode(stats: NonNullable<NonNullStats["SkyWars"]>): Mode | null {
|
||||
const { wins: normal } = getSkywarsModeStats("normal", stats, true)
|
||||
const { wins: insane } = getSkywarsModeStats("insane", stats, true)
|
||||
const { wins: teams_normal } = getSkywarsModeStats("teams_normal", stats, true)
|
||||
@@ -100,9 +100,9 @@ export function getBestSkywarsMode(stats: _SkywarsStats): Mode | null {
|
||||
}
|
||||
}
|
||||
|
||||
export function getSkywarsModeStats(mode: Mode, stats: _SkywarsStats, raw: true): SkywarsModeStats
|
||||
export function getSkywarsModeStats(mode: Mode, stats: _SkywarsStats, raw?: false): (string | number)[]
|
||||
export function getSkywarsModeStats(mode: Mode, stats: _SkywarsStats, raw = false) {
|
||||
export function getSkywarsModeStats(mode: Mode, stats: NonNullable<NonNullStats["SkyWars"]>, raw: true): SkywarsModeStats
|
||||
export function getSkywarsModeStats(mode: Mode, stats: NonNullable<NonNullStats["SkyWars"]>, raw?: false): (string | number)[]
|
||||
export function getSkywarsModeStats(mode: Mode, stats: NonNullable<NonNullStats["SkyWars"]>, raw = false) {
|
||||
switch (mode) {
|
||||
case "normal":
|
||||
return skywarsModeStats("solo_normal", stats, raw)
|
||||
@@ -123,7 +123,7 @@ export function getSkywarsModeStats(mode: Mode, stats: _SkywarsStats, raw = fals
|
||||
}
|
||||
}
|
||||
|
||||
function skywarsModeStats(suffix: string, stats: _SkywarsStats, raw = false) {
|
||||
function skywarsModeStats(suffix: Exclude<typeof MODES[number]["id"], "">, stats: NonNullable<NonNullStats["SkyWars"]>, raw = false) {
|
||||
if (raw) {
|
||||
return {
|
||||
kills: stats[`kills_${suffix}`],
|
||||
|
||||
Reference in New Issue
Block a user