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 | 'use client' import { useMemo, memo } from 'react' import { css } from '@styled/css' import { animated, useSpring, type Interpolation } from '@react-spring/web' import { useTheme } from '@/contexts/ThemeContext' import type { MapData } from '../types' import { getRegionColor } from '../mapColors' /** * Animated SVG path component for smooth color/style transitions */ interface AnimatedRegionProps { id: string path: string fill: string stroke: string strokeWidth: number opacity: number isExcluded: boolean isPreviewAdd: boolean isPreviewRemove: boolean onMouseEnter: () => void onMouseLeave: () => void onClick: (e: React.MouseEvent) => void } const AnimatedRegion = memo(function AnimatedRegion({ id, path, fill, stroke, strokeWidth, opacity, isExcluded, isPreviewAdd, isPreviewRemove, onMouseEnter, onMouseLeave, onClick, }: AnimatedRegionProps) { const springProps = useSpring({ fill, stroke, strokeWidth, opacity, config: { duration: 400 }, }) return ( <animated.path data-region={id} data-excluded={isExcluded ? 'true' : undefined} data-preview-add={isPreviewAdd ? 'true' : undefined} data-preview-remove={isPreviewRemove ? 'true' : undefined} d={path} fill={springProps.fill} stroke={springProps.stroke} strokeWidth={springProps.strokeWidth} vectorEffect="non-scaling-stroke" onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave} onClick={onClick} style={{ cursor: 'pointer', pointerEvents: 'all', opacity: springProps.opacity, touchAction: 'manipulation', }} /> ) }) interface MapSelectorMapProps { /** Map data to display */ mapData: MapData /** ViewBox for the SVG (may be cropped for continent views) */ viewBox: string /** Callback when a region is clicked */ onRegionClick: (regionId: string) => void /** Callback when hover state changes */ onRegionHover: (regionId: string | null) => void /** Currently hovered region ID */ hoveredRegion: string | null /** Regions with sub-maps available (get special styling) */ highlightedRegions?: string[] /** Render only regions whose IDs are in this list (undefined = show all) */ visibleRegions?: string[] /** * Region grouping for hover highlighting. * When hovering a region, all regions in the same group get highlighted. * Map from region ID to group ID. */ regionGroups?: Map<string, string> /** * Currently selected group ID (e.g., selected continent). * Regions in this group get persistent selection styling. */ selectedGroup?: string | null /** * Limit hover highlighting to only these regions. * If undefined, all regions are hoverable. * Use this to disable hover on non-interactive regions. */ hoverableRegions?: string[] /** * Regions that are excluded by region size filtering. * These will be shown dimmed/grayed out. */ excludedRegions?: string[] /** * Regions that would be ADDED to the selection if the user clicks. * Shown with a distinct "preview add" style (e.g., green tint). */ previewAddRegions?: string[] /** * Regions that would be REMOVED from the selection if the user clicks. * Shown with a distinct "preview remove" style (e.g., red/orange tint). */ previewRemoveRegions?: string[] /** * Animated viewBox for smooth zoom transitions. * When provided, uses animated.svg for smooth interpolation. */ animatedViewBox?: Interpolation<number, string> /** * Region ID to visually highlight (e.g., when hovering over region name in popover) */ focusedRegion?: string | null /** * When true, fills the parent container (100% width and height) instead of using fixed aspect ratio. * Used for full-viewport setup screen layout. */ fillContainer?: boolean } export function MapSelectorMap({ mapData, viewBox, onRegionClick, onRegionHover, hoveredRegion, highlightedRegions = [], visibleRegions, regionGroups, selectedGroup, hoverableRegions, excludedRegions = [], previewAddRegions = [], previewRemoveRegions = [], animatedViewBox, focusedRegion, fillContainer = false, }: MapSelectorMapProps) { const { resolvedTheme } = useTheme() const isDark = resolvedTheme === 'dark' // Filter regions if visibleRegions is provided const displayRegions = visibleRegions ? mapData.regions.filter((r) => visibleRegions.includes(r.id)) : mapData.regions // Compute which group is currently hovered (if using groups) const hoveredGroup = useMemo(() => { if (!hoveredRegion || !regionGroups) return null return regionGroups.get(hoveredRegion) ?? null }, [hoveredRegion, regionGroups]) // Check if a region is in the hovered group const isRegionHighlighted = (regionId: string): boolean => { if (!hoveredRegion) return false // If hoverableRegions is specified, only those regions can be highlighted if (hoverableRegions && !hoverableRegions.includes(regionId)) { return false } // If we have groups, check if this region is in the same group as hovered if (regionGroups && hoveredGroup) { const thisGroup = regionGroups.get(regionId) return thisGroup === hoveredGroup } // No groups - just check direct hover return regionId === hoveredRegion } // Check if a region is in the selected group const isRegionSelected = (regionId: string): boolean => { if (!selectedGroup || !regionGroups) return false const thisGroup = regionGroups.get(regionId) return thisGroup === selectedGroup } // Check if a region is excluded by size filtering const isRegionExcluded = (regionId: string): boolean => { return excludedRegions.includes(regionId) } // Check if a region would be added in a preview const isRegionPreviewAdd = (regionId: string): boolean => { return previewAddRegions.includes(regionId) } // Check if a region would be removed in a preview const isRegionPreviewRemove = (regionId: string): boolean => { return previewRemoveRegions.includes(regionId) } // Check if a region is the focused region (from popover hover) const isRegionFocused = (regionId: string): boolean => { return focusedRegion === regionId } // Get fill color for a region const getRegionFill = (regionId: string): string => { const isExcluded = isRegionExcluded(regionId) const isPreviewAdd = isRegionPreviewAdd(regionId) const isPreviewRemove = isRegionPreviewRemove(regionId) const isHovered = isRegionHighlighted(regionId) const isSelected = isRegionSelected(regionId) const isFocused = isRegionFocused(regionId) const hasSubMap = highlightedRegions.includes(regionId) // Focused region (from popover hover) takes highest precedence if (isFocused) { return isDark ? '#7c3aed' : '#a78bfa' // Purple/violet for focus } // Preview states take precedence - show what would happen on click if (isPreviewAdd) { // Region would be ADDED - show with green/teal tint return isDark ? '#065f46' : '#a7f3d0' } if (isPreviewRemove) { // Region would be REMOVED - show with amber/orange tint return isDark ? '#78350f' : '#fde68a' } // Excluded regions are dimmed (but not if preview is showing something else) if (isExcluded) { return isDark ? '#1f2937' : '#e5e7eb' // Gray out excluded regions } // Use the game's color algorithm const baseColor = getRegionColor(regionId, false, isHovered, isDark) // Hover takes precedence if (isHovered) { return baseColor } // Selected regions get a distinct color if (isSelected) { return isDark ? '#065f46' : '#a7f3d0' // Green tint for selection } // If this region has a sub-map, give it a subtle glow effect if (hasSubMap) { // Slightly brighter to indicate drillable return isDark ? '#4a5568' : '#c4b39a' } return baseColor } // Get stroke color for a region const getRegionStroke = (regionId: string): string => { const isExcluded = isRegionExcluded(regionId) const isPreviewAdd = isRegionPreviewAdd(regionId) const isPreviewRemove = isRegionPreviewRemove(regionId) const isHovered = isRegionHighlighted(regionId) const isSelected = isRegionSelected(regionId) const isFocused = isRegionFocused(regionId) const hasSubMap = highlightedRegions.includes(regionId) // Focused region gets prominent border if (isFocused) { return isDark ? '#c4b5fd' : '#7c3aed' // Purple border for focus } // Preview states take precedence if (isPreviewAdd) { return isDark ? '#10b981' : '#059669' // Green border } if (isPreviewRemove) { return isDark ? '#f59e0b' : '#d97706' // Amber border } // Excluded regions get subtle stroke if (isExcluded) { return isDark ? '#374151' : '#d1d5db' } if (isHovered) { return isDark ? '#60a5fa' : '#1d4ed8' } if (isSelected) { return isDark ? '#10b981' : '#059669' // Green border for selection } if (hasSubMap) { // Subtle highlight for drillable regions return isDark ? '#60a5fa40' : '#1d4ed840' } return isDark ? '#374151' : '#9ca3af' } // Get stroke width for a region const getRegionStrokeWidth = (regionId: string): number => { const isPreviewAdd = isRegionPreviewAdd(regionId) const isPreviewRemove = isRegionPreviewRemove(regionId) const isHovered = isRegionHighlighted(regionId) const isSelected = isRegionSelected(regionId) const isFocused = isRegionFocused(regionId) const hasSubMap = highlightedRegions.includes(regionId) if (isFocused) return 3 // Prominent stroke for focused region if (isPreviewAdd || isPreviewRemove) return 1.5 if (isHovered) return 2 if (isSelected) return 1.5 if (hasSubMap) return 1.5 return 0.5 } // Get opacity for a region (preview regions should be fully visible) const getRegionOpacity = (regionId: string): number => { const isExcluded = isRegionExcluded(regionId) const isPreviewAdd = isRegionPreviewAdd(regionId) const isPreviewRemove = isRegionPreviewRemove(regionId) // Preview states override excluded opacity if (isPreviewAdd || isPreviewRemove) return 1 if (isExcluded) return 0.5 return 1 } // Use animated SVG when animatedViewBox is provided for smooth zoom transitions const SvgComponent = animatedViewBox ? animated.svg : 'svg' const svgViewBox = animatedViewBox || viewBox return ( <div data-component="map-selector-map" className={css({ width: '100%', // When fillContainer is true, fill the parent; otherwise use fixed 16:9 aspect ratio ...(fillContainer ? { height: '100%' } : { aspectRatio: '16 / 9' }), bg: isDark ? 'gray.900' : 'gray.50', rounded: fillContainer ? 'none' : 'xl', border: fillContainer ? 'none' : '2px solid', borderColor: isDark ? 'gray.700' : 'gray.200', overflow: 'hidden', position: 'relative', })} > <SvgComponent viewBox={svgViewBox as string} className={css({ position: 'absolute', top: 0, left: 0, width: '100%', height: '100%', cursor: 'crosshair', display: 'block', touchAction: 'manipulation', })} preserveAspectRatio="xMidYMid meet" > {/* Ocean background */} <rect x="-10000" y="-10000" width="30000" height="30000" fill={isDark ? '#111827' : '#e0f2fe'} /> {/* Render each region with smooth animations */} {displayRegions.map((region) => { const isExcluded = excludedRegions.includes(region.id) const isPreviewAdd = previewAddRegions.includes(region.id) const isPreviewRemove = previewRemoveRegions.includes(region.id) return ( <AnimatedRegion key={region.id} id={region.id} path={region.path} fill={getRegionFill(region.id)} stroke={getRegionStroke(region.id)} strokeWidth={getRegionStrokeWidth(region.id)} opacity={getRegionOpacity(region.id)} isExcluded={isExcluded} isPreviewAdd={isPreviewAdd} isPreviewRemove={isPreviewRemove} onMouseEnter={() => onRegionHover(region.id)} onMouseLeave={() => onRegionHover(null)} onClick={(e) => { e.stopPropagation() onRegionClick(region.id) }} /> ) })} </SvgComponent> </div> ) } |