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 | 122x 106x 16x 8x 8x 2x 6x 3x 3x 122x 122x 106x 16x 8x 8x 2x 6x 3x 3x 3x 145x 122x 122x 122x 122x 145x 89x 89x 145x 89x 145x 89x 145x 89x 145x 3x | /**
* SpeedIndicatorHUD Component - Visual indicator for player movement speed
*
* Displays a speed percentage indicator showing the current movement speed
* relative to base speed, taking into account stance modifiers, injuries,
* stamina, and combat state.
*
* NOTE: This component is rendered OUTSIDE the Canvas as part of the HTML overlay.
* It does NOT use Html from drei - it's a standard React component.
*
* @module components/combat/SpeedIndicatorHUD
* @category Combat UI
* @korean 속도표시기
*/
import React, { useMemo } from "react";
import { KOREAN_COLORS, FONT_FAMILY } from "../../../../../types/constants";
export interface SpeedIndicatorHUDProps {
/**
* Final movement speed in m/s
* @korean 최종속도
*/
readonly finalSpeed: number;
/**
* Base movement speed before modifiers in m/s
* @korean 기본속도
*/
readonly baseSpeed: number;
/**
* Player position ('left' or 'right' side of screen)
* @korean 플레이어위치
*/
readonly position: "left" | "right";
/**
* Mobile responsive mode (smaller text)
* @korean 모바일여부
*/
readonly isMobile: boolean;
/**
* Whether to show the indicator (optional, default: true)
* @korean 표시여부
*/
readonly visible?: boolean;
}
/**
* Get color for speed percentage
*
* **Korean**: 속도 색상 (Speed Color)
*
* Color coding:
* - Green: 100%+ (boosted speed)
* - Cyan: 80-99% (good speed)
* - Yellow: 50-79% (reduced speed)
* - Orange: 25-49% (heavily reduced)
* - Red: <25% (critical reduction)
*/
function getSpeedColor(speedPercent: number): string {
let colorValue: number;
if (speedPercent >= 100) {
colorValue = KOREAN_COLORS.POSITIVE_GREEN;
} else if (speedPercent >= 80) {
colorValue = KOREAN_COLORS.PRIMARY_CYAN;
} else if (speedPercent >= 50) {
colorValue = KOREAN_COLORS.WARNING_YELLOW;
} else if (speedPercent >= 25) {
colorValue = KOREAN_COLORS.WARNING_ORANGE;
} else {
colorValue = KOREAN_COLORS.ACCENT_RED;
}
// Convert number to properly formatted hex string with # prefix
return `#${colorValue.toString(16).padStart(6, "0")}`;
}
/**
* Get Korean label for speed range
*/
function getSpeedLabel(speedPercent: number): {
korean: string;
english: string;
} {
if (speedPercent >= 100) {
return { korean: "가속", english: "BOOSTED" };
} else if (speedPercent >= 80) {
return { korean: "양호", english: "GOOD" };
} else if (speedPercent >= 50) {
return { korean: "감소", english: "REDUCED" };
} else if (speedPercent >= 25) {
return { korean: "저하", english: "SLOWED" };
} else {
return { korean: "위급", english: "CRITICAL" };
}
}
/**
* SpeedIndicatorHUD - Movement speed percentage indicator
*
* Displays current movement speed as a percentage of base speed
* with color coding and bilingual labels. Updates dynamically as
* speed modifiers change from stance, injury, stamina, and combat state.
*
* @example
* ```tsx
* <SpeedIndicatorHUD
* finalSpeed={1.8}
* baseSpeed={2.0}
* position="left"
* isMobile={false}
* />
* ```
*
* @public
* @korean 속도표시기
*/
export const SpeedIndicatorHUD: React.FC<SpeedIndicatorHUDProps> = ({
finalSpeed,
baseSpeed,
position,
isMobile,
visible = true,
}) => {
const speedData = useMemo(() => {
// Calculate speed as percentage of base
const speedPercent = baseSpeed > 0 ? (finalSpeed / baseSpeed) * 100 : 100;
const color = getSpeedColor(speedPercent);
const label = getSpeedLabel(speedPercent);
return {
speedPercent: Math.round(speedPercent),
color,
label,
};
}, [finalSpeed, baseSpeed]);
const containerStyle = useMemo(() => {
const isLeft = position === "left";
return {
position: "absolute" as const,
bottom: isMobile ? "120px" : "140px", // Above stamina/health bars
left: isLeft ? (isMobile ? "12px" : "20px") : "auto",
right: isLeft ? "auto" : isMobile ? "12px" : "20px",
display: visible ? "flex" : "none",
flexDirection: "column" as const,
alignItems: "center" as const,
gap: isMobile ? "4px" : "6px",
padding: isMobile ? "8px 12px" : "10px 16px",
backgroundColor: `rgba(0, 0, 0, 0.7)`,
border: `2px solid ${speedData.color}`,
borderRadius: "6px",
boxShadow: `0 0 10px ${speedData.color}`,
pointerEvents: "none" as const,
transition: "border-color 0.3s ease-out, box-shadow 0.3s ease-out",
zIndex: 100, // Above most UI elements
};
}, [position, isMobile, visible, speedData.color]);
const percentStyle = useMemo(
() => ({
fontFamily: FONT_FAMILY.KOREAN,
fontSize: isMobile ? "18px" : "22px",
fontWeight: "bold" as const,
color: speedData.color,
textShadow: `0 0 8px ${speedData.color}`,
lineHeight: 1,
margin: 0,
}),
[isMobile, speedData.color]
);
const labelStyle = useMemo(
() => ({
fontFamily: FONT_FAMILY.KOREAN,
fontSize: isMobile ? "10px" : "12px",
fontWeight: "normal" as const,
color: speedData.color,
opacity: 0.9,
letterSpacing: "0.5px",
lineHeight: 1,
margin: 0,
}),
[isMobile, speedData.color]
);
const koreanLabelStyle = useMemo(
() => ({
fontFamily: FONT_FAMILY.KOREAN,
fontSize: isMobile ? "11px" : "13px",
fontWeight: "600" as const,
color: speedData.color,
opacity: 0.95,
letterSpacing: "0.5px",
lineHeight: 1,
margin: 0,
}),
[isMobile, speedData.color]
);
return (
<div
data-testid={`speed-indicator-${position}`}
style={containerStyle}
aria-label={`${speedData.label.korean} | ${speedData.label.english}: ${speedData.speedPercent}%`}
role="status"
aria-live="polite"
>
{/* Speed percentage */}
<div style={percentStyle}>
{speedData.speedPercent}%
</div>
{/* Korean label */}
<div style={koreanLabelStyle}>
{speedData.label.korean}
</div>
{/* English label */}
<div style={labelStyle}>
{speedData.label.english}
</div>
{/* Speed unit label */}
<div
style={{
...labelStyle,
fontSize: isMobile ? "9px" : "10px",
opacity: 0.7,
marginTop: isMobile ? "2px" : "3px",
}}
>
속도변경 | Speed
</div>
</div>
);
};
SpeedIndicatorHUD.displayName = "SpeedIndicatorHUD";
|