All files / components/screens/combat/components/feedback RoundStartAnnouncementOverlayHtml.tsx

100% Statements 35/35
84.61% Branches 11/13
100% Functions 13/13
100% Lines 31/31

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                                                                                                        2x           13x 13x 13x   13x 13x 10x     13x 2x     13x 10x 10x     13x 12x 12x       13x 10x 10x   10x 2x 2x 2x 2x         10x 10x 10x 10x 2x         13x 13x         13x                                                                                                                                                
/**
 * RoundStartAnnouncement Component - Displays "Round X Begin!" announcement
 *
 * Korean: 라운드 시작 발표 (Round Start Announcement)
 *
 * Shows "Round X Begin!" for subsequent rounds (not the first round).
 * Implements Korean cyberpunk aesthetic with bilingual text support.
 *
 * Refactored to use useKoreanTheme hook for consistent styling.
 *
 * @module components/combat/RoundStartAnnouncement
 * @category Combat UI
 */
 
import React, {
  useCallback,
  useEffect,
  useMemo,
  useRef,
  useState,
} from "react";
import { useAudio } from "../../../../../audio/AudioProvider";
import { useKoreanTheme } from "../../../../shared/base/useKoreanTheme";
import { hexColorToCSS } from "../../../../../utils/colorUtils";
 
/**
 * Props for the RoundStartAnnouncement component
 */
export interface RoundStartAnnouncementProps {
  /** Round number (1-based) */
  readonly roundNumber: number;
  /** Duration to display announcement in seconds */
  readonly duration?: number;
  /** Callback when announcement completes */
  readonly onComplete: () => void;
  /** Whether layout should adapt for mobile screens */
  readonly isMobile: boolean;
}
 
/**
 * RoundStartAnnouncement Component
 *
 * Displays "Round X Begin!" announcement with:
 * - Bilingual round number and "Begin!" text
 * - Flash/pulse animation for impact
 * - Auto-dismiss after configured duration
 * - Audio cue for round start
 * - Responsive sizing for mobile/tablet/desktop
 * - Uses useKoreanTheme for consistent styling
 *
 * Korean: 라운드 시작 발표 컴포넌트
 */
export const RoundStartAnnouncement: React.FC<RoundStartAnnouncementProps> = ({
  roundNumber,
  duration = 2,
  onComplete,
  isMobile,
}) => {
  const audio = useAudio();
  const theme = useKoreanTheme({ variant: "primary", size: "xlarge", isMobile });
  const [isVisible, setIsVisible] = useState(false);
 
  const onCompleteRef = useRef(onComplete);
  useEffect(() => {
    onCompleteRef.current = onComplete;
  }, [onComplete]);
 
  const handleComplete = useCallback(() => {
    onCompleteRef.current();
  }, []);
 
  useEffect(() => {
    const timer = setTimeout(() => setIsVisible(true), 50);
    return () => clearTimeout(timer);
  }, []);
 
  useEffect(() => {
    Eif (audio.isAudioReady) {
      audio.playSFX("attack_medium"); // Using placeholder - will be round_start
    }
  }, [audio]);
 
  useEffect(() => {
    let isMounted = true;
    let innerTimer: ReturnType<typeof setTimeout> | null = null;
 
    const outerTimer = setTimeout(() => {
      setIsVisible(false);
      innerTimer = setTimeout(() => {
        Eif (isMounted) {
          handleComplete();
        }
      }, 300); // Wait for fade out
    }, duration * 1000);
 
    return () => {
      isMounted = false;
      clearTimeout(outerTimer);
      if (innerTimer) {
        clearTimeout(innerTimer);
      }
    };
  }, [duration, handleComplete]);
 
  const goldColor = useMemo(() => hexColorToCSS(theme.colors.ACCENT_GOLD), [theme.colors.ACCENT_GOLD]);
  const darkBg = useMemo(
    () => hexColorToCSS(theme.colors.UI_BACKGROUND_DARK),
    [theme.colors.UI_BACKGROUND_DARK]
  );
 
  return (
    <>
      <div
        data-testid="round-start-announcement"
        role="alert"
        aria-live="assertive"
        aria-label={`Round ${roundNumber} starting`}
        style={{
          position: "fixed",
          top: 0,
          left: 0,
          width: "100%",
          height: "100%",
          display: "flex",
          alignItems: "center",
          justifyContent: "center",
          backgroundColor: `${darkBg}88`,
          zIndex: 900,
          opacity: isVisible ? 1 : 0,
          transition: "opacity 0.3s ease-in-out",
          pointerEvents: "none",
        }}
      >
        <div
          style={{
            fontSize: isMobile ? "56px" : "96px",
            fontWeight: "bold",
            color: goldColor,
            fontFamily: theme.fontFamily.KOREAN,
            textShadow: `0 0 40px ${goldColor}`,
            animation: "roundStartFlash 0.5s ease-out",
            textAlign: "center",
            userSelect: "none",
          }}
          data-testid="round-start-text"
        >
          라운드 {roundNumber} 시작!
          <br />
          <span
            style={{
              fontSize: isMobile ? "40px" : "64px",
            }}
          >
            Round {roundNumber} Begin!
          </span>
        </div>
      </div>
 
      {/* CSS Animation */}
      <style>
        {`
          @keyframes roundStartFlash {
            0% {
              opacity: 0;
              transform: scale(1.5);
            }
            30% {
              opacity: 1;
              transform: scale(1.2);
            }
            100% {
              opacity: 1;
              transform: scale(1);
            }
          }
        `}
      </style>
    </>
  );
};
 
export default RoundStartAnnouncement;