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 | 2x 37x 37x 37x 60x 127x 37x 23x 23x 27x 37x 14x 14x 37x 4x 2x 2x 37x 23x 37x 37x 2x | import React, { useCallback, useMemo, useState } from "react";
import { PlayerArchetype } from "../../../../types/common";
import { FONT_FAMILY, KOREAN_COLORS } from "../../../../types/constants";
import { hexColorToCSS, hexToRgbaString } from "../../../../utils/colorUtils";
import { ArchetypeCardGrid } from "./ArchetypeCardGrid";
import {
ArchetypeDataShape,
ArchetypeDisplayOverlayHtml,
} from "./ArchetypeDisplayOverlayHtml";
export interface EnhancedArchetypeDisplayProps {
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; // For controls/haptics only, use width for layout sizing
readonly allowDetailedView?: boolean; // Allow switching to card grid view
}
/**
* EnhancedArchetypeDisplay - Provides both compact and detailed card view modes
* Can switch between ArchetypeDisplayOverlayHtml (compact) and ArchetypeCardGrid (detailed)
*/
export const EnhancedArchetypeDisplay: React.FC<EnhancedArchetypeDisplayProps> =
React.memo(
({
archetypes,
selectedIndex,
onArchetypeChange,
onPlaySFX,
width = 800,
height = 300,
isMobile = false,
allowDetailedView = true,
}) => {
const [viewMode, setViewMode] = useState<"compact" | "detailed">(
"compact",
);
// Use width for layout sizing decisions
const isSmallScreen = width < 768;
// Convert archetype data to card data format
const cardData = useMemo(() => {
return archetypes.map((archetype) => ({
archetype: Object.values(PlayerArchetype).find(
(key) => key === archetype.id,
) as PlayerArchetype,
id: archetype.id,
korean: archetype.korean,
english: archetype.english,
description: archetype.description,
color: archetype.color,
textureKey: archetype.textureKey,
stats: archetype.stats,
philosophy: archetype.philosophy,
specialAbilities: archetype.specialAbilities ?? [], // Use actual data or empty array
}));
}, [archetypes]);
// Get current archetype
const currentArchetype = useMemo(() => {
const archetype = archetypes[selectedIndex];
return Object.values(PlayerArchetype).find(
(key) => key === archetype.id,
) as PlayerArchetype;
}, [archetypes, selectedIndex]);
// Toggle view mode
const handleToggleView = useCallback(() => {
setViewMode((prev) => (prev === "compact" ? "detailed" : "compact"));
onPlaySFX("menu_hover");
}, [onPlaySFX]);
// Handle archetype change from card grid
const handleArchetypeChangeFromGrid = useCallback(
(archetype: PlayerArchetype) => {
const index = archetypes.findIndex((a) => a.id === archetype);
Eif (index !== -1) {
onArchetypeChange(index);
}
},
[archetypes, onArchetypeChange],
);
// Memoize colors
const colors = useMemo(
() => ({
toggleButton: hexToRgbaString(KOREAN_COLORS.ACCENT_GOLD, 0.9),
toggleText: hexColorToCSS(KOREAN_COLORS.UI_BACKGROUND_DARK),
}),
[],
);
// Adjust height for detailed view
const detailedHeight = Math.max(height * 2, 600);
return (
<div
style={{
width: `${width}px`,
display: "flex",
flexDirection: "column",
gap: isSmallScreen ? "10px" : "16px",
}}
data-testid="enhanced-archetype-display"
>
{/* View toggle button (only show if allowed and not small screen) */}
{allowDetailedView && !isSmallScreen && (
<div
style={{
display: "flex",
justifyContent: "flex-end",
width: "100%",
}}
>
<button
onClick={handleToggleView}
style={{
padding: "8px 16px",
fontSize: "12px",
backgroundColor: colors.toggleButton,
color: colors.toggleText,
border: "none",
borderRadius: "6px",
fontFamily: FONT_FAMILY.KOREAN,
fontWeight: "bold",
cursor: "pointer",
transition: "all 0.2s ease",
}}
onMouseEnter={(e) => {
e.currentTarget.style.transform = "scale(1.05)";
}}
onMouseLeave={(e) => {
e.currentTarget.style.transform = "scale(1)";
}}
data-testid="view-toggle-button"
>
{viewMode === "compact"
? "상세 보기 | Detailed View"
: "간단 보기 | Compact View"}
</button>
</div>
)}
{/* Render appropriate view */}
{viewMode === "compact" ? (
<ArchetypeDisplayOverlayHtml
archetypes={archetypes}
selectedIndex={selectedIndex}
onArchetypeChange={onArchetypeChange}
onPlaySFX={onPlaySFX}
width={width}
height={height}
isMobile={isMobile}
/>
) : (
<ArchetypeCardGrid
archetypes={cardData}
selectedArchetype={currentArchetype}
onArchetypeChange={handleArchetypeChangeFromGrid}
onPlaySFX={onPlaySFX}
width={width}
height={detailedHeight}
isMobile={isMobile}
/>
)}
</div>
);
},
);
EnhancedArchetypeDisplay.displayName = "EnhancedArchetypeDisplay";
export default EnhancedArchetypeDisplay;
|