augment trees, pitch-limit fallback, and cached definitions

This commit is contained in:
tresabhi committed 2026-11-15 17:28:43 -06:00
1 parent da9c5272bc
commit 79129ff3c0
57 files changed
+2196 -717

No files matched your search

@@ -541,3 +541,85 @@
}
}
}
.assault {
--axis-width: var(--space-8);
--axis-height: var(--space-7);
position: relative;
width: 100%;
height: 100%;
padding: var(--space-4) var(--space-5) var(--axis-height) var(--axis-width);
border-radius: inherit;
background-color: var(--gray-2);
user-select: none;
.assault-damage {
position: absolute;
top: var(--space-4);
bottom: var(--axis-height);
left: var(--space-2);
span {
position: absolute;
left: 0;
transform: translateY(50%);
color: var(--gray-11);
font-size: var(--font-size-minor);
white-space: nowrap;
}
}
.assault-plot {
position: relative;
display: flex;
align-items: flex-end;
width: 100%;
height: 100%;
cursor: ew-resize;
touch-action: none;
}
.assault-sector {
background: linear-gradient(
45deg,
color-mix(in hsl, var(--tomato-7), var(--jade-7) var(--mix)),
color-mix(in hsl, var(--tomato-9), var(--jade-9) var(--mix))
);
border-top: 1px solid var(--gray-11);
}
.assault-cursor {
position: absolute;
top: 0;
bottom: 0;
width: 2px;
transform: translateX(-50%);
background-color: var(--accent-11);
pointer-events: none;
}
.assault-distances {
position: absolute;
bottom: 0;
left: var(--axis-width);
right: var(--space-5);
display: flex;
height: var(--axis-height);
div {
position: relative;
height: 100%;
}
span {
position: absolute;
right: 0;
margin-top: var(--space-2);
transform: translateX(50%);
color: var(--gray-11);
font-size: var(--font-size-minor);
writing-mode: vertical-rl;
}
}
}
@@ -22,6 +22,11 @@ import { useDuelModels } from "../../hooks/useDuelModels";
import { useDuelModules } from "../../hooks/useDuelModules";
import { useEquipment } from "../../hooks/useEquipment";
import { useStrings } from "../../hooks/useStrings";
import {
fakeLogSquishyHigh,
fakeLogSquishyHighInverse,
fakeLogSquishyLow,
} from "../../core/blitzkit/fakeLog";
import { Tankopedia } from "../../stores/tankopedia";
import type { ComputedCharacteristics } from "../../types/characteristics";
import { Button } from "../Button";
@@ -901,3 +906,131 @@ export function FlexibilityToy() {
</div>
);
}
// Where the pointer is across the plot, from 0 to 1
function plotFraction(event: PointerEvent<HTMLDivElement>) {
const rect = event.currentTarget.getBoundingClientRect();
return clamp((event.clientX - rect.left) / rect.width, 0, 1);
}
export function AssaultShellsToy({ characteristics }: ToyProps) {
const strings = useStrings();
const distance = Tankopedia.use((state) => state.environment.distance);
// Where the cursor is while it is dragged, as a fraction of the plot
const [dragged, setDragged] = useState<number>();
const distances = characteristics.get("_assault_distances") as number[];
const factors = characteristics.get("_assault_factors") as number[];
const baseDamage = characteristics.get("_base_damage") as number;
const maxDistance = distances.at(-1)!;
// Sector widths are stretched so the near ones stay readable. The last one
// always ends at the far edge
const sectors = useMemo(() => {
const maxFactor = Math.max(...factors);
let start = 0;
return distances.map((sectorDistance, index) => {
const end = fakeLogSquishyHigh(sectorDistance / maxDistance);
const relative = factors[index] / maxFactor;
const sector = {
distance: sectorDistance,
factor: factors[index],
width: `${(end - start) * 100}%`,
height: `${fakeLogSquishyLow(relative) * 100}%`,
mix: `${clamp(2 * relative - 1, 0, 1) * 100}%`,
};
start = end;
return sector;
});
}, [distances, factors, maxDistance]);
const cursor =
dragged ??
fakeLogSquishyHigh(Math.min(distance, maxDistance) / maxDistance);
const handlePointerDown = useCallback(
(event: PointerEvent<HTMLDivElement>) => {
event.currentTarget.setPointerCapture(event.pointerId);
setDragged(plotFraction(event));
},
[],
);
const handlePointerMove = useCallback(
(event: PointerEvent<HTMLDivElement>) => {
if (!event.currentTarget.hasPointerCapture(event.pointerId)) return;
setDragged(plotFraction(event));
},
[],
);
// Only the release writes the distance, so dragging recomputes nothing
const handlePointerUp = useCallback(
(event: PointerEvent<HTMLDivElement>) => {
if (!event.currentTarget.hasPointerCapture(event.pointerId)) return;
const fraction = plotFraction(event);
Tankopedia.mutate((draft) => {
draft.environment.distance =
fakeLogSquishyHighInverse(fraction) * maxDistance;
});
setDragged(undefined);
},
[maxDistance],
);
const handlePointerCancel = useCallback(() => setDragged(undefined), []);
return (
<div className={styles.assault}>
<div className={styles["assault-damage"]}>
{sectors.map(({ distance: sectorDistance, factor, height }) => (
<span key={sectorDistance} style={{ bottom: height }}>
{literals(strings.common.units.hp, {
value: Math.round(baseDamage * factor),
})}
</span>
))}
</div>
<div
className={styles["assault-plot"]}
onPointerDown={handlePointerDown}
onPointerMove={handlePointerMove}
onPointerUp={handlePointerUp}
onPointerCancel={handlePointerCancel}
>
{sectors.map(({ distance: sectorDistance, width, height, mix }) => (
<div
key={sectorDistance}
className={styles["assault-sector"]}
style={{ width, height, "--mix": mix } as CSSProperties}
/>
))}
<div
className={styles["assault-cursor"]}
style={{ left: `${cursor * 100}%` }}
/>
</div>
<div className={styles["assault-distances"]}>
{sectors.map(({ distance: sectorDistance, width }) => (
<div key={sectorDistance} style={{ width }}>
<span>
{literals(strings.common.units.m, {
value: Math.round(sectorDistance),
})}
</span>
</div>
))}
</div>
</div>
);
}