import React, { useMemo } from 'react'; import type { ForestPatch, MapTheme } from '../../types/mapTypes'; import { RealisticTree } from './RealisticTree'; interface RealisticForestProps { forest: ForestPatch; theme: MapTheme; showLabels: boolean; } export const RealisticForest: React.FC = ({ forest, theme, showLabels, }) => { const isDark = theme.id !== 'parchment'; const pencil = theme.pencilColor; const shade = theme.pencilShade; const { id, name, cx, cy, rx, ry, trees } = forest; const sortedTrees = useMemo(() => { return [...trees].sort((a, b) => a.y - b.y); }, [trees]); const understory = useMemo(() => { const boulders: { x: number; y: number; rx: number; ry: number; angle: number }[] = []; const fallenLogs: { x: number; y: number; length: number; angle: number }[] = []; const fernClusters: { x: number; y: number }[] = []; const seed = cx * 13 + cy * 19; const count = 6; for (let i = 0; i < count; i++) { const angle = (i * 1.8 + seed * 0.1) % (Math.PI * 2); const bx = cx + Math.cos(angle) * (rx * 0.7); const by = cy + Math.sin(angle) * (ry * 0.7); if (i % 2 === 0) { boulders.push({ x: Math.round(bx), y: Math.round(by), rx: 5 + (i % 3) * 2, ry: 3 + (i % 2) * 1.5, angle: (i * 35) % 60 - 30, }); } else { fallenLogs.push({ x: Math.round(bx), y: Math.round(by), length: 12 + (i % 4) * 3, angle: (i * 45) % 90 - 45, }); } fernClusters.push({ x: Math.round(cx + Math.cos(angle + 0.5) * (rx * 0.5)), y: Math.round(cy + Math.sin(angle + 0.5) * (ry * 0.5)), }); } return { boulders, fallenLogs, fernClusters }; }, [cx, cy, rx, ry]); const boundaryPath = useMemo(() => { const points: { x: number; y: number }[] = []; const steps = 16; for (let i = 0; i < steps; i++) { const angle = (i / steps) * Math.PI * 2; const noise = 1 + Math.sin(angle * 4 + cx * 0.05) * 0.08 + Math.cos(angle * 3 + cy * 0.05) * 0.06; const px = cx + Math.cos(angle) * (rx * noise); const py = cy + Math.sin(angle) * (ry * noise); points.push({ x: Math.round(px), y: Math.round(py) }); } return points.map((p, idx) => (idx === 0 ? `M ${p.x},${p.y}` : `L ${p.x},${p.y}`)).join(' ') + ' Z'; }, [cx, cy, rx, ry]); return ( {/* 1. Forest Floor Shading */} {/* 2. Forest Understory */} {understory.boulders.map((b, bIdx) => ( ))} {understory.fallenLogs.map((log, lIdx) => ( ))} {understory.fernClusters.map((fern, fIdx) => ( ))} {/* 3. Deep Y-Sorted Realistic Trees */} {sortedTrees.map((tree, tIdx) => ( ))} {/* 4. Forest Banner Title */} {showLabels && name && ( ❖ {name} ❖ )} ); };