Updated bedwars progress
This commit is contained in:
@@ -1,8 +1,12 @@
|
|||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
|
import { useEffect, useState } from "react"
|
||||||
|
import { Tooltip } from "react-tooltip"
|
||||||
|
|
||||||
type GenericProgressProps =
|
type GenericProgressProps =
|
||||||
& {
|
& {
|
||||||
percent: number
|
percent: number
|
||||||
|
tooltipId: string
|
||||||
|
tooltipContent: string
|
||||||
}
|
}
|
||||||
& ({
|
& ({
|
||||||
className: string
|
className: string
|
||||||
@@ -12,27 +16,72 @@ type GenericProgressProps =
|
|||||||
rainbow: true
|
rainbow: true
|
||||||
})
|
})
|
||||||
|
|
||||||
export default function GenericProgress({ percent, className, rainbow }: GenericProgressProps) {
|
export default function GenericProgress({ percent, tooltipId, tooltipContent, className, rainbow }: GenericProgressProps) {
|
||||||
|
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 !== tooltipId) return
|
||||||
|
|
||||||
|
setPos({ x: e.clientX, y: e.clientY - 10 })
|
||||||
|
}, { signal: controller.signal })
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
controller.abort()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
if (rainbow) {
|
if (rainbow) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
className="h-5 rounded-l-md"
|
data-tooltip-id={tooltipId}
|
||||||
style={{
|
data-tooltip-content={tooltipContent}
|
||||||
width: `${percent}%`,
|
className="flex flex-1"
|
||||||
background: "repeating-linear-gradient(to right,#f55,#fa0,#ff5,#5f5,#5ff,#f5f,#a0a,#f55 16rem)"
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
|
<div
|
||||||
|
data-id={tooltipId}
|
||||||
|
className="h-5 rounded-l-md"
|
||||||
|
style={{
|
||||||
|
width: `${percent}%`,
|
||||||
|
background: "repeating-linear-gradient(to right,#f55,#fa0,#ff5,#5f5,#5ff,#f5f,#a0a,#f55 16rem)"
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
data-id={tooltipId}
|
||||||
|
className={cn("flex-1 h-5 rounded-r-md bg-background", percent === 0 ? "rounded-l-md" : undefined)}
|
||||||
|
>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className={cn("flex-1 h-5 rounded-r-md bg-background", percent === 0 ? "rounded-l-md" : undefined)}></div>
|
<Tooltip id={tooltipId} position={pos} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className={cn("h-5 rounded-l-md", className)} style={{ width: `${percent}%` }}></div>
|
<div
|
||||||
<div className={cn("flex-1 h-5 rounded-r-md bg-background", percent === 0 ? "rounded-l-md" : undefined)}></div>
|
data-tooltip-id={tooltipId}
|
||||||
|
data-tooltip-content={tooltipContent}
|
||||||
|
className="flex flex-1"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
data-id={tooltipId}
|
||||||
|
className={cn("h-5 rounded-l-md", className)}
|
||||||
|
style={{ width: `${percent}%` }}
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
data-id={tooltipId}
|
||||||
|
className={cn("flex-1 h-5 rounded-r-md bg-background", percent === 0 ? "rounded-l-md" : undefined)}
|
||||||
|
>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<Tooltip id={tooltipId} position={pos} />
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,11 +45,12 @@ export default function BedwarsStats({ stats }: { stats: NonNullStats["Bedwars"]
|
|||||||
const bbl = (stats.beds_broken_bedwars / stats.beds_lost_bedwars).toFixed(2)
|
const bbl = (stats.beds_broken_bedwars / stats.beds_lost_bedwars).toFixed(2)
|
||||||
const level = getBWLevelForExp(stats.Experience)
|
const level = getBWLevelForExp(stats.Experience)
|
||||||
|
|
||||||
const percent = getProgress(
|
const current = getTotalExpForLevel(level)
|
||||||
getTotalExpForLevel(level),
|
const next = getTotalExpForLevel(level + 1)
|
||||||
stats.Experience,
|
const percent = getProgress(current, stats.Experience, next)
|
||||||
getTotalExpForLevel(level + 1)
|
|
||||||
)
|
const xpProgress = stats.Experience - current
|
||||||
|
const ceilingXp = next - current
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card>
|
<Card>
|
||||||
@@ -93,7 +94,7 @@ export default function BedwarsStats({ stats }: { stats: NonNullStats["Bedwars"]
|
|||||||
</div>
|
</div>
|
||||||
<CollapsibleContent>
|
<CollapsibleContent>
|
||||||
<Separator className="my-4" />
|
<Separator className="my-4" />
|
||||||
<BedwarsProgress level={level} percent={percent} />
|
<BedwarsProgress level={level} percent={percent} currentXp={xpProgress} ceilingXp={ceilingXp} />
|
||||||
<BedwarsGeneralStats statsChecked={stats} level={level} percent={percent} bbl={bbl} kd={kd} fkd={fkd} wl={wl} />
|
<BedwarsGeneralStats statsChecked={stats} level={level} percent={percent} bbl={bbl} kd={kd} fkd={fkd} wl={wl} />
|
||||||
<Separator className="my-4" />
|
<Separator className="my-4" />
|
||||||
<BedwarsStatTable stats={stats} />
|
<BedwarsStatTable stats={stats} />
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { formatNumber } from "@/lib/formatters"
|
||||||
import { bedwarsLevelColors, getBedwarsStar, getPrestigeName, getTextColor } from "@/lib/hypixel/bedwars/bedwars"
|
import { bedwarsLevelColors, getBedwarsStar, getPrestigeName, getTextColor } from "@/lib/hypixel/bedwars/bedwars"
|
||||||
import { getBWLevelForExp } from "@/lib/hypixel/bedwars/level"
|
import { getBWLevelForExp } from "@/lib/hypixel/bedwars/level"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
@@ -13,11 +14,16 @@ export function BedwarsLevel({ xp }: { xp: number }) {
|
|||||||
return <Multicolored val={val} color={color} />
|
return <Multicolored val={val} color={color} />
|
||||||
}
|
}
|
||||||
|
|
||||||
export function BedwarsProgress({ level, percent }: { level: number, percent: number }) {
|
export function BedwarsProgress({ level, percent, currentXp, ceilingXp }: { level: number, percent: number, currentXp: number, ceilingXp: number }) {
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center mb-10">
|
<div className="flex items-center mb-10">
|
||||||
<LevelNumber level={level} className="mr-2" />
|
<LevelNumber level={level} className="mr-2" />
|
||||||
<Progress level={level} percent={percent} />
|
<Progress
|
||||||
|
level={level}
|
||||||
|
percent={percent}
|
||||||
|
tooltipId="bedwars-progress"
|
||||||
|
tooltipContent={`${formatNumber(currentXp)}/${formatNumber(ceilingXp)} XP`}
|
||||||
|
/>
|
||||||
<LevelNumber level={level + 1} className="ml-2" />
|
<LevelNumber level={level + 1} className="ml-2" />
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
@@ -48,7 +54,7 @@ export function BedWarsPrestige({ level }: { level: number }) {
|
|||||||
function LevelNumber({ level, className }: { level: number, className?: string }) {
|
function LevelNumber({ level, className }: { level: number, className?: string }) {
|
||||||
if (level >= 1000 && level < 1100) {
|
if (level >= 1000 && level < 1100) {
|
||||||
return (
|
return (
|
||||||
<div
|
<p
|
||||||
className={className}
|
className={className}
|
||||||
style={{
|
style={{
|
||||||
backgroundImage: "linear-gradient(to left,#a0a,#f5f,#5ff,#5f5,#ff5,#fa0,#f55)",
|
backgroundImage: "linear-gradient(to left,#a0a,#f5f,#5ff,#5f5,#ff5,#fa0,#f55)",
|
||||||
@@ -57,17 +63,17 @@ function LevelNumber({ level, className }: { level: number, className?: string }
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{level}
|
{level}
|
||||||
</div>
|
</p>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return <div className={cn(`text-mc-${getTextColor(level)}`, className)}>{level}</div>
|
return <p className={cn(`text-mc-${getTextColor(level)}`, className)}>{level}</p>
|
||||||
}
|
}
|
||||||
|
|
||||||
function Progress({ level, percent }: { level: number, percent: number }) {
|
function Progress({ level, percent, tooltipId, tooltipContent }: { level: number, percent: number, tooltipId: string, tooltipContent: string }) {
|
||||||
if (level >= 1000 && level < 1100) {
|
if (level >= 1000 && level < 1100) {
|
||||||
return <GenericProgress percent={percent} rainbow={true} />
|
return <GenericProgress percent={percent} rainbow={true} tooltipId={tooltipId} tooltipContent={tooltipContent} />
|
||||||
}
|
}
|
||||||
|
|
||||||
return <GenericProgress percent={percent} className={`bg-mc-${getTextColor(level)}`} />
|
return <GenericProgress percent={percent} className={`bg-mc-${getTextColor(level)}`} tooltipId={tooltipId} tooltipContent={tooltipContent} />
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user