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 | 24x 9x 15x 2x 13x 6x 7x 3x 4x 24x 9x 15x 2x 13x 6x 7x 3x 4x 28x 7x 21x 6x 15x 2x 13x 2x 11x 4x 91x 91x 91x 91x 91x 91x 57x 91x 61x 4x 4x 3x 4x 4x 4x 2x 2x 1x 2x 61x 91x 57x 57x 1x 57x 1x 91x 67x 24x 24x 24x 24x 24x 91x 91x 91x | /**
* ComboCounter - Combo counter display component
*
* Displays the current combo count with Korean-English bilingual text.
* Animates on combo increment and shows milestone indicators.
*
* Uses Html overlay from @react-three/drei for rendering within 3D scenes.
*
* @module components/combat/components/ComboCounter
* @category Combat UI
* @korean 콤보카운터
*/
import { Html } from "@react-three/drei";
import React, { useEffect, useMemo, useRef, useState } from "react";
import { FONT_FAMILY, KOREAN_COLORS } from "../../../../../types/constants";
import { hexColorToCSS, hexToRgbaString } from "../../../../../utils/colorUtils";
/**
* Props for the ComboCounter component
*/
export interface ComboCounterProps {
/** Current combo count */
readonly combo: number;
/** Whether to use mobile-optimized sizing */
readonly isMobile?: boolean;
/** Minimum combo to display (default: 2) */
readonly minDisplayCombo?: number;
}
/**
* Get combo tier color based on combo count
*/
function getComboColor(combo: number): string {
if (combo >= 10) {
// Rainbow effect for high combos - use magenta
return hexColorToCSS(KOREAN_COLORS.SECONDARY_MAGENTA);
}
if (combo >= 7) {
// Critical tier - red
return hexColorToCSS(KOREAN_COLORS.ACCENT_RED);
}
if (combo >= 5) {
// High tier - gold
return hexColorToCSS(KOREAN_COLORS.ACCENT_GOLD);
}
if (combo >= 3) {
// Medium tier - cyan
return hexColorToCSS(KOREAN_COLORS.PRIMARY_CYAN);
}
// Low tier - white
return hexColorToCSS(KOREAN_COLORS.TEXT_PRIMARY);
}
/**
* Get glow color based on combo tier
*/
function getGlowColor(combo: number): string {
if (combo >= 10) {
return hexToRgbaString(KOREAN_COLORS.SECONDARY_MAGENTA, 0.8);
}
if (combo >= 7) {
return hexToRgbaString(KOREAN_COLORS.ACCENT_RED, 0.8);
}
if (combo >= 5) {
return hexToRgbaString(KOREAN_COLORS.ACCENT_GOLD, 0.8);
}
if (combo >= 3) {
return hexToRgbaString(KOREAN_COLORS.PRIMARY_CYAN, 0.6);
}
return hexToRgbaString(KOREAN_COLORS.TEXT_PRIMARY, 0.4);
}
/**
* Get combo milestone text
*/
function getComboMilestone(
combo: number
): { korean: string; english: string } | null {
if (combo === 5) {
return { korean: "훌륭합니다!", english: "Great!" };
}
if (combo === 10) {
return { korean: "놀라운 연속 공격!", english: "Amazing!" };
}
if (combo === 15) {
return { korean: "전설적인 공격!", english: "Legendary!" };
}
if (combo === 20) {
return { korean: "신의 일격!", english: "GODLIKE!" };
}
return null;
}
/**
* ComboCounter Component
*
* Displays the current combo count with animations and milestone indicators.
* Only visible when combo >= minDisplayCombo (default: 2).
*
* @example
* ```tsx
* <ComboCounter
* combo={5}
* isMobile={isMobile}
* />
* ```
*/
export const ComboCounter: React.FC<ComboCounterProps> = ({
combo,
isMobile = false,
minDisplayCombo = 2,
}) => {
// Animation state - all values that affect render must be in state
const [scale, setScale] = useState(1);
const [showMilestone, setShowMilestone] = useState(false);
const [prevCombo, setPrevCombo] = useState(combo);
const milestoneTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(
null
);
const scaleTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
// Calculate 3D position - center top of screen
const position3D: [number, number, number] = useMemo(() => {
// Position at top center of scene
return [0, 4.5, 0];
}, []);
// Handle combo changes via useEffect - this is the proper React pattern
useEffect(() => {
if (combo > prevCombo) {
// Scale up on combo increment - defer to avoid cascading renders
setTimeout(() => setScale(1.3), 0);
// Clear previous scale timeout
if (scaleTimeoutRef.current) {
clearTimeout(scaleTimeoutRef.current);
}
scaleTimeoutRef.current = setTimeout(() => {
setScale(1);
}, 150);
// Check for milestone
const milestone = getComboMilestone(combo);
if (milestone) {
setTimeout(() => setShowMilestone(true), 0);
if (milestoneTimeoutRef.current) {
clearTimeout(milestoneTimeoutRef.current);
}
milestoneTimeoutRef.current = setTimeout(() => {
setShowMilestone(false);
}, 1500);
}
}
// Defer prevCombo update to avoid cascading renders
setTimeout(() => setPrevCombo(combo), 0);
}, [combo, prevCombo]);
// Cleanup
useEffect(() => {
return () => {
if (milestoneTimeoutRef.current) {
clearTimeout(milestoneTimeoutRef.current);
}
if (scaleTimeoutRef.current) {
clearTimeout(scaleTimeoutRef.current);
}
};
}, []);
// Don't render if combo is below minimum
if (combo < minDisplayCombo) {
return null;
}
const milestone = getComboMilestone(combo);
const comboColor = getComboColor(combo);
const glowColor = getGlowColor(combo);
// Get background color with alpha for milestone box
const getMilestoneBackground = (comboVal: number): string => {
if (comboVal >= 10) {
return hexToRgbaString(KOREAN_COLORS.SECONDARY_MAGENTA, 0.3);
}
if (comboVal >= 7) {
return hexToRgbaString(KOREAN_COLORS.ACCENT_RED, 0.3);
}
if (comboVal >= 5) {
return hexToRgbaString(KOREAN_COLORS.ACCENT_GOLD, 0.3);
}
if (comboVal >= 3) {
return hexToRgbaString(KOREAN_COLORS.PRIMARY_CYAN, 0.3);
}
return hexToRgbaString(KOREAN_COLORS.TEXT_PRIMARY, 0.3);
};
// Font sizes
const mainFontSize = isMobile ? 32 : 48;
const subFontSize = isMobile ? 16 : 20;
const milestoneFontSize = isMobile ? 20 : 28;
return (
<Html
position={position3D}
center
distanceFactor={10}
style={{ pointerEvents: "none" }}
>
<div
data-testid="combo-counter"
style={{
display: "flex",
flexDirection: "column",
alignItems: "center",
transform: `scale(${scale})`,
transition: "transform 0.15s ease-out",
}}
>
{/* Main combo number */}
<div
style={{
fontSize: `${mainFontSize}px`,
fontWeight: "bold",
fontFamily: FONT_FAMILY.KOREAN,
color: comboColor,
textShadow: `
0 0 15px ${glowColor},
0 0 30px ${glowColor},
3px 3px 6px rgba(0, 0, 0, 0.9)
`,
lineHeight: 1,
}}
>
{combo}
</div>
{/* Korean text */}
<div
style={{
fontSize: `${subFontSize}px`,
fontWeight: "bold",
fontFamily: FONT_FAMILY.KOREAN,
color: comboColor,
textShadow: `0 0 10px ${glowColor}, 2px 2px 4px rgba(0, 0, 0, 0.8)`,
marginTop: "4px",
}}
>
연속 타격!
</div>
{/* English text */}
<div
style={{
fontSize: `${subFontSize - 4}px`,
fontWeight: "bold",
fontFamily: FONT_FAMILY.KOREAN,
color: hexColorToCSS(KOREAN_COLORS.TEXT_SECONDARY),
textShadow: "2px 2px 4px rgba(0, 0, 0, 0.8)",
}}
>
{combo} HIT COMBO!
</div>
{/* Milestone indicator */}
{showMilestone && milestone && (
<div
style={{
marginTop: "8px",
padding: "4px 16px",
background: getMilestoneBackground(combo),
borderRadius: "4px",
border: `2px solid ${comboColor}`,
animation: "pulse 0.5s ease-in-out infinite",
}}
>
<div
style={{
fontSize: `${milestoneFontSize}px`,
fontWeight: "bold",
fontFamily: FONT_FAMILY.KOREAN,
color: comboColor,
textShadow: `0 0 10px ${glowColor}`,
}}
>
{milestone.korean}
</div>
<div
style={{
fontSize: `${milestoneFontSize - 6}px`,
fontWeight: "bold",
fontFamily: FONT_FAMILY.KOREAN,
color: hexColorToCSS(KOREAN_COLORS.TEXT_SECONDARY),
}}
>
{milestone.english}
</div>
</div>
)}
</div>
{/* CSS Animation */}
<style>{`
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.05); }
}
`}</style>
</Html>
);
};
export default ComboCounter;
|