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 321 322 323 324 325 326 | 2x 2x 2x 71x 71x 2x 71x 71x 71x 71x 71x 71x 71x 71x 71x | /**
* StanceWheel Component
*
* Circular 8-segment stance selector for mobile touch controls
* Provides visual and tactile stance switching interface
*
* @module components/mobile/StanceWheel
* @category Mobile Controls
* @korean 자세 휠
*/
import { Html } from '@react-three/drei';
import React, { useCallback, useState } from 'react';
import { KOREAN_COLORS } from '../../types/constants';
import { TRIGRAM_STANCES_ORDER } from '../../systems/trigram/types';
import { TrigramStance } from '../../types/common';
import { triggerHaptic } from '../../utils/haptics';
import { getColorRGB } from '../../utils/colorHelpers';
/**
* Props for StanceWheel component
*/
export interface StanceWheelProps {
/** Current stance index (0-7) */
readonly currentStance: number;
/** Callback when stance changes */
readonly onStanceChange: (stanceIndex: number) => void;
/** Whether wheel is expanded */
readonly expanded: boolean;
/** Callback to toggle expansion */
readonly onToggle: () => void;
/** Whether wheel is disabled */
readonly disabled?: boolean;
/** Position from bottom in pixels (default: 20 when collapsed, 80 when expanded) */
readonly bottom?: number;
/** Opacity of wheel (default: 0.8) */
readonly opacity?: number;
}
/**
* Trigram symbols for each stance
*/
const TRIGRAM_SYMBOLS = ['☰', '☱', '☲', '☳', '☴', '☵', '☶', '☷'] as const;
/**
* Korean names for each stance
*/
const STANCE_KOREAN_NAMES = [
'건', // Geon - Heaven
'태', // Tae - Lake
'리', // Li - Fire
'진', // Jin - Thunder
'손', // Son - Wind
'감', // Gam - Water
'간', // Gan - Mountain
'곤', // Gon - Earth
] as const;
/**
* Get color for a specific stance
*/
const getStanceColor = (stance: TrigramStance): number => {
const stanceColors: Record<TrigramStance, number> = {
geon: 0xffd700, // Gold - Heaven
tae: 0x00ffff, // Cyan - Lake
li: 0xff4444, // Red - Fire
jin: 0xffaa00, // Orange - Thunder
son: 0x88ff88, // Light Green - Wind
gam: 0x0088ff, // Blue - Water
gan: 0x8844ff, // Purple - Mountain
gon: 0xaa6644, // Brown - Earth
};
return stanceColors[stance] ?? KOREAN_COLORS.PRIMARY_CYAN;
};
/**
* StanceWheel Component
*
* Circular stance selector with 8 segments for trigram stances
* Features:
* - Expandable/collapsible interface
* - Visual stance indicator when collapsed
* - 8 touch-optimized stance buttons when expanded
* - Korean trigram symbols and names
* - Color-coded by stance element
* - Haptic feedback on selection
* - 50x50px minimum touch targets
*
* Usage in Combat:
* - Tap collapsed indicator to expand wheel
* - Select from 8 trigram stances
* - Current stance highlighted with gold accent
* - Tap current stance to collapse wheel
*
* @example
* ```tsx
* <StanceWheel
* currentStance={player.stance}
* onStanceChange={(index) => handleStanceChange(index)}
* expanded={wheelExpanded}
* onToggle={() => setWheelExpanded(!wheelExpanded)}
* disabled={isPaused}
* />
* ```
*
* @public
* @korean 자세휠
*/
export const StanceWheel: React.FC<StanceWheelProps> = ({
currentStance,
onStanceChange,
expanded,
onToggle,
disabled = false,
bottom,
opacity = 0.8,
}) => {
const [hoveredStance, setHoveredStance] = useState<number | null>(null);
/**
* Handle stance selection (touch or mouse)
*/
const handleStanceSelect = useCallback(
(e: React.TouchEvent | React.MouseEvent, stanceIndex: number) => {
if (disabled) return;
e.preventDefault();
e.stopPropagation();
// Don't allow selecting the same stance
if (stanceIndex === currentStance) {
// Collapse wheel if tapping current stance
onToggle();
triggerHaptic('light');
return;
}
onStanceChange(stanceIndex);
triggerHaptic('medium');
// Auto-collapse after selection (optional)
// onToggle();
},
[disabled, currentStance, onStanceChange, onToggle]
);
/**
* Handle wheel toggle (touch or mouse)
*/
const handleToggle = useCallback(
(e: React.TouchEvent | React.MouseEvent) => {
if (disabled) return;
e.preventDefault();
e.stopPropagation();
onToggle();
triggerHaptic('light');
},
[disabled, onToggle]
);
// Dynamic bottom position
const dynamicBottom = bottom ?? (expanded ? 80 : 20);
// Get RGB values for colors using shared utility
const currentStanceColor = getColorRGB(getStanceColor(TRIGRAM_STANCES_ORDER[currentStance]));
const goldColor = getColorRGB(KOREAN_COLORS.ACCENT_GOLD);
const primaryColor = getColorRGB(KOREAN_COLORS.PRIMARY_CYAN);
Iif (expanded) {
// Expanded: Show full 8-segment wheel
const wheelSize = 200;
const segmentAngle = 360 / 8;
return (
<Html fullscreen>
<div
style={{
position: 'absolute',
bottom: `${dynamicBottom}px`,
left: '50%',
transform: 'translateX(-50%)',
opacity: disabled ? 0.3 : opacity,
pointerEvents: disabled ? 'none' : 'auto',
transition: 'all 0.3s ease',
}}
data-testid="stance-wheel-expanded"
>
<div
style={{
width: `${wheelSize}px`,
height: `${wheelSize}px`,
position: 'relative',
}}
>
{/* Stance buttons arranged in circle */}
{TRIGRAM_STANCES_ORDER.map((stance, index) => {
const angle = index * segmentAngle;
const radian = (angle - 90) * (Math.PI / 180); // -90 to start from top
const x = Math.cos(radian) * 80 + 100;
const y = Math.sin(radian) * 80 + 100;
const isActive = index === currentStance;
const isHovered = index === hoveredStance;
const stanceColor = getColorRGB(getStanceColor(stance));
return (
<button
key={stance}
onTouchStart={(e) => handleStanceSelect(e, index)}
onTouchEnd={(e) => {
e.preventDefault();
e.stopPropagation();
setHoveredStance(null);
}}
onMouseDown={(e) => handleStanceSelect(e, index)}
onMouseEnter={() => setHoveredStance(index)}
onMouseLeave={() => setHoveredStance(null)}
style={{
position: 'absolute',
left: `${x - 25}px`,
top: `${y - 25}px`,
width: '50px',
height: '50px',
borderRadius: '50%',
background: isActive
? `rgba(${goldColor.r}, ${goldColor.g}, ${goldColor.b}, 0.95)`
: `rgba(${stanceColor.r}, ${stanceColor.g}, ${stanceColor.b}, 0.8)`,
border: `3px solid ${isActive ? '#fff' : `rgba(${stanceColor.r}, ${stanceColor.g}, ${stanceColor.b}, 1)`}`,
fontSize: '24px',
color: isActive ? '#000' : '#fff',
fontWeight: 'bold',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
cursor: 'pointer',
userSelect: 'none',
touchAction: 'none',
transition: 'all 0.15s ease',
transform: isActive || isHovered ? 'scale(1.15)' : 'scale(1)',
boxShadow: isActive
? `0 0 25px rgba(${goldColor.r}, ${goldColor.g}, ${goldColor.b}, 0.9)`
: isHovered
? `0 0 15px rgba(${stanceColor.r}, ${stanceColor.g}, ${stanceColor.b}, 0.8)`
: `0 4px 10px rgba(0, 0, 0, 0.5)`,
}}
data-testid={`stance-button-${index}`}
>
<div style={{ fontSize: '20px', lineHeight: 1 }}>{TRIGRAM_SYMBOLS[index]}</div>
<div style={{ fontSize: '8px', marginTop: '2px' }}>{STANCE_KOREAN_NAMES[index]}</div>
</button>
);
})}
{/* Center label */}
<div
style={{
position: 'absolute',
top: '50%',
left: '50%',
transform: 'translate(-50%, -50%)',
fontSize: '12px',
color: `rgba(${primaryColor.r}, ${primaryColor.g}, ${primaryColor.b}, 0.9)`,
textShadow: '0 1px 3px rgba(0, 0, 0, 0.8)',
fontWeight: 'bold',
textAlign: 'center',
pointerEvents: 'none',
}}
>
자세 선택
<br />
<span style={{ fontSize: '10px' }}>Stance</span>
</div>
</div>
</div>
</Html>
);
}
// Collapsed: Show current stance indicator
return (
<Html fullscreen>
<div
style={{
position: 'absolute',
bottom: `${dynamicBottom}px`,
left: '50%',
transform: 'translateX(-50%)',
opacity: disabled ? 0.3 : opacity,
pointerEvents: disabled ? 'none' : 'auto',
transition: 'all 0.3s ease',
}}
data-testid="stance-wheel-collapsed"
>
<button
onTouchStart={handleToggle}
onMouseDown={handleToggle}
style={{
width: '60px',
height: '60px',
borderRadius: '50%',
background: `rgba(${currentStanceColor.r}, ${currentStanceColor.g}, ${currentStanceColor.b}, 0.9)`,
border: `3px solid rgba(${goldColor.r}, ${goldColor.g}, ${goldColor.b}, 0.9)`,
fontSize: '28px',
color: '#fff',
fontWeight: 'bold',
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
cursor: 'pointer',
userSelect: 'none',
touchAction: 'none',
transition: 'all 0.15s ease',
boxShadow: `0 4px 15px rgba(0, 0, 0, 0.6), 0 0 20px rgba(${currentStanceColor.r}, ${currentStanceColor.g}, ${currentStanceColor.b}, 0.6)`,
}}
disabled={disabled}
data-testid="stance-wheel-toggle"
>
<div style={{ fontSize: '24px', lineHeight: 1 }}>{TRIGRAM_SYMBOLS[currentStance]}</div>
<div style={{ fontSize: '10px', marginTop: '2px' }}>{STANCE_KOREAN_NAMES[currentStance]}</div>
</button>
</div>
</Html>
);
};
|