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 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | 3x 158x 158x 158x 158x 158x 158x 67x 67x 67x 158x 68x 68x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 20x 158x 68x 158x 68x 158x 68x 158x 68x 158x 68x 158x 67x 158x 20x 158x 158x 158x 158x | /**
* StanceChangeIndicator - Visual feedback for stance changes
* Displays Korean and English stance names with trigram symbols
*
* @module components/shared/three/indicators/StanceChangeIndicator
* @category Combat UI
* @korean 자세변경표시기
*/
import { Html } from "@react-three/drei";
import React, { useEffect, useState, useMemo, useRef } from "react";
import { FONT_FAMILY, KOREAN_COLORS } from "../../../../types/constants";
import { hexToRgbaString } from "../../../../utils/colorUtils";
import { TRIGRAM_STANCES_ORDER } from "../../../../systems/trigram/types";
import { TrigramStance } from "../../../../types/common";
import {
getTrigramElementColor,
getTrigramKoreanName,
getTrigramEnglishName,
getTrigramSymbol
} from "./ElementalColorSystem";
import { triggerStanceChangeHaptic } from "./HapticFeedback";
/**
* Props for StanceChangeIndicator component
*/
export interface StanceChangeIndicatorProps {
/** Current stance index (0-7) */
readonly currentStance: number;
/** Previous stance index (0-7) for change detection */
readonly previousStance: number;
/** Mobile layout flag */
readonly isMobile?: boolean;
/** Display duration in milliseconds (default: 1000ms) */
readonly duration?: number;
/** Show transition progress bar (default: true) */
readonly showProgress?: boolean;
/** Transition duration in milliseconds for progress bar (default: 600ms) */
readonly transitionDuration?: number;
}
/**
* StanceChangeIndicator Component
*
* Displays a temporary overlay showing the current trigram stance
* with Korean name, English name, and trigram symbol.
*
* Features:
* - Fade in/out animation
* - Korean cyberpunk styling
* - Responsive mobile layout
* - Trigram symbol display
* - Glow effect for visual emphasis
*
* @example
* ```tsx
* <StanceChangeIndicator
* currentStance={player.stance}
* previousStance={previousStance}
* isMobile={isMobile}
* />
* ```
*
* @public
* @korean 자세변경표시기
*/
export const StanceChangeIndicator: React.FC<StanceChangeIndicatorProps> = ({
currentStance,
previousStance,
isMobile = false,
duration = 1000,
showProgress = true,
transitionDuration = 600,
}) => {
const [showIndicator, setShowIndicator] = useState(false);
const [progress, setProgress] = useState(0);
const isMountedRef = useRef(true);
const startTimeRef = useRef<number>(0);
const animationFrameRef = useRef<number | undefined>(undefined);
// Track component mount state
useEffect(() => {
isMountedRef.current = true;
return () => {
isMountedRef.current = false;
};
}, []);
// Show/hide indicator based on stance change
// This effect intentionally sets state synchronously for immediate visual feedback
useEffect(() => {
// Cancel any existing animation frame first
Iif (animationFrameRef.current !== undefined) {
cancelAnimationFrame(animationFrameRef.current);
animationFrameRef.current = undefined;
}
if (currentStance !== previousStance) {
setShowIndicator(true);
setProgress(0);
startTimeRef.current = 0;
// Trigger haptic feedback for stance change
triggerStanceChangeHaptic();
// Animation loop for progress bar
Eif (showProgress) {
const animate = (timestamp: number) => {
if (!isMountedRef.current) return;
// Initialize start time on first frame
if (startTimeRef.current === 0) {
startTimeRef.current = timestamp;
}
const elapsed = timestamp - startTimeRef.current;
const newProgress = Math.min((elapsed / transitionDuration) * 100, 100);
setProgress(newProgress);
if (newProgress < 100) {
animationFrameRef.current = requestAnimationFrame(animate);
}
};
animationFrameRef.current = requestAnimationFrame(animate);
}
const timer = setTimeout(() => {
if (isMountedRef.current) {
setShowIndicator(false);
}
}, duration);
return () => {
clearTimeout(timer);
Eif (animationFrameRef.current) {
cancelAnimationFrame(animationFrameRef.current);
}
};
}
}, [currentStance, previousStance, duration, showProgress, transitionDuration]);
// Get trigram stance from index
const stance = useMemo(
() => TRIGRAM_STANCES_ORDER[currentStance] ?? TrigramStance.GEON,
[currentStance]
);
// Get elemental color for stance
const elementalColor = useMemo(
() => getTrigramElementColor(stance),
[stance]
);
// Get trigram names using elemental color system
const koreanName = useMemo(
() => getTrigramKoreanName(stance),
[stance]
);
const englishName = useMemo(
() => getTrigramEnglishName(stance),
[stance]
);
const trigramSymbol = useMemo(
() => getTrigramSymbol(stance),
[stance]
);
// Memoize animation styles to prevent redefinition on every render
const animationStyles = useMemo(() => (
<style>
{`
@keyframes fadeInOut {
0% {
opacity: 0;
transform: translateY(-20px);
}
10% {
opacity: 1;
transform: translateY(0);
}
90% {
opacity: 1;
transform: translateY(0);
}
100% {
opacity: 0;
transform: translateY(-10px);
}
}
`}
</style>
), []);
if (!showIndicator) return null;
const fontSize = isMobile ? 24 : 36;
const subFontSize = isMobile ? 14 : 18;
const top = isMobile ? "30%" : "20%";
// Use elemental color system
const primaryColorHex = hexToRgbaString(elementalColor, 1);
return (
<Html fullscreen>
<div
data-testid="stance-change-indicator"
role="status"
aria-live="polite"
aria-label={`Stance changed to ${englishName}`}
style={{
position: "absolute",
top,
left: "50%",
transform: "translateX(-50%)",
textAlign: "center",
animation: "fadeInOut 1s",
pointerEvents: "none",
zIndex: 1000,
}}
>
{/* Main stance display */}
<div
style={{
fontSize: `${fontSize}px`,
color: primaryColorHex,
fontFamily: FONT_FAMILY.KOREAN,
fontWeight: "bold",
textShadow: `0 0 20px ${hexToRgbaString(elementalColor, 0.8)},
0 0 40px ${hexToRgbaString(elementalColor, 0.5)}`,
marginBottom: "8px",
}}
>
{koreanName} {trigramSymbol}
</div>
{/* English name */}
<div
style={{
fontSize: `${subFontSize}px`,
color: hexToRgbaString(KOREAN_COLORS.ACCENT_GOLD, 1),
fontFamily: FONT_FAMILY.KOREAN,
textShadow: `0 0 10px ${hexToRgbaString(KOREAN_COLORS.ACCENT_GOLD, 0.6)}`,
marginBottom: showProgress ? "12px" : "0",
}}
>
{englishName}
</div>
{/* Transition progress bar (600ms) */}
{showProgress && (
<div
data-testid="stance-transition-progress"
style={{
width: "200px",
margin: "0 auto",
padding: "8px 0",
}}
>
{/* Progress label */}
<div
style={{
fontSize: "11px",
color: "rgba(255, 255, 255, 0.7)",
fontFamily: FONT_FAMILY.KOREAN,
marginBottom: "4px",
letterSpacing: "1px",
}}
>
팔괘전환 | Transition
</div>
{/* Progress bar container */}
<div
style={{
width: "100%",
height: "6px",
backgroundColor: "rgba(0, 0, 0, 0.6)",
borderRadius: "3px",
overflow: "hidden",
border: `1px solid ${hexToRgbaString(elementalColor, 0.3)}`,
}}
>
{/* Progress bar fill */}
<div
style={{
width: `${progress}%`,
height: "100%",
backgroundColor: primaryColorHex,
transition: "width 0.05s linear",
boxShadow: `0 0 8px ${primaryColorHex}`,
}}
/>
</div>
{/* Time remaining */}
<div
style={{
fontSize: "10px",
color: "rgba(255, 255, 255, 0.5)",
fontFamily: FONT_FAMILY.KOREAN,
marginTop: "4px",
}}
>
{Math.max(0, Math.ceil(transitionDuration * (1 - progress / 100)))}ms
</div>
</div>
)}
{/* CSS Animation - Memoized to prevent redefinition */}
{animationStyles}
</div>
</Html>
);
};
|