All files / components/ui MobileHUDLayout.tsx

22.22% Statements 4/18
0% Branches 0/14
0% Functions 0/5
22.22% Lines 4/18

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 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376                                                                                                                          1x                                                                                                                                                                                                                                                           1x                                                                                                                                                                             1x                                                                                                                                                                                                       1x  
/**
 * MobileHUDLayout Component
 * 
 * Mobile-optimized HUD layout for combat screens
 * Designed for touch-friendly interfaces with strategic element positioning
 * 
 * Features:
 * - Touch targets ≥44x44px (iOS guideline)
 * - Font sizes ≥14px body, ≥16px important text
 * - Safe area inset support
 * - Portrait and landscape mode optimization
 * - Simplified layout for small screens
 * 
 * @module components/ui/MobileHUDLayout
 * @category Mobile UI
 * @korean 모바일HUD레이아웃
 */
 
import { Html } from '@react-three/drei';
import React, { useMemo } from 'react';
import { PlayerState } from '../../systems';
import { KOREAN_COLORS, FONT_FAMILY } from '../../types/constants';
import { useWindowSize } from '../../hooks/useWindowSize';
import { useResponsiveLayout } from '../../hooks/useResponsiveLayout';
import {
  calculateHUDHeight,
  calculateProgressBarSize,
  isValidTouchTarget,
} from '../../utils/responsiveLayout';
 
/**
 * Props for MobileHUDLayout component
 */
export interface MobileHUDLayoutProps {
  /** Player 1 state */
  readonly player1: PlayerState;
  /** Player 2 state */
  readonly player2: PlayerState;
  /** Time remaining in seconds */
  readonly timeRemaining: number;
  /** Current round number */
  readonly currentRound: number;
  /** Maximum rounds */
  readonly maxRounds: number;
  /** Whether game is paused */
  readonly isPaused?: boolean;
  /** Test ID for testing */
  readonly testId?: string;
}
 
/**
 * Mobile health bar component
 * Optimized for touch interaction and visibility
 */
interface MobileHealthBarProps {
  readonly player: PlayerState;
  readonly side: 'left' | 'right';
  readonly layout: ReturnType<typeof useResponsiveLayout>;
  readonly barSize: { width: number; height: number };
}
 
const MobileHealthBar: React.FC<MobileHealthBarProps> = ({
  player,
  side,
  layout,
  barSize,
}) => {
  const healthPercent = (player.health / player.maxHealth) * 100;
  const isLowHealth = healthPercent < 30;
 
  // Validate touch target
  const isValidTouch = isValidTouchTarget(barSize.width, barSize.height);
  const actualHeight = Math.max(barSize.height, 44); // Ensure minimum
 
  return (
    <div
      style={{
        position: 'absolute',
        [side]: layout.spacing.md,
        top: layout.safeArea.top + layout.spacing.sm,
        width: barSize.width,
        display: 'flex',
        flexDirection: 'column',
        gap: layout.spacing.xs,
      }}
      data-testid={`mobile-health-${side}`}
      data-valid-touch={isValidTouch}
    >
      {/* Player Name */}
      <div
        style={{
          fontSize: layout.fontSize.small,
          fontFamily: FONT_FAMILY.KOREAN,
          color: `#${KOREAN_COLORS.TEXT_PRIMARY.toString(16).padStart(6, '0')}`,
          fontWeight: 'bold',
          textShadow: '0 0 4px rgba(0,0,0,0.8)',
        }}
      >
        {player.archetype}
      </div>
 
      {/* Health Bar */}
      <div
        style={{
          position: 'relative',
          width: '100%',
          height: actualHeight,
          backgroundColor: 'rgba(0, 0, 0, 0.7)',
          borderRadius: layout.spacing.xs,
          border: `2px solid #${KOREAN_COLORS.PRIMARY_CYAN.toString(16).padStart(6, '0')}`,
          overflow: 'hidden',
          boxShadow: isLowHealth
            ? `0 0 10px rgba(255, 0, 0, 0.6)`
            : 'none',
        }}
        data-testid={`health-bar-${side}`}
      >
        {/* Health Fill */}
        <div
          style={{
            position: 'absolute',
            top: 0,
            left: 0,
            width: `${healthPercent}%`,
            height: '100%',
            backgroundColor: isLowHealth
              ? `#${KOREAN_COLORS.ACCENT_RED.toString(16).padStart(6, '0')}`
              : `#${KOREAN_COLORS.HEALTH_FULL.toString(16).padStart(6, '0')}`,
            transition: 'width 0.3s ease, background-color 0.3s ease',
          }}
        />
 
        {/* Health Text */}
        <div
          style={{
            position: 'absolute',
            top: '50%',
            left: '50%',
            transform: 'translate(-50%, -50%)',
            fontSize: layout.fontSize.body,
            fontFamily: FONT_FAMILY.KOREAN,
            color: '#ffffff',
            fontWeight: 'bold',
            textShadow: '0 0 4px rgba(0,0,0,0.9)',
            pointerEvents: 'none',
          }}
        >
          {Math.ceil(player.health)} / {player.maxHealth}
        </div>
      </div>
 
      {/* Stamina Bar - Smaller */}
      <div
        style={{
          width: '100%',
          height: Math.max(layout.spacing.lg, 20),
          backgroundColor: 'rgba(0, 0, 0, 0.7)',
          borderRadius: layout.spacing.xs / 2,
          border: `1px solid #${KOREAN_COLORS.PRIMARY_CYAN.toString(16).padStart(6, '0')}`,
          overflow: 'hidden',
        }}
        data-testid={`stamina-bar-${side}`}
      >
        <div
          style={{
            width: `${(player.stamina / player.maxStamina) * 100}%`,
            height: '100%',
            backgroundColor: `#${KOREAN_COLORS.STAMINA_FULL.toString(16).padStart(6, '0')}`,
            transition: 'width 0.2s ease',
          }}
        />
      </div>
    </div>
  );
};
 
/**
 * Mobile timer component
 * Centered at top with large, readable font
 */
interface MobileTimerProps {
  readonly timeRemaining: number;
  readonly currentRound: number;
  readonly maxRounds: number;
  readonly layout: ReturnType<typeof useResponsiveLayout>;
}
 
const MobileTimer: React.FC<MobileTimerProps> = ({
  timeRemaining,
  currentRound,
  maxRounds,
  layout,
}) => {
  const isLowTime = timeRemaining < 10;
 
  return (
    <div
      style={{
        position: 'absolute',
        top: layout.safeArea.top + layout.spacing.sm,
        left: '50%',
        transform: 'translateX(-50%)',
        display: 'flex',
        flexDirection: 'column',
        alignItems: 'center',
        gap: layout.spacing.xs,
      }}
      data-testid="mobile-timer"
    >
      {/* Round Display */}
      <div
        style={{
          fontSize: layout.fontSize.small,
          fontFamily: FONT_FAMILY.KOREAN,
          color: `#${KOREAN_COLORS.ACCENT_GOLD.toString(16).padStart(6, '0')}`,
          fontWeight: 'bold',
          textShadow: '0 0 4px rgba(0,0,0,0.8)',
        }}
      >
        R{currentRound}/{maxRounds}
      </div>
 
      {/* Timer */}
      <div
        style={{
          fontSize: layout.fontSize.hud,
          fontFamily: FONT_FAMILY.KOREAN,
          color: isLowTime
            ? `#${KOREAN_COLORS.ACCENT_RED.toString(16).padStart(6, '0')}`
            : `#${KOREAN_COLORS.TEXT_PRIMARY.toString(16).padStart(6, '0')}`,
          fontWeight: 'bold',
          textShadow: isLowTime
            ? '0 0 8px rgba(255, 0, 0, 0.8)'
            : '0 0 4px rgba(0,0,0,0.8)',
          animation: isLowTime ? 'pulse 1s infinite' : 'none',
        }}
        data-testid="timer-value"
      >
        {Math.ceil(timeRemaining)}s
      </div>
    </div>
  );
};
 
/**
 * MobileHUDLayout Component
 * 
 * Optimized HUD layout for mobile combat gameplay
 * Automatically adjusts for:
 * - iPhone SE (375x667)
 * - iPhone 11/12/13 (414x896)
 * - Portrait and landscape orientations
 * 
 * Design Principles:
 * - Essential information only (health, timer, rounds)
 * - Touch-friendly element sizing (≥44px)
 * - High contrast for outdoor visibility
 * - Minimal screen real estate usage
 * - Safe area aware positioning
 * 
 * @example
 * ```tsx
 * <MobileHUDLayout
 *   player1={player1State}
 *   player2={player2State}
 *   timeRemaining={90}
 *   currentRound={1}
 *   maxRounds={3}
 * />
 * ```
 * 
 * @public
 * @korean 모바일HUD레이아웃
 */
export const MobileHUDLayout: React.FC<MobileHUDLayoutProps> = ({
  player1,
  player2,
  timeRemaining,
  currentRound,
  maxRounds,
  // roundsWon - reserved for future round indicator dots
  isPaused = false,
  testId = 'mobile-hud-layout',
}) => {
  const { width, height } = useWindowSize();
  const layout = useResponsiveLayout(width, height);
 
  // Note: roundsWon parameter is available for future round indicator dots UI
  // Currently, round info is shown in timer component
 
  // Calculate optimal HUD dimensions
  const hudHeight = useMemo(
    () => calculateHUDHeight(width, layout.isLandscape),
    [width, layout.isLandscape]
  );
 
  // Calculate progress bar sizes
  const healthBarSize = useMemo(
    () => calculateProgressBarSize(layout.isMobile, 'health'),
    [layout.isMobile]
  );
 
  return (
    <Html fullscreen>
      <div
        style={{
          position: 'absolute',
          top: 0,
          left: 0,
          width: '100%',
          height: hudHeight,
          pointerEvents: 'none',
        }}
        data-testid={testId}
        data-mobile={layout.isMobile}
        data-landscape={layout.isLandscape}
      >
        {/* Player 1 HUD - Left Side */}
        <MobileHealthBar
          player={player1}
          side="left"
          layout={layout}
          barSize={healthBarSize}
        />
 
        {/* Timer and Round Info - Center */}
        <MobileTimer
          timeRemaining={timeRemaining}
          currentRound={currentRound}
          maxRounds={maxRounds}
          layout={layout}
        />
 
        {/* Player 2 HUD - Right Side */}
        <MobileHealthBar
          player={player2}
          side="right"
          layout={layout}
          barSize={healthBarSize}
        />
 
        {/* Pause Indicator */}
        {isPaused && (
          <div
            style={{
              position: 'absolute',
              top: '50%',
              left: '50%',
              transform: 'translate(-50%, -50%)',
              fontSize: layout.fontSize.hero,
              fontFamily: FONT_FAMILY.KOREAN,
              color: `#${KOREAN_COLORS.ACCENT_RED.toString(16).padStart(6, '0')}`,
              fontWeight: 'bold',
              textShadow: '0 0 10px rgba(0,0,0,0.9)',
              pointerEvents: 'none',
            }}
            data-testid="pause-indicator"
          >
            일시정지 | PAUSED
          </div>
        )}
 
        {/* Global pulse animation */}
        <style>{`
          @keyframes pulse {
            0%, 100% { opacity: 1; }
            50% { opacity: 0.6; }
          }
        `}</style>
      </div>
    </Html>
  );
};
 
MobileHUDLayout.displayName = 'MobileHUDLayout';