All files / components/screens/intro/components ArchetypeDisplayOverlayHtml.tsx

72.97% Statements 27/37
66.66% Branches 34/51
66.66% Functions 6/9
72.97% Lines 27/37

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 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446                                                                                2x                   25x     25x 25x 25x 25x 25x 25x 25x 25x 25x 25x   25x             25x 1x 1x 1x       25x 25x 25x                                                         25x 25x                                                 25x 25x     25x                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 100x                                                                                                                                           2x      
import React, { useCallback, useMemo } from "react";
import { FALLBACK_ARCHETYPE_IMAGE, FONT_FAMILY, KOREAN_COLORS } from "../../../../types/constants";
import { hexToRgbaString } from "../../../../utils/colorUtils";
import "./MenuSection.css";
 
// Enhanced shape matching PLAYER_ARCHETYPES_DATA entries
export interface ArchetypeDataShape {
  readonly id: string;
  readonly korean: string;
  readonly english: string;
  readonly description: string;
  readonly color: number;
  readonly textureKey: string;
  readonly stats: {
    readonly attackPower: number;
    readonly defense: number;
    readonly speed: number;
    readonly technique: number;
  };
  readonly philosophy: {
    readonly korean: string;
    readonly english: string;
  };
  readonly specialAbilities?: readonly string[]; // Optional special abilities
}
 
export interface ArchetypeDisplayOverlayHtmlProps {
  readonly archetypes: readonly ArchetypeDataShape[];
  readonly selectedIndex: number;
  readonly onArchetypeChange: (index: number) => void;
  readonly onPlaySFX: (sound: string) => void;
  readonly width?: number;
  readonly height?: number;
  readonly isMobile?: boolean;
}
 
/**
 * HTML-based ArchetypeDisplay component for Three.js integration
 */
export const ArchetypeDisplayOverlayHtml: React.FC<ArchetypeDisplayOverlayHtmlProps> =
  React.memo(
    ({
      archetypes,
      selectedIndex,
      onArchetypeChange,
      onPlaySFX,
      width = 800,
      height = 300,
      isMobile = false,
    }) => {
      const selectedArchetype = archetypes[selectedIndex];
 
      // Responsive sizing with large desktop support
      const isLargeContainer = width >= 1100;
      const archImageWidth = isMobile ? 140 : isLargeContainer ? 120 : 180;
      const archImageHeight = isMobile ? 200 : isLargeContainer ? 170 : 260;
      const containerPadding = isMobile ? 20 : isLargeContainer ? 12 : 20;
      const contentGap = isMobile ? 10 : isLargeContainer ? 8 : 16;
      const infoGap = isMobile ? 8 : isLargeContainer ? 6 : 12;
      const titleFontSize = isMobile ? 14 : isLargeContainer ? 14 : 18;
      const philosophyFontSize = isMobile ? 10 : isLargeContainer ? 10 : 12;
      const statLabelFontSize = isMobile ? 9 : isLargeContainer ? 9 : 11;
      const statBarHeight = isMobile ? 10 : isLargeContainer ? 10 : 12;
 
      const handlePrevious = useCallback(() => {
        const newIndex =
          selectedIndex === 0 ? archetypes.length - 1 : selectedIndex - 1;
        onArchetypeChange(newIndex);
        onPlaySFX("menu_hover");
      }, [selectedIndex, archetypes.length, onArchetypeChange, onPlaySFX]);
 
      const handleNext = useCallback(() => {
        const newIndex = (selectedIndex + 1) % archetypes.length;
        onArchetypeChange(newIndex);
        onPlaySFX("menu_hover");
      }, [selectedIndex, archetypes.length, onArchetypeChange, onPlaySFX]);
 
      // Convert real stats to 0-1 scale for visualization
      const combatStats = useMemo(() => {
        const maxStatValue = 100;
        return [
          {
            korean: "공격",
            english: "Attack",
            value: selectedArchetype.stats.attackPower / maxStatValue,
            rawValue: selectedArchetype.stats.attackPower,
          },
          {
            korean: "방어",
            english: "Defense",
            value: selectedArchetype.stats.defense / maxStatValue,
            rawValue: selectedArchetype.stats.defense,
          },
          {
            korean: "속도",
            english: "Speed",
            value: selectedArchetype.stats.speed / maxStatValue,
            rawValue: selectedArchetype.stats.speed,
          },
          {
            korean: "기술",
            english: "Technique",
            value: selectedArchetype.stats.technique / maxStatValue,
            rawValue: selectedArchetype.stats.technique,
          },
        ];
      }, [selectedArchetype.stats]);
 
      // Memoize RGBA color calculations
      const colors = useMemo(
        () => ({
          archetypeColor: `#${selectedArchetype.color
            .toString(16)
            .padStart(6, "0")}`,
          background: hexToRgbaString(KOREAN_COLORS.UI_BACKGROUND_DARK, 0.95),
          border: hexToRgbaString(KOREAN_COLORS.PRIMARY_CYAN, 0.7),
          titleGold: `#${KOREAN_COLORS.ACCENT_GOLD.toString(16).padStart(
            6,
            "0"
          )}`,
          statsBackground: hexToRgbaString(
            KOREAN_COLORS.UI_BACKGROUND_MEDIUM,
            0.9
          ),
          statsBorder: hexToRgbaString(KOREAN_COLORS.PRIMARY_CYAN, 0.5),
          statBarBackground: hexToRgbaString(
            KOREAN_COLORS.UI_BACKGROUND_MEDIUM,
            1
          ),
          statBarFill: hexToRgbaString(selectedArchetype.color, 0.9),
        }),
        [selectedArchetype.color]
      );
 
      // Get archetype image path
      const archetypeImagePath = useMemo(() => {
        return `/assets/visual/archetypes/${selectedArchetype.textureKey}.png`;
      }, [selectedArchetype.textureKey]);
 
      return (
        <div
          style={{
            width: `${width}px`,
            height: `${height}px`,
            display: "flex",
            flexDirection: "row",
            alignItems: "flex-start",
            justifyContent: "flex-start",
            gap: `${contentGap}px`,
            background: colors.background,
            borderRadius: "8px",
            border: `2px solid ${colors.archetypeColor}`,
            padding: `${containerPadding}px`,
            position: "relative",
            overflow: "hidden",
          }}
          data-testid="archetype-display-container"
        >
          {/* Left Side - Character Image and Navigation */}
          <div
            style={{
              width: `${archImageWidth + 40}px`,
              display: "flex",
              flexDirection: "column",
              alignItems: "center",
              justifyContent: "center",
              gap: `${infoGap}px`,
              flexShrink: 0,
            }}
            data-testid="archetype-image-section"
          >
            {/* Character Image */}
            <div
              style={{
                width: `${archImageWidth + 20}px`,
                height: `${archImageHeight + 20}px`,
                display: "flex",
                alignItems: "center",
                justifyContent: "center",
                position: "relative",
                background: `radial-gradient(circle, ${colors.archetypeColor}26, transparent)`,
                borderRadius: "4px",
                border: `2px solid ${colors.archetypeColor}`,
              }}
              data-testid="archetype-image-container"
            >
              <img
                src={archetypeImagePath}
                alt={`${selectedArchetype.korean} - ${selectedArchetype.english}`}
                style={{
                  width: `${archImageWidth}px`,
                  height: `${archImageHeight}px`,
                  objectFit: "contain",
                  cursor: "pointer",
                }}
                onClick={handleNext}
                onKeyDown={(e) => {
                  if (e.key === "Enter" || e.key === " ") {
                    e.preventDefault();
                    handleNext();
                  }
                }}
                tabIndex={0}
                role="button"
                aria-label={`${selectedArchetype.korean} ${selectedArchetype.english} - Click or press Enter to cycle to next archetype`}
                data-testid="archetype-image"
                onError={(e) => {
                  // Fallback if image doesn't load: use Black Trigram logo, prevent infinite loop
                  const target = e.currentTarget as HTMLImageElement;
                  if (!target.src.endsWith(FALLBACK_ARCHETYPE_IMAGE)) {
                    target.src = FALLBACK_ARCHETYPE_IMAGE;
                    target.alt = `${selectedArchetype.korean} (image unavailable)`;
                  }
                }}
              />
            </div>
 
            {/* Navigation Buttons */}
            <div
              style={{
                display: "flex",
                flexDirection: "row",
                gap: "8px",
                width: "100%",
              }}
              data-testid="archetype-navigation"
            >
              <button
                onClick={handlePrevious}
                aria-label="Previous archetype"
                className="archetype-nav-button"
                style={{
                  flex: 1,
                  height: "30px",
                  fontSize: "14px",
                  fontWeight: "bold",
                  color: `#${KOREAN_COLORS.TEXT_PRIMARY.toString(16).padStart(
                    6,
                    "0"
                  )}`,
                  background: colors.statsBackground,
                  border: `1px solid ${hexToRgbaString(
                    KOREAN_COLORS.ACCENT_GOLD,
                    0.7
                  )}`,
                  borderRadius: "4px",
                  cursor: "pointer",
                }}
                data-testid="prev-archetype-button"
              >
                ◀
              </button>
              <button
                onClick={handleNext}
                aria-label="Next archetype"
                className="archetype-nav-button"
                style={{
                  flex: 1,
                  height: "30px",
                  fontSize: "14px",
                  fontWeight: "bold",
                  color: `#${KOREAN_COLORS.TEXT_PRIMARY.toString(16).padStart(
                    6,
                    "0"
                  )}`,
                  background: colors.statsBackground,
                  border: `1px solid ${hexToRgbaString(
                    KOREAN_COLORS.ACCENT_GOLD,
                    0.7
                  )}`,
                  borderRadius: "4px",
                  cursor: "pointer",
                }}
                data-testid="next-archetype-button"
              >
                ▶
              </button>
            </div>
          </div>
 
          {/* Right Side - Archetype Information */}
          <div
            style={{
              flex: 1,
              display: "flex",
              flexDirection: "column",
              alignItems: "flex-start",
              justifyContent: "flex-start",
              gap: `${infoGap}px`,
              minWidth: 0,
              overflow: "hidden",
            }}
            data-testid="archetype-info"
          >
            {/* Header with name and counter */}
            <div
              style={{
                width: "100%",
                display: "flex",
                flexDirection: "row",
                alignItems: "center",
                justifyContent: "space-between",
              }}
            >
              <div
                style={{
                  fontSize: `${titleFontSize}px`,
                  fontWeight: "bold",
                  fontFamily: FONT_FAMILY.KOREAN,
                  color: colors.archetypeColor,
                }}
                data-testid="archetype-title"
              >
                {selectedArchetype.korean} | {selectedArchetype.english}
              </div>
              <div
                style={{
                  fontSize: "12px",
                  fontWeight: "bold",
                  fontFamily: FONT_FAMILY.PRIMARY,
                  color: colors.archetypeColor,
                }}
                data-testid="archetype-counter"
              >
                {selectedIndex + 1} / {archetypes.length}
              </div>
            </div>
 
            {/* Philosophy */}
            <div
              style={{
                fontSize: `${philosophyFontSize}px`,
                fontStyle: "italic",
                fontFamily: FONT_FAMILY.KOREAN,
                color: `#${KOREAN_COLORS.TEXT_SECONDARY.toString(16).padStart(
                  6,
                  "0"
                )}`,
                lineHeight: "1.4",
              }}
              data-testid="archetype-philosophy"
            >
              {selectedArchetype.philosophy.korean} |{" "}
              {selectedArchetype.philosophy.english}
            </div>
 
            {/* Combat Stats */}
            <div
              style={{
                width: "100%",
                display: "flex",
                flexDirection: "column",
                gap: "8px",
              }}
              data-testid="combat-stats"
            >
              <div
                style={{
                  fontSize: isMobile ? "12px" : "14px",
                  fontWeight: "bold",
                  fontFamily: FONT_FAMILY.KOREAN,
                  color: `#${KOREAN_COLORS.ACCENT_GOLD.toString(16).padStart(
                    6,
                    "0"
                  )}`,
                }}
              >
                전투 능력치 | Combat Stats
              </div>
 
              {/* Individual stat bars */}
              {combatStats.map((stat) => (
                <div
                  key={stat.korean}
                  style={{
                    width: "100%",
                    display: "flex",
                    flexDirection: "row",
                    alignItems: "center",
                    gap: "12px",
                  }}
                >
                  {/* Stat label */}
                  <div
                    style={{
                      width: "80px",
                      fontSize: `${statLabelFontSize}px`,
                      fontFamily: FONT_FAMILY.KOREAN,
                      color: `#${KOREAN_COLORS.TEXT_SECONDARY.toString(
                        16
                      ).padStart(6, "0")}`,
                      flexShrink: 0,
                    }}
                  >
                    {stat.korean} | {stat.english}
                  </div>
 
                  {/* Stat bar container */}
                  <div
                    style={{
                      flex: 1,
                      height: `${statBarHeight}px`,
                      background: colors.statBarBackground,
                      borderRadius: "2px",
                      position: "relative",
                      border: `1px solid ${colors.archetypeColor}`,
                    }}
                  >
                    <div
                      style={{
                        width: `${stat.value * 100}%`,
                        height: "100%",
                        background: colors.statBarFill,
                        borderRadius: "2px",
                        transition: "width 0.3s ease",
                      }}
                    />
                  </div>
 
                  {/* Stat value */}
                  <div
                    style={{
                      width: "30px",
                      fontSize: isMobile ? "9px" : "11px",
                      fontWeight: "bold",
                      fontFamily: FONT_FAMILY.PRIMARY,
                      color: colors.archetypeColor,
                      textAlign: "right",
                      flexShrink: 0,
                    }}
                  >
                    {stat.rawValue}
                  </div>
                </div>
              ))}
            </div>
          </div>
        </div>
      );
    }
  );
 
ArchetypeDisplayOverlayHtml.displayName = "ArchetypeDisplayOverlayHtml";
 
export default ArchetypeDisplayOverlayHtml;