Files
Dune/components/battle-wheel.tsx
T
Quintine b2fcef8d51 Add Storm and Spice Blow practice
Expand the interactive introduction to thirteen lessons and eleven Basic examples. Separate storm sealing, reveal and movement; compare first-turn and later-turn ranges, wraparound, exposure and shelter. Offer four spice sequences for accumulation, storm loss, later worms and first-turn worm return, with Nexus opening only after the replacement blow finishes. Reuse existing card inspection and preserve all previous lesson identities and results through version 6 migration.

Extract unchanged storm-sector, exposure, worm-protection and spice-placement calculations into a focused module shared by engine, preflight and teaching. Existing battle-wheel defaults stay intact while storm practice supplies its minimum and accessible label. No live state schema, rules interpretation, mode gate or AI strategy changes.

All 4954 offline tests, types, lint and production build pass on stable final source. Focused tests compare all 24 offered storm dials and four spice cases with actual engine actions, verify exact ignored-worm return, and exercise every saved stage and v1–v5 migration. Independent review found no material findings. Earlier broad runs passed but were invalidated by a final rules-copy clarification and migration documentation correction; final3 verifies the stable source.

Browser checks retain the earlier Fremen revival outcome after migration, restore a sealed storm and completed Nexus across refresh, verify wrap/shelter/zero movement, exercise all four spice cases and inspect the revealed worm. Mobile controls and modal fit 390px; Escape restores the trigger. Screenshot capture remains unavailable. Full faction, Fremen-ride, Advanced/expansion teaching and complete game acceptance remain open.

All 1373 rooms, 2883 seats and auxiliary rows remain unchanged; SQLite integrity and foreign keys pass. Server reused without restart. HTTP tests not repeated because HTTP, auth, persistence and state shape are unchanged.

Private evidence: 20260921-opening-phase-practice.
Verified source tree: 6bd333ec6938904b31523f8b20042e516ba55b6ac4c63973e5bb7ee74baa71fb
2026-09-21 09:24:51 +10:00

191 lines
5.4 KiB
TypeScript

'use client';
import { useId } from 'react';
import styles from './battle-wheel.module.css';
export type BattleWheelProps = {
value: number;
onChange: (value: number) => void;
max: number;
min?: number;
sliderLabel?: string;
step: number;
disabled?: boolean;
id?: string;
};
const point = (angle: number, radius: number) => ({
x: 100 + Math.sin((angle * Math.PI) / 180) * radius,
y: 100 - Math.cos((angle * Math.PI) / 180) * radius,
});
/** The parent supplies the dial limits and labels the numeric input by its ID. */
export function BattleWheel({
value,
onChange,
max,
min = 0,
sliderLabel = 'Forces dialed slider',
step,
disabled = false,
id = 'forces-dialed',
}: BattleWheelProps) {
const graphicId = useId();
const rimId = `${graphicId}-rim`;
const faceId = `${graphicId}-face`;
const fraction = max > min ? Math.min(1, Math.max(0, (value - min) / (max - min))) : 0;
const angle = -135 + fraction * 270;
// This caps decorative detail only; the native controls keep the supplied step.
const divisions = Math.min(80, Math.max(1, Math.ceil((max - min) / step)));
const labels = [
...new Set(
[0, 0.25, 0.5, 0.75, 1].map((position) =>
Math.min(max, min + Math.round(((max - min) * position) / step) * step),
),
),
];
return (
<div className={styles.root} data-disabled={disabled || undefined}>
<svg
className={styles.wheel}
viewBox="0 0 200 200"
aria-hidden="true"
focusable="false"
>
<defs>
<linearGradient id={rimId} x1="0" y1="0" x2="1" y2="1">
<stop offset="0" stopColor="#e3c68a" />
<stop offset="0.35" stopColor="#756344" />
<stop offset="0.65" stopColor="#302d24" />
<stop offset="1" stopColor="#b29966" />
</linearGradient>
<radialGradient id={faceId} cx="40%" cy="28%" r="75%">
<stop offset="0" stopColor="#30362b" />
<stop offset="1" stopColor="#131810" />
</radialGradient>
</defs>
<circle cx="100" cy="102" r="96" fill="#080b07" opacity="0.6" />
<circle cx="100" cy="100" r="95" fill={`url(#${rimId})`} />
<circle cx="100" cy="100" r="91" fill="#181d15" />
<circle
cx="100"
cy="100"
r="87"
fill="none"
stroke="#736344"
strokeWidth="0.6"
/>
{Array.from({ length: divisions + 1 }, (_, index) => {
const position = index / divisions;
const tickAngle = -135 + position * 270;
const major = index % Math.max(1, Math.round(divisions / 4)) === 0;
const outer = point(tickAngle, 83);
const inner = point(tickAngle, major ? 73 : 78);
return (
<line
key={index}
x1={inner.x}
y1={inner.y}
x2={outer.x}
y2={outer.y}
stroke={position <= fraction ? '#e3c68a' : '#777762'}
strokeWidth={major ? 1.7 : 0.8}
/>
);
})}
{labels.map((mark) => {
const label = point(-135 + (max > min ? (mark - min) / (max - min) : 0) * 270, 62);
return (
<text
key={mark}
x={label.x}
y={label.y}
fill="#d1c4a4"
fontSize="12"
textAnchor="middle"
dominantBaseline="central"
>
{Number(mark.toFixed(2))}
</text>
);
})}
<circle
cx="100"
cy="100"
r="44"
fill={`url(#${faceId})`}
stroke="#89764d"
strokeWidth="1"
/>
<circle
cx="100"
cy="100"
r="40"
fill="none"
stroke="#c6ad76"
strokeOpacity="0.15"
/>
<path
d="M 96 29 L 100 18 L 104 29 Z"
fill="#f2d79b"
stroke="#171b12"
strokeWidth="0.8"
transform={`rotate(${angle} 100 100)`}
/>
<text
x="100"
y="101"
textAnchor="middle"
dominantBaseline="central"
className={styles.chosen}
>
{value}
</text>
<text
x="100"
y="124"
textAnchor="middle"
fill="#c0b290"
fontSize="9"
letterSpacing="1.6"
>
DIALED
</text>
<path d="M 85 173 H 115" stroke="#a28b5e" strokeWidth="1" />
<circle cx="100" cy="180" r="1.5" fill="#a28b5e" />
</svg>
<div className={styles.controls}>
<div className={styles.slider}>
<input
className={styles.range}
type="range"
min={min}
max={max}
step={step}
value={value}
disabled={disabled}
aria-label={sliderLabel}
onChange={(event) => onChange(Number(event.target.value))}
/>
<div className={styles.bounds} aria-hidden="true">
<span>{min}</span>
<span>{max}</span>
</div>
</div>
<input
className={styles.number}
id={id}
type="number"
min={min}
max={max}
step={step}
value={value}
disabled={disabled}
onChange={(event) => onChange(Number(event.target.value))}
/>
</div>
</div>
);
}