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 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | 5x 71x 71x 5x 71x 71x 5x 142x 71x 142x 71x 142x 142x 71x 142x 71x 142x 71x 2x 2x 142x 142x 142x | /**
* PlayerStateIndicators - Html overlay for player stats
*
* Displays health, stamina, Ki, balance state, and other combat metrics
* as an Html overlay above the 3D player model.
*
* @module components/three/PlayerStateIndicators
* @category 3D Components
* @korean 플레이어상태표시기
*/
import { Html } from "@react-three/drei";
import React, { useMemo } from "react";
import { FONT_FAMILY, KOREAN_COLORS } from "../../types/constants";
import type { PlayerStateIndicatorsProps, BalanceState } from "../../types/player-visual";
import { toHexColor } from "../../utils/colorHelpers";
/**
* Get color for balance state
*
* @param balance - Current balance state
* @returns CSS color string
* @korean 균형색상가져오기
*/
const getBalanceColor = (balance: BalanceState): string => {
switch (balance) {
case "READY":
return "#00cc44"; // Green - ready for combat
case "SHAKEN":
return "#ffcc00"; // Yellow - slightly compromised
case "VULNERABLE":
return "#ff8800"; // Orange - significantly exposed
case "HELPLESS":
return "#cc0000"; // Red - complete vulnerability
default:
return "#00cc44";
}
};
/**
* Get Korean text for balance state
*
* @param balance - Current balance state
* @returns Korean text
* @korean 균형한글가져오기
*/
const getBalanceText = (balance: BalanceState): string => {
switch (balance) {
case "READY":
return "준비완료";
case "SHAKEN":
return "동요상태";
case "VULNERABLE":
return "취약상태";
case "HELPLESS":
return "무력상태";
default:
return "준비완료";
}
};
/**
* PlayerStateIndicators Component
*
* Renders an Html overlay with health bar, stamina bar, Ki indicator,
* balance state, and consciousness level.
*
* @example
* ```tsx
* <PlayerStateIndicators
* health={85}
* maxHealth={100}
* stamina={60}
* ki={40}
* balance="READY"
* consciousness={100}
* isMobile={false}
* />
* ```
*
* @korean 플레이어상태표시기컴포넌트
*/
export const PlayerStateIndicators: React.FC<PlayerStateIndicatorsProps> = ({
health,
maxHealth,
stamina,
ki,
balance,
consciousness,
pain = 0,
bloodLoss = 0,
isMobile,
}) => {
// Calculate percentages
const healthPercent = useMemo(
() => Math.max(0, Math.min(100, (health / maxHealth) * 100)),
[health, maxHealth]
);
const staminaPercent = useMemo(
() => Math.max(0, Math.min(100, stamina)),
[stamina]
);
const kiPercent = useMemo(() => Math.max(0, Math.min(100, ki)), [ki]);
const consciousnessPercent = useMemo(
() => Math.max(0, Math.min(100, consciousness)),
[consciousness]
);
// Responsive sizing
const sizing = useMemo(
() => ({
width: isMobile ? "60px" : "80px",
barHeight: isMobile ? "4px" : "6px",
thinBarHeight: isMobile ? "3px" : "4px",
fontSize: isMobile ? "8px" : "10px",
gap: isMobile ? "2px" : "4px",
}),
[isMobile]
);
// Health bar color based on percentage
const healthColor = useMemo(() => {
if (healthPercent > 50) return "#00ff00"; // Green
Iif (healthPercent > 25) return "#ffff00"; // Yellow
return "#ff0000"; // Red
}, [healthPercent]);
// Balance state color
const balanceColor = useMemo(() => getBalanceColor(balance), [balance]);
const balanceTextKorean = useMemo(() => getBalanceText(balance), [balance]);
return (
<Html
position={[0, 2.5, 0]}
center
distanceFactor={isMobile ? 15 : 10}
occlude={false}
style={{ pointerEvents: "none", userSelect: "none" }}
>
<div
style={{
display: "flex",
flexDirection: "column",
gap: sizing.gap,
minWidth: sizing.width,
fontFamily: FONT_FAMILY.KOREAN,
}}
data-testid="player-state-indicators"
>
{/* Health bar */}
<div
style={{
height: sizing.barHeight,
background: "rgba(0,0,0,0.6)",
borderRadius: "2px",
overflow: "hidden",
border: `1px solid ${toHexColor(KOREAN_COLORS.PRIMARY_CYAN)}`,
}}
data-testid="health-bar"
title={`Health: ${health}/${maxHealth}`}
>
<div
style={{
width: `${healthPercent}%`,
height: "100%",
background: healthColor,
transition: "width 0.3s ease, background-color 0.3s ease",
}}
/>
</div>
{/* Stamina bar */}
<div
style={{
height: sizing.thinBarHeight,
background: "rgba(0,0,0,0.6)",
borderRadius: "2px",
overflow: "hidden",
border: `1px solid ${toHexColor(KOREAN_COLORS.ACCENT_GOLD)}`,
}}
data-testid="stamina-bar"
title={`Stamina: ${stamina}%`}
>
<div
style={{
width: `${staminaPercent}%`,
height: "100%",
background: toHexColor(KOREAN_COLORS.ACCENT_GOLD),
transition: "width 0.3s ease",
}}
/>
</div>
{/* Ki bar */}
<div
style={{
height: sizing.thinBarHeight,
background: "rgba(0,0,0,0.6)",
borderRadius: "2px",
overflow: "hidden",
border: `1px solid ${toHexColor(KOREAN_COLORS.PRIMARY_CYAN)}`,
}}
data-testid="ki-bar"
title={`Ki: ${ki}%`}
>
<div
style={{
width: `${kiPercent}%`,
height: "100%",
background: toHexColor(KOREAN_COLORS.PRIMARY_CYAN),
transition: "width 0.3s ease",
boxShadow:
kiPercent > 80
? `0 0 ${isMobile ? "4px" : "6px"} ${toHexColor(KOREAN_COLORS.PRIMARY_CYAN)}`
: "none",
}}
/>
</div>
{/* Balance state indicator */}
<div
style={{
fontSize: sizing.fontSize,
color: balanceColor,
textAlign: "center",
fontWeight: "bold",
textShadow: "0 0 4px rgba(0,0,0,0.8)",
padding: "2px 4px",
background: "rgba(0,0,0,0.4)",
borderRadius: "2px",
}}
data-testid="balance-indicator"
title={`Balance: ${balance}`}
>
{balanceTextKorean}
</div>
{/* Consciousness indicator (if below 100%) */}
{consciousnessPercent < 100 && (
<div
style={{
height: sizing.thinBarHeight,
background: "rgba(0,0,0,0.6)",
borderRadius: "2px",
overflow: "hidden",
border: `1px solid ${toHexColor(KOREAN_COLORS.CONSCIOUSNESS_PURPLE)}`,
}}
data-testid="consciousness-bar"
title={`Consciousness: ${consciousness}%`}
>
<div
style={{
width: `${consciousnessPercent}%`,
height: "100%",
background: toHexColor(KOREAN_COLORS.CONSCIOUSNESS_PURPLE),
transition: "width 0.3s ease",
}}
/>
</div>
)}
{/* Pain indicator (if above 20%) */}
{pain > 20 && (
<div
style={{
fontSize: sizing.fontSize,
color: toHexColor(KOREAN_COLORS.PAIN_INDICATOR),
textAlign: "center",
fontWeight: "bold",
textShadow: "0 0 4px rgba(0,0,0,0.8)",
}}
data-testid="pain-indicator"
title={`Pain: ${pain}%`}
>
통증 {Math.round(pain)}%
</div>
)}
{/* Blood loss indicator (if above 10%) */}
{bloodLoss && bloodLoss > 10 && (
<div
style={{
fontSize: sizing.fontSize,
color: toHexColor(KOREAN_COLORS.BLOODLOSS_INDICATOR),
textAlign: "center",
fontWeight: "bold",
textShadow: "0 0 4px rgba(0,0,0,0.8)",
}}
data-testid="bloodloss-indicator"
title={`Blood Loss: ${bloodLoss}%`}
>
출혈 {Math.round(bloodLoss)}%
</div>
)}
</div>
</Html>
);
};
export default PlayerStateIndicators;
|