UPdated mode stats types
This commit is contained in:
@@ -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