algospaced-dsa / algospaced-ui /src /components /map /RealisticRiver.tsx
iamfebin's picture
feat: FSRS card manager, fantasy cartography art polish, and map progression effects
f0175ec
Raw History Blame Contribute Delete
13.3 kB
import React, { useMemo } from 'react';
import type { RiverPath, MapTheme } from '../../types/mapTypes';
import { RealisticTree } from './RealisticTree';
interface RealisticRiverProps {
river: RiverPath;
theme: MapTheme;
showLabels: boolean;
}
export const RealisticRiver: React.FC<RealisticRiverProps> = ({
river,
theme,
showLabels,
}) => {
const isDark = theme.id !== 'parchment';
const pencil = theme.pencilColor;
const shade = theme.pencilShade;
// Muted antique verdigris-sepia water wash instead of bright digital blue
const waterFill = isDark ? '#1e2b2e' : '#b8c5be';
const foamColor = isDark ? '#d8c8b0' : '#f2e6ce';
const riverConfig = useMemo(() => {
if (river.id === 'river-elden') {
return {
// Tapers to a pointed mountain spring at (1348, 365) inside Dragon's Eye Tarn
riverPoly: `M 1348,365
C 1322,410 1274,465 1222,535
C 1152,635 1032,695 972,815
C 910,935 942,1055 892,1175
C 850,1275 770,1355 698,1480
L 668,1480
C 745,1355 825,1275 865,1175
C 915,1055 885,935 948,815
C 1008,695 1132,635 1205,535
C 1258,465 1314,410 1348,365
Z`,
leftBank:
'M 1348,365 C 1314,410 1258,465 1205,535 C 1132,635 1008,695 948,815 C 885,935 915,1055 865,1175 C 825,1275 745,1355 668,1480',
rightBank:
'M 1348,365 C 1322,410 1274,465 1222,535 C 1152,635 1032,695 972,815 C 910,935 942,1055 892,1175 C 850,1275 770,1355 698,1480',
labelPos: { x: 1035, y: 980, rot: -55 },
islands: [
{ cx: 958, cy: 960, rx: 13, ry: 6, angle: -45, name: 'Elden Ait' },
{ cx: 770, cy: 1330, rx: 16, ry: 7, angle: -50, name: 'Otter Shoal' },
],
waterfall: {
x: 1214,
y: 538,
width: 24,
height: 20,
angle: -38,
name: 'The Elden Cascades',
},
rapids: [
{ x: 1140, y: 660, angle: -40 },
{ x: 920, y: 1020, angle: 60 },
],
sandbars: [
{ cx: 995, cy: 750, rx: 11, ry: 4.5, angle: 30 },
{ cx: 900, cy: 1110, rx: 13, ry: 5, angle: -25 },
],
bridges: river.hasBridges || [
{ x: 945, y: 855, angle: -35, type: 'stone_arch', name: 'Highbridge' },
{ x: 890, y: 1160, angle: 25, type: 'timber_trestle', name: 'Lower Toll Bridge' },
],
};
} else if (river.id === 'river-silver') {
return {
// Tapers from Mistwood Tarn (585, 395) into River Elden at (958, 820)
riverPoly: `M 585,395
C 645,478 730,545 782,656
C 832,756 912,806 962,816
L 955,826
C 904,816 824,766 774,664
C 724,554 642,484 585,395
Z`,
leftBank:
'M 585,395 C 642,484 724,554 774,664 C 824,766 904,816 955,826',
rightBank:
'M 585,395 C 645,478 730,545 782,656 C 832,756 912,806 962,816',
labelPos: { x: 740, y: 710, rot: 35 },
islands: [{ cx: 710, cy: 535, rx: 9, ry: 4.5, angle: 35, name: 'Willow Islet' }],
waterfall: {
x: 625,
y: 452,
width: 18,
height: 15,
angle: 45,
name: 'Silver Falls',
},
rapids: [{ x: 810, y: 710, angle: 50 }],
sandbars: [{ cx: 755, cy: 610, rx: 8, ry: 3.5, angle: 40 }],
bridges: river.hasBridges || [
{ x: 740, y: 620, angle: 45, type: 'stone_arch', name: 'Silver Arch' },
],
};
} else {
// Eastern River: Now tapers to a narrow spring at (2125, 420) and winds in organic S-curves!
return {
riverPoly: `M 2125,420
C 2065,500 2095,610 2025,720
C 1955,830 2015,960 1915,1080
C 1815,1200 1755,1340 1668,1500
L 1638,1500
C 1730,1340 1792,1200 1895,1080
C 1995,960 1938,830 2012,720
C 2082,610 2058,500 2125,420
Z`,
leftBank:
'M 2125,420 C 2058,500 2082,610 2012,720 C 1938,830 1995,960 1895,1080 C 1792,1200 1730,1340 1638,1500',
rightBank:
'M 2125,420 C 2065,500 2095,610 2025,720 C 1955,830 2015,960 1915,1080 C 1815,1200 1755,1340 1668,1500',
labelPos: { x: 1935, y: 1020, rot: -52 },
islands: [{ cx: 1850, cy: 1155, rx: 11, ry: 5, angle: -52, name: 'Crag Islet' }],
waterfall: {
x: 2048,
y: 660,
width: 20,
height: 18,
angle: -35,
name: 'The Great Cataract',
},
rapids: [{ x: 1975, y: 860, angle: -55 }],
sandbars: [{ cx: 1945, cy: 990, rx: 10, ry: 4.5, angle: -50 }],
bridges: river.hasBridges || [
{ x: 1982, y: 785, angle: -28, type: 'stone_arch', name: 'Highland Span' },
],
};
}
}, [river.id, river.hasBridges]);
const sandbarFill = isDark ? '#3d3425' : '#e6dcbf';
const islandVegetation = isDark ? '#263422' : '#d2d8ba';
return (
<g id={`realistic-${river.id}`} className="realistic-river-group select-none">
{/* 1. Main Water Body Tapered Ribbon */}
<path d={riverConfig.riverPoly} fill={waterFill} opacity={isDark ? 0.75 : 0.65} />
{/* 2. Outer Riverbank Double Contour */}
<path
d={riverConfig.leftBank}
fill="none"
stroke={pencil}
strokeWidth="1.7"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d={riverConfig.rightBank}
fill="none"
stroke={pencil}
strokeWidth="1.7"
strokeLinecap="round"
strokeLinejoin="round"
/>
{/* Parallel Engraved Shoreline Waterlining */}
<path
d={riverConfig.leftBank}
fill="none"
stroke={shade}
strokeWidth="0.7"
opacity={0.6}
transform="translate(2, 1)"
/>
<path
d={riverConfig.rightBank}
fill="none"
stroke={shade}
strokeWidth="0.7"
opacity={0.6}
transform="translate(-2, -1)"
/>
{/* 3. Internal River Flow Streamlines */}
<path
d={riverConfig.leftBank}
fill="none"
stroke={shade}
strokeWidth="0.9"
strokeDasharray="18 28 10 34"
strokeLinecap="round"
opacity={0.55}
transform="translate(5, 2)"
/>
{/* 4. Natural Sandbars & Gravel Shoals */}
{riverConfig.sandbars.map((sb, sbIdx) => (
<g key={sbIdx} transform={`translate(${sb.cx}, ${sb.cy}) rotate(${sb.angle})`}>
<ellipse
cx="0"
cy="0"
rx={sb.rx}
ry={sb.ry}
fill={sandbarFill}
stroke={pencil}
strokeWidth="1"
/>
<circle cx="-3" cy="-1" r="0.6" fill={pencil} />
<circle cx="2" cy="1" r="0.7" fill={pencil} />
</g>
))}
{/* 5. River Rapids */}
{riverConfig.rapids.map((rapid, rIdx) => (
<g key={rIdx} transform={`translate(${rapid.x}, ${rapid.y}) rotate(${rapid.angle})`}>
<path
d="M -10,-5 Q -5,-7 0,-5 Q 5,-3 10,-5 M -8,0 Q -3,-2 2,0 Q 7,2 9,0"
fill="none"
stroke={pencil}
strokeWidth="1.1"
strokeLinecap="round"
opacity={0.7}
/>
<circle
cx="-4"
cy="-2"
r="1.6"
fill={isDark ? '#2e251b' : '#6b5742'}
stroke={pencil}
strokeWidth="0.8"
/>
<circle
cx="5"
cy="2"
r="1.4"
fill={isDark ? '#2e251b' : '#6b5742'}
stroke={pencil}
strokeWidth="0.8"
/>
</g>
))}
{/* 6. River Islands */}
{riverConfig.islands.map((island, isIdx) => (
<g key={isIdx} transform={`translate(${island.cx}, ${island.cy}) rotate(${island.angle})`}>
<ellipse
cx="0"
cy="0"
rx={island.rx}
ry={island.ry}
fill={islandVegetation}
stroke={pencil}
strokeWidth="1.3"
/>
<g transform={`scale(${island.rx > 14 ? 0.55 : 0.42})`}>
<RealisticTree
tree={{
x: 0,
y: -1,
scale: 0.65,
type: 'willow',
seed: isIdx * 99 + 42,
}}
theme={theme}
/>
</g>
{showLabels && island.name && island.rx > 12 && (
<text
x="0"
y={island.ry + 10}
textAnchor="middle"
fill={isDark ? '#d4bfa1' : '#57422f'}
className="font-garamond italic text-[10px] font-semibold select-none"
>
{island.name}
</text>
)}
</g>
))}
{/* 7. Waterfall */}
{riverConfig.waterfall && (
<g
id={`waterfall-${river.id}`}
transform={`translate(${riverConfig.waterfall.x}, ${riverConfig.waterfall.y}) rotate(${riverConfig.waterfall.angle})`}
>
{/* Rocky Ledge */}
<path
d={`M ${-riverConfig.waterfall.width / 2},-2 Q 0,-5 ${riverConfig.waterfall.width / 2},-2`}
fill="none"
stroke={pencil}
strokeWidth="2.2"
strokeLinecap="round"
/>
<g stroke={pencil} strokeWidth="1" opacity={0.75}>
<line
x1={-riverConfig.waterfall.width * 0.35}
y1="0"
x2={-riverConfig.waterfall.width * 0.35}
y2={riverConfig.waterfall.height}
/>
<line
x1="0"
y1="0"
x2="0"
y2={riverConfig.waterfall.height + 2}
strokeWidth="1.3"
/>
<line
x1={riverConfig.waterfall.width * 0.35}
y1="0"
x2={riverConfig.waterfall.width * 0.35}
y2={riverConfig.waterfall.height}
/>
</g>
<ellipse
cx="0"
cy={riverConfig.waterfall.height + 3}
rx={riverConfig.waterfall.width * 0.6}
ry="4.5"
fill={foamColor}
stroke={pencil}
strokeWidth="1"
strokeDasharray="3 2 5 2"
opacity={0.85}
/>
{showLabels && riverConfig.waterfall.name && (
<text
x="-14"
y="-8"
textAnchor="end"
fill={isDark ? '#e4caa0' : '#3d2817'}
stroke={isDark ? '#1a1510' : '#f4ead5'}
strokeWidth="3"
style={{ paintOrder: 'stroke' }}
className="font-cinzel text-[10px] font-bold tracking-wider select-none"
>
{riverConfig.waterfall.name}
</text>
)}
</g>
)}
{/* 8. Historic Bridges */}
{riverConfig.bridges.map((bridge, bIdx) => (
<g
key={bIdx}
id={`bridge-${river.id}-${bIdx}`}
transform={`translate(${bridge.x}, ${bridge.y}) rotate(${bridge.angle})`}
>
<rect
x="-22"
y="-9"
width="7"
height="18"
rx="1"
fill={isDark ? '#2e251b' : '#9c876b'}
stroke={pencil}
strokeWidth="1.2"
/>
<rect
x="15"
y="-9"
width="7"
height="18"
rx="1"
fill={isDark ? '#2e251b' : '#9c876b'}
stroke={pencil}
strokeWidth="1.2"
/>
<rect
x="-18"
y="-7"
width="36"
height="14"
rx="2"
fill={isDark ? '#3d3126' : '#d8c7a8'}
stroke={pencil}
strokeWidth="1.6"
/>
<line x1="-10" y1="-7" x2="-10" y2="7" stroke={pencil} strokeWidth="1" />
<line x1="0" y1="-7" x2="0" y2="7" stroke={pencil} strokeWidth="1.3" />
<line x1="10" y1="-7" x2="10" y2="7" stroke={pencil} strokeWidth="1" />
{showLabels && bridge.name && (
<text
x="0"
y="17"
textAnchor="middle"
fill={isDark ? '#d4bfa1' : '#4a3726'}
stroke={isDark ? '#1a1510' : '#f4ead5'}
strokeWidth="2.5"
style={{ paintOrder: 'stroke' }}
className="font-garamond italic text-[10px] font-semibold select-none"
>
{bridge.name}
</text>
)}
</g>
))}
{/* 9. River Name Label with Parchment Halo */}
{showLabels && (
<text
x={riverConfig.labelPos.x}
y={riverConfig.labelPos.y}
fill={isDark ? '#e4caa0' : '#4a3420'}
stroke={isDark ? '#1a1510' : '#f4ead5'}
strokeWidth="3.5"
style={{ paintOrder: 'stroke' }}
className="font-cinzel italic text-[14px] font-bold tracking-widest select-none"
opacity={0.92}
transform={`rotate(${riverConfig.labelPos.rot} ${riverConfig.labelPos.x} ${riverConfig.labelPos.y})`}
>
~ {river.name} ~
</text>
)}
</g>
);
};