Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | 2x 227x 227x 227x 227x 82x 75x 7x 3x 4x 72x 73x 227x 227x 227x 227x 227x 227x 227x 227x 227x 227x 227x 227x 227x 2x | /**
* ProgressBar - Three.js-compatible progress bar component
*
* Displays health, ki, stamina with Korean theming
*
* @module components/three
*/
import { Html } from "@react-three/drei";
import React, { useMemo } from "react";
import { KOREAN_COLORS, FONT_FAMILY } from "../../types/constants";
import { hexToRgbaString } from "../../utils/colorUtils";
/**
* Progress bar type
*/
export type ProgressBarType = "health" | "ki" | "stamina";
/**
* Props for ProgressBar component
*/
export interface ProgressBarProps {
readonly type: ProgressBarType;
readonly current: number;
readonly max: number;
readonly label?: { korean: string; english: string };
readonly position?: [number, number, number];
readonly width?: number;
readonly height?: number;
readonly showText?: boolean;
readonly animated?: boolean;
readonly testId?: string;
}
/**
* ProgressBar Component
*
* A progress bar component for displaying health, ki, and stamina.
* Uses Korean cyberpunk theming with gradient fills.
*
* @example
* ```tsx
* <ProgressBar
* type="health"
* current={75}
* max={100}
* label={{ korean: "체력", english: "Health" }}
* />
* ```
*/
export const ProgressBar: React.FC<ProgressBarProps> = ({
type,
current,
max,
label,
position = [0, 0, 0],
width = 200,
height = 24,
showText = true,
animated = true,
testId,
}) => {
// Calculate percentage safely
const percentage = useMemo(
() => Math.max(0, Math.min(1, max > 0 ? current / max : 0)),
[current, max]
);
// Get colors based on type and percentage
const colors = useMemo(() => {
switch (type) {
case "health":
if (percentage > 0.6) {
return {
start: KOREAN_COLORS.HEALTH_FULL,
end: KOREAN_COLORS.HEALTH_MEDIUM,
glow: KOREAN_COLORS.POSITIVE_GREEN,
};
} else if (percentage > 0.3) {
return {
start: KOREAN_COLORS.HEALTH_MEDIUM,
end: KOREAN_COLORS.HEALTH_LOW,
glow: KOREAN_COLORS.WARNING_ORANGE,
};
} else {
return {
start: KOREAN_COLORS.HEALTH_LOW,
end: KOREAN_COLORS.HEALTH_CRITICAL,
glow: KOREAN_COLORS.ACCENT_RED,
};
}
case "ki":
return {
start: KOREAN_COLORS.KI_FULL,
end: KOREAN_COLORS.KI_MEDIUM,
glow: KOREAN_COLORS.PRIMARY_CYAN,
};
case "stamina":
return {
start: KOREAN_COLORS.STAMINA_FULL,
end: KOREAN_COLORS.STAMINA_MEDIUM,
glow: KOREAN_COLORS.SECONDARY_YELLOW,
};
default:
return {
start: KOREAN_COLORS.PRIMARY_CYAN,
end: KOREAN_COLORS.ACCENT_BLUE,
glow: KOREAN_COLORS.PRIMARY_CYAN,
};
}
}, [type, percentage]);
// Memoize container styles for performance
const containerStyle = useMemo<React.CSSProperties>(
() => ({
width: `${width}px`,
display: "flex",
flexDirection: "column",
gap: "4px",
}),
[width]
);
// Memoize label styles for performance
const labelStyle = useMemo<React.CSSProperties>(
() => ({
fontFamily: FONT_FAMILY.KOREAN,
fontSize: "12px",
fontWeight: "bold",
color: hexToRgbaString(KOREAN_COLORS.TEXT_PRIMARY),
textShadow: `0 2px 4px ${hexToRgbaString(KOREAN_COLORS.BLACK_SOLID, 0.5)}`,
display: "flex",
justifyContent: "space-between",
alignItems: "center",
}),
[]
);
// Memoize bar container styles for performance
const barContainerStyle = useMemo<React.CSSProperties>(
() => ({
width: "100%",
height: `${height}px`,
background: hexToRgbaString(KOREAN_COLORS.UI_BACKGROUND_DARK, 0.8),
border: `2px solid ${hexToRgbaString(KOREAN_COLORS.UI_BORDER, 0.6)}`,
borderRadius: "4px",
overflow: "hidden",
position: "relative",
}),
[height]
);
// Memoize fill styles for performance
const fillStyle = useMemo<React.CSSProperties>(() => {
return {
width: `${percentage * 100}%`,
height: "100%",
background: `linear-gradient(to right, ${hexToRgbaString(colors.start)}, ${hexToRgbaString(colors.end)})`,
transition: animated ? "width 0.3s ease" : "none",
position: "relative",
boxShadow: animated
? `0 0 10px ${hexToRgbaString(colors.glow, 0.5)}`
: "none",
};
}, [percentage, colors, animated]);
// Memoize shine effect styles for performance
const shineStyle = useMemo<React.CSSProperties>(
() => ({
position: "absolute",
top: "0",
left: "0",
width: "60%",
height: "40%",
background: hexToRgbaString(KOREAN_COLORS.WHITE_SOLID, 0.3),
borderRadius: "4px",
margin: "2px",
}),
[]
);
// Memoize text styles for performance
const textStyle = useMemo<React.CSSProperties>(
() => ({
position: "absolute",
top: "50%",
left: "50%",
transform: "translate(-50%, -50%)",
fontFamily: FONT_FAMILY.KOREAN,
fontSize: "11px",
fontWeight: "bold",
color: hexToRgbaString(KOREAN_COLORS.TEXT_PRIMARY),
textShadow: `
0 1px 2px ${hexToRgbaString(KOREAN_COLORS.BLACK_SOLID, 0.8)},
0 0 4px ${hexToRgbaString(KOREAN_COLORS.BLACK_SOLID, 0.6)}
`,
whiteSpace: "nowrap",
}),
[]
);
return (
<Html position={position} center>
<div
style={containerStyle}
data-testid={testId ?? `progress-bar-${type}`}
data-current={current}
data-max={max}
data-percentage={Math.round(percentage * 100)}
>
{/* Label */}
{label && showText && (
<div style={labelStyle}>
<span>
{label.korean} | {label.english}
</span>
<span>
{Math.ceil(current)} / {max}
</span>
</div>
)}
{/* Bar Container */}
<div style={barContainerStyle}>
{/* Fill */}
<div style={fillStyle}>
{/* Shine effect */}
<div style={shineStyle} />
</div>
{/* Percentage Text Overlay */}
{showText && (
<div style={textStyle}>
{Math.round(percentage * 100)}%
</div>
)}
</div>
</div>
</Html>
);
};
ProgressBar.displayName = "ProgressBar";
|