diff --git a/src/app/(stats)/player/[ign]/_stats/warlords/client.tsx b/src/app/(stats)/player/[ign]/_stats/warlords/client.tsx new file mode 100644 index 0000000..b3d080a --- /dev/null +++ b/src/app/(stats)/player/[ign]/_stats/warlords/client.tsx @@ -0,0 +1,60 @@ +"use client" + +import { formatNumber } from "@/lib/formatters" +import { getWarlordsWeaponsRepaired } from "@/lib/hypixel/warlords/general" +import { NonNullStats } from "@/lib/schema/player" +import { cn } from "@/lib/utils" +import { useEffect, useState } from "react" +import { Tooltip } from "react-tooltip" + +export function WarlordsWeaponsBar({ stats }: { stats: NonNullable }) { + const [pos, setPos] = useState({ x: 0, y: 0 }) + + useEffect(() => { + const controller = new AbortController() + + window.addEventListener("mousemove", (e) => { + if (!(e.target instanceof HTMLDivElement)) return + if (e.target.dataset.id !== "warlords-weapons-bar") return + + setPos({ x: e.clientX, y: e.clientY - 10 }) + }, { signal: controller.signal }) + + return () => { + controller.abort() + } + }) + + const repaired = getWarlordsWeaponsRepaired(stats) + + return ( + <> +

+ {"Total Weapons Repaired: "} + {formatNumber(stats.repaired)} +

+
+ {repaired.map(({ repaired, num }) => { + const percent = num / stats.repaired + + if (percent === 0) return null + + return ( +
+
+ ) + })} +
+ + + ) +} diff --git a/src/app/(stats)/player/[ign]/_stats/warlords/warlords.tsx b/src/app/(stats)/player/[ign]/_stats/warlords/warlords.tsx index 74579fc..c943d02 100644 --- a/src/app/(stats)/player/[ign]/_stats/warlords/warlords.tsx +++ b/src/app/(stats)/player/[ign]/_stats/warlords/warlords.tsx @@ -4,6 +4,7 @@ import { devide } from "@/lib/hypixel/general" import { getWarlordsLosses, getWarlordsMostPlayedClass } from "@/lib/hypixel/warlords/general" import { NonNullStats } from "@/lib/schema/player" import GeneralStats from "../GeneralStats" +import { WarlordsWeaponsBar } from "./client" import WarlordsGeneralStats from "./stats" export default function WarlordsStats({ stats }: { stats: NonNullStats["Warlords"] }) { @@ -39,6 +40,9 @@ export default function WarlordsStats({ stats }: { stats: NonNullStats["Warlords > + + + ) } diff --git a/src/data/hypixel/warlords.ts b/src/data/hypixel/warlords.ts index d30eec9..65772e2 100644 --- a/src/data/hypixel/warlords.ts +++ b/src/data/hypixel/warlords.ts @@ -14,7 +14,7 @@ export const MODES = [ export const RARITIES = [ { id: "common", name: "Common", color: "green" }, { id: "rare", name: "Rare", color: "blue" }, - { id: "epic", name: "Epic", color: "purple" }, + { id: "epic", name: "Epic", color: "dark-purple" }, { id: "legendary", name: "Legendary", color: "gold" } ] as const export const UPGRADES = [ diff --git a/src/lib/hypixel/warlords/general.ts b/src/lib/hypixel/warlords/general.ts index 8fd39fe..fc91603 100644 --- a/src/lib/hypixel/warlords/general.ts +++ b/src/lib/hypixel/warlords/general.ts @@ -1,6 +1,16 @@ -import { CLASSES } from "@/data/hypixel/warlords" +import { CLASSES, RARITIES } from "@/data/hypixel/warlords" import { NonNullStats } from "@/lib/schema/player" +export function getWarlordsWeaponsRepaired(stats: NonNullable) { + const val: { repaired: typeof RARITIES[number], num: number }[] = [] + + for (const repaired of RARITIES.slice().reverse()) { + val.push({ repaired, num: stats[`repaired_${repaired.id}`] }) + } + + return val +} + export function getWarlordsLosses(stats: NonNullable) { return stats.mage_plays + stats.paladin_plays + stats.shaman_plays + stats.warrior_plays - stats.wins } diff --git a/src/lib/schema/stats/warlords.ts b/src/lib/schema/stats/warlords.ts index 4dc3b3a..b9d1d0a 100644 --- a/src/lib/schema/stats/warlords.ts +++ b/src/lib/schema/stats/warlords.ts @@ -21,5 +21,10 @@ export const warlordsStatsSchema = z.object({ mage_losses: z.number().default(0), paladin_losses: z.number().default(0), shaman_losses: z.number().default(0), - warrior_losses: z.number().default(0) + warrior_losses: z.number().default(0), + repaired: z.number().default(0), + repaired_common: z.number().default(0), + repaired_rare: z.number().default(0), + repaired_epic: z.number().default(0), + repaired_legendary: z.number().default(0) })