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 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | 1x 1x 1x 1x 10x 10x 1x 1x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 25x 25x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x | import { Html } from "@react-three/drei";
import { Canvas } from "@react-three/fiber";
import React, {
useCallback,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import { useAudio } from "../../audio/AudioProvider";
import { useWebGLContextLossHandler } from "../../hooks/useWebGLContextLossHandler";
import { useWindowSize } from "../../hooks/useWindowSize";
import { PLAYER_ARCHETYPES_DATA } from "../../systems/types";
import { GameMode, PlayerArchetype } from "../../types/common";
import {
ARCHETYPE_BACKGROUNDS,
FONT_FAMILY,
KOREAN_COLORS,
} from "../../types/constants";
import { hexToRgbaString } from "../../utils/colorUtils";
import { getArchetypeAssets } from "../../utils/playerUtils";
import { BackgroundScene3D } from "../three/BackgroundScene3D";
import { KoreanHeaderHTML } from "../ui/KoreanHeaderHTML";
import { VolumeControl } from "../ui/VolumeControl";
import { ArchetypeDisplayHTML } from "./components/ArchetypeDisplayHTML";
import { EnhancedArchetypeDisplay } from "./components/EnhancedArchetypeDisplay";
import { MenuSectionHTML } from "./components/MenuSectionHTML";
const APP_VERSION = import.meta.env.APP_VERSION;
export interface IntroScreenThreeJSProps {
readonly onMenuSelect: (mode: GameMode, archetype?: PlayerArchetype) => void;
readonly onArchetypeSelect?: (archetype: PlayerArchetype) => void;
readonly selectedArchetype?: PlayerArchetype;
readonly width?: number;
readonly height?: number;
readonly useEnhancedArchetypeDisplay?: boolean; // Use enhanced card display
}
const MENU_ITEMS: { mode: GameMode; korean: string; english: string }[] = [
{ mode: GameMode.VERSUS, korean: "대전", english: "Combat" },
{ mode: GameMode.TRAINING, korean: "훈련", english: "Training" },
{ mode: GameMode.CONTROLS, korean: "조작", english: "Controls" },
{ mode: GameMode.PHILOSOPHY, korean: "철학", english: "Philosophy" },
];
// Texture key mapping for archetypes
const ARCHETYPE_TEXTURE_MAPPING: Record<PlayerArchetype, string> = {
[PlayerArchetype.MUSA]: "musa",
[PlayerArchetype.AMSALJA]: "amsalja",
[PlayerArchetype.HACKER]: "hacker",
[PlayerArchetype.JEONGBO_YOWON]: "jeongbo_yowon",
[PlayerArchetype.JOJIK_POKRYEOKBAE]: "jojik_pokryeokbae",
};
// Helper function to convert PlayerArchetype enum to array index
const getArchetypeIndex = (archetype: PlayerArchetype): number => {
const archetypeKeys = Object.keys(
PLAYER_ARCHETYPES_DATA
) as PlayerArchetype[];
return archetypeKeys.indexOf(archetype);
};
// Helper function to convert array index to PlayerArchetype enum
const getArchetypeFromIndex = (index: number): PlayerArchetype => {
const archetypeKeys = Object.keys(
PLAYER_ARCHETYPES_DATA
) as PlayerArchetype[];
return archetypeKeys[index] ?? PlayerArchetype.MUSA;
};
/**
* Three.js-based IntroScreen Component
*/
export const IntroScreenThreeJS: React.FC<IntroScreenThreeJSProps> = ({
onMenuSelect,
onArchetypeSelect,
selectedArchetype = PlayerArchetype.MUSA,
width: propWidth,
height: propHeight,
useEnhancedArchetypeDisplay = true, // Default to enhanced display
}) => {
const audio = useAudio();
const introMusicStarted = useRef(false);
const [selectedMenuIndex, setSelectedMenuIndex] = useState(0);
// Content is always mounted/visible (no loading gate)
const isMounted = true;
// Handle WebGL context loss and restoration (for 3D background only)
useWebGLContextLossHandler({
onContextLost: () => {
console.warn("⚠️ WebGL context lost in IntroScreen");
},
onContextRestored: () => {
console.log("✓ WebGL context restored in IntroScreen");
},
autoRestore: true,
});
// Add local state for archetype management
const [currentArchetype, setCurrentArchetype] =
useState<PlayerArchetype>(selectedArchetype);
const [selectedArchetypeIndex, setSelectedArchetypeIndex] = useState<number>(
getArchetypeIndex(selectedArchetype)
);
const { width, height } = useWindowSize();
// Use prop dimensions if provided, otherwise use window size
const screenWidth = propWidth ?? width;
const screenHeight = propHeight ?? height;
// Memoize colors for performance
const colors = useMemo(
() => ({
trigramTextShadow: `0 0 10px ${hexToRgbaString(
KOREAN_COLORS.PRIMARY_CYAN,
0.8
)}`,
footerBackground: hexToRgbaString(KOREAN_COLORS.UI_BACKGROUND_DARK, 0.9),
footerBorder: hexToRgbaString(KOREAN_COLORS.ACCENT_GOLD, 0.3),
}),
[]
);
// Create archetype data with texture keys from PLAYER_ARCHETYPES_DATA
const archetypeData = useMemo(() => {
return Object.entries(PLAYER_ARCHETYPES_DATA).map(([key, data]) => {
const archetypeEnum = key as PlayerArchetype;
return {
id: key.toLowerCase(),
korean: data.name.korean,
english: data.name.english,
description: data.description.korean,
color: data.colors.primary,
textureKey: ARCHETYPE_TEXTURE_MAPPING[archetypeEnum],
stats: data.stats,
philosophy: data.philosophy,
specialAbilities: data.specialAbilities, // Include special abilities
};
});
}, []);
// Sync with prop changes
useEffect(() => {
setCurrentArchetype(selectedArchetype);
setSelectedArchetypeIndex(getArchetypeIndex(selectedArchetype));
}, [selectedArchetype]);
// Direct menu selection - MOVED BEFORE useEffect that uses it
const handleMenuItemSelect = useCallback(
(mode: GameMode) => {
onMenuSelect(mode, currentArchetype);
},
[onMenuSelect, currentArchetype]
);
// Handle archetype change by index - MOVED BEFORE useEffect that uses it
const handleArchetypeIndexChange = useCallback(
(index: number) => {
const newArchetype = getArchetypeFromIndex(index);
setSelectedArchetypeIndex(index);
setCurrentArchetype(newArchetype);
onArchetypeSelect?.(newArchetype);
// Check if audio system is ready, not individual methods
if (audio.isAudioReady) {
audio.playSFX("menu_hover");
// Play archetype theme music preview when archetype changes
// Use getArchetypeAssets utility for proper error handling and fallback
const archetypeAssets = getArchetypeAssets(newArchetype);
// Stop intro music and play archetype theme
audio.stopMusic();
audio.playMusic(archetypeAssets.themeId);
}
},
[onArchetypeSelect, audio]
);
// Play intro music after first user interaction
useEffect(() => {
const startMusic = () => {
if (audio.isAudioReady && !introMusicStarted.current) {
introMusicStarted.current = true;
audio.playMusic("intro_theme");
}
};
// Event listeners with { once: true } are automatically removed after triggering
window.addEventListener("keydown", startMusic, { once: true });
window.addEventListener("mousedown", startMusic, { once: true });
window.addEventListener("touchstart", startMusic, { once: true });
return () => {
// Safe cleanup - check if audio is initialized before stopping music
Eif (audio.isInitialized) {
audio.stopMusic();
}
};
}, [audio]);
// Keyboard navigation
useEffect(() => {
const handleKeyDown = (event: KeyboardEvent) => {
// Archetype navigation (handleArchetypeIndexChange already plays menu_hover SFX)
if (event.key === "ArrowLeft") {
const newIndex =
selectedArchetypeIndex === 0
? archetypeData.length - 1
: selectedArchetypeIndex - 1;
handleArchetypeIndexChange(newIndex);
} else if (event.key === "ArrowRight") {
const newIndex = (selectedArchetypeIndex + 1) % archetypeData.length;
handleArchetypeIndexChange(newIndex);
} else {
// Direct game mode shortcuts
switch (event.key.toLowerCase()) {
case "c":
handleMenuItemSelect(GameMode.CONTROLS);
break;
case "p":
handleMenuItemSelect(GameMode.PHILOSOPHY);
break;
case "t":
handleMenuItemSelect(GameMode.TRAINING);
break;
case "v":
handleMenuItemSelect(GameMode.VERSUS);
break;
}
}
};
window.addEventListener("keydown", handleKeyDown);
return () => window.removeEventListener("keydown", handleKeyDown);
}, [
audio,
archetypeData.length,
selectedArchetypeIndex,
handleArchetypeIndexChange,
handleMenuItemSelect,
]);
// Responsive layout calculations with large desktop support
const isMobile = screenWidth < 768;
const isTablet = screenWidth >= 768 && screenWidth < 1024;
const isLargeDesktop = screenWidth >= 1920; // 4K/2K displays
// Optimized logo sizing - larger logo on large desktop, compensated by smaller header
const logoSize = isMobile
? Math.min(screenWidth, screenHeight) * 0.22 // Compact for mobile
: isTablet
? Math.min(screenWidth, screenHeight) * 0.18 // Balanced for tablet
: isLargeDesktop
? Math.min(screenWidth, screenHeight) * 0.12 // Larger for 4K/2K (was 0.09)
: Math.min(screenWidth, screenHeight) * 0.14; // Standard desktop
// Optimized component heights - scale for large displays
const menuHeight = isMobile
? 280
: isTablet
? 320
: isLargeDesktop
? 220
: 320;
const archetypeHeight = isMobile
? 260
: isTablet
? 300
: isLargeDesktop
? 220
: 300;
return (
<div
style={{
width: screenWidth,
height: screenHeight,
position: "relative",
overflow: "hidden",
}}
data-testid="intro-screen"
>
{/* Archetype background image (very subtle, behind 3D scene) */}
<div
style={{
position: "absolute",
top: 0,
left: 0,
width: "100%",
height: "100%",
backgroundImage: `url(${ARCHETYPE_BACKGROUNDS.overview})`,
backgroundSize: "cover",
backgroundPosition: "center",
backgroundRepeat: "no-repeat",
opacity: 0.08,
filter: "blur(4px)",
zIndex: 0,
}}
data-testid="archetype-background"
/>
{/* Volume Control - outside Canvas to maintain AudioProvider context */}
<VolumeControl position="top-right" compact={isMobile} />
{/* Three.js Canvas for 3D background */}
<Canvas
style={{
position: "absolute",
top: 0,
left: 0,
width: "100%",
height: "100%",
zIndex: 1,
}}
gl={{
antialias: true,
alpha: true,
powerPreference: "high-performance",
}}
dpr={[1, 2]}
camera={{ position: [0, 5, 10], fov: 75 }}
onCreated={({ gl }) => {
gl.setClearColor(KOREAN_COLORS.UI_BACKGROUND_DARK, 0.95);
}}
>
{/* 3D Background Scene */}
<BackgroundScene3D theme="intro" />
{/* HTML Overlay for UI - only render when content is ready */}
<Html fullscreen>
<div
style={{
width: "100vw",
height: "100vh",
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "flex-start",
padding: 0,
gap: isMobile ? "8px" : "16px",
pointerEvents: "none",
opacity: isMounted ? 1 : 0,
transition: "opacity 0.2s ease-out",
}}
>
{/* Main Title */}
<div
style={{
marginTop: isMobile
? "15px"
: isTablet
? "20px"
: isLargeDesktop
? "8px"
: "25px",
pointerEvents: "none",
}}
data-testid="main-title-container"
>
<KoreanHeaderHTML
title={{ korean: "흑괘", english: "Black Trigram" }}
subtitle={{
korean: "한국 무술 시뮬레이터",
english: "Korean Martial Arts Simulator",
}}
size={isLargeDesktop ? "medium" : "large"}
alignment="center"
animated={true}
/>
</div>
{/* Logo Section */}
<div
style={{
flex: 0,
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "flex-start",
marginTop: isMobile
? "5px"
: isTablet
? "6px"
: isLargeDesktop
? "3px"
: "8px",
marginBottom: isMobile
? "5px"
: isTablet
? "6px"
: isLargeDesktop
? "3px"
: "8px",
pointerEvents: "none",
}}
data-testid="logo-section"
>
{/* Logo Image */}
<img
src="/assets/visual/logo/black-trigram.png"
alt="Black Trigram Logo"
style={{
width: `${logoSize}px`,
height: `${logoSize}px`,
objectFit: "contain",
filter: "drop-shadow(0 0 20px rgba(0, 255, 255, 0.5))",
}}
data-testid="main-logo"
onError={(e) => {
e.currentTarget.style.display = "none";
}}
/>
{/* Trigram Symbols */}
<div
style={{
fontSize: isMobile
? "18px"
: isTablet
? "20px"
: isLargeDesktop
? "16px"
: "22px",
color: `#${KOREAN_COLORS.PRIMARY_CYAN.toString(16).padStart(
6,
"0"
)}`,
letterSpacing: isMobile
? "6px"
: isTablet
? "8px"
: isLargeDesktop
? "5px"
: "10px",
textAlign: "center",
marginTop: isMobile
? "10px"
: isTablet
? "10px"
: isLargeDesktop
? "5px"
: "12px",
textShadow: colors.trigramTextShadow,
}}
data-testid="trigram-symbols"
>
☰ ☱ ☲ ☳ ☴ ☵ ☶ ☷
</div>
</div>
{/* Main Content Area */}
<div
style={{
width: "100%",
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "flex-start",
gap: isMobile
? "10px"
: isTablet
? "12px"
: isLargeDesktop
? "6px"
: "14px",
paddingLeft: isMobile
? "15px"
: isTablet
? "25px"
: isLargeDesktop
? "20px"
: "30px",
paddingRight: isMobile
? "15px"
: isTablet
? "25px"
: isLargeDesktop
? "20px"
: "30px",
paddingBottom: isMobile
? "8px"
: isLargeDesktop
? "4px"
: "10px",
pointerEvents: "auto",
}}
data-testid="main-content"
>
{/* Menu Section */}
<div
style={{
width: isMobile
? "100%"
: isTablet
? "80%"
: isLargeDesktop
? "55%"
: "70%",
maxWidth: isMobile
? "100%"
: isTablet
? "850px"
: isLargeDesktop
? "1100px"
: "900px",
}}
data-testid="menu-section-container"
>
<MenuSectionHTML
menuItems={MENU_ITEMS}
selectedIndex={selectedMenuIndex}
onModeSelect={handleMenuItemSelect}
onSelectedIndexChange={setSelectedMenuIndex}
onPlaySFX={audio.playSFX}
width={
isMobile
? screenWidth * 0.9
: isTablet
? Math.min(850, screenWidth * 0.8)
: isLargeDesktop
? Math.min(1100, screenWidth * 0.55)
: Math.min(900, screenWidth * 0.7)
}
height={menuHeight}
/>
</div>
{/* Archetype Selection */}
<div
style={{
width: isMobile
? "100%"
: isTablet
? "80%"
: isLargeDesktop
? "55%"
: "70%",
maxWidth: isMobile
? "100%"
: isTablet
? "850px"
: isLargeDesktop
? "1100px"
: "900px",
}}
data-testid="archetype-section-container"
>
{useEnhancedArchetypeDisplay ? (
<EnhancedArchetypeDisplay
archetypes={archetypeData}
selectedIndex={selectedArchetypeIndex}
onArchetypeChange={handleArchetypeIndexChange}
onPlaySFX={audio.playSFX}
width={
isMobile
? screenWidth * 0.9
: isTablet
? Math.min(850, screenWidth * 0.8)
: isLargeDesktop
? Math.min(1100, screenWidth * 0.55)
: Math.min(900, screenWidth * 0.7)
}
height={archetypeHeight}
isMobile={isMobile}
allowDetailedView={!isMobile}
/>
) : (
<ArchetypeDisplayHTML
archetypes={archetypeData}
selectedIndex={selectedArchetypeIndex}
onArchetypeChange={handleArchetypeIndexChange}
onPlaySFX={audio.playSFX}
width={
isMobile
? screenWidth * 0.9
: isTablet
? Math.min(850, screenWidth * 0.8)
: isLargeDesktop
? Math.min(1100, screenWidth * 0.55)
: Math.min(900, screenWidth * 0.7)
}
height={archetypeHeight}
isMobile={isMobile}
/>
)}
</div>
</div>
{/* Footer */}
<div
style={{
width: "100%",
display: "flex",
flexDirection: "column",
alignItems: "center",
justifyContent: "center",
gap: "6px",
paddingBottom: "10px",
background: `linear-gradient(to bottom, rgba(0, 0, 0, 0), ${colors.footerBackground})`,
borderTop: `1px solid ${colors.footerBorder}`,
pointerEvents: "auto",
}}
data-testid="intro-footer"
>
{/* Motto */}
<div
style={{
fontSize: isMobile ? "11px" : "14px",
color: `#${KOREAN_COLORS.ACCENT_CYAN.toString(16).padStart(
6,
"0"
)}`,
fontFamily: FONT_FAMILY.KOREAN,
fontStyle: "italic",
fontWeight: "bold",
textAlign: "center",
}}
data-testid="footer-motto"
>
흑괘의 길을 걸어라 - Walk the Path of the Black Trigram
</div>
{/* GitHub link */}
<div
style={{
fontSize: isMobile ? "9px" : "12px",
color: `#${KOREAN_COLORS.SECONDARY_MAGENTA.toString(
16
).padStart(6, "0")}`,
fontWeight: "bold",
textAlign: "center",
cursor: "pointer",
}}
onClick={() =>
window.open(
"https://github.com/Hack23/blacktrigram",
"_blank"
)
}
data-testid="footer-link"
>
Open Source Korean Martial Arts Game by Hack23
</div>
{/* Version */}
<div
style={{
fontSize: isMobile ? "9px" : "12px",
color: `#${KOREAN_COLORS.SECONDARY_MAGENTA.toString(
16
).padStart(6, "0")}`,
fontWeight: "bold",
textAlign: "center",
cursor: "pointer",
}}
onClick={() =>
window.open(
`https://github.com/Hack23/blacktrigram/releases/tag/v${APP_VERSION}`,
"_blank"
)
}
data-testid="footer-version"
>
Version {APP_VERSION}
</div>
</div>
</div>
</Html>
</Canvas>
</div>
);
};
export default IntroScreenThreeJS;
|