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

@@ -19,7 +19,7 @@
&[data-size="major"] {
--padding: var(--space-3);
--content-size: calc(1.5 * var(--font-size-regular));
--content-size: calc(1.75 * var(--font-size-regular));
}
padding: var(--padding) calc(2 * var(--padding));
@@ -1,5 +1,5 @@
.discriminator {
--inset: var(--space-3);
--inset: var(--space-2);
&[data-inset="small"] {
--inset: var(--space-2);
@@ -0,0 +1,87 @@
.tree {
--line-thickness: calc(var(--space-1) * 2);
--line-color: var(--gray-6);
.cell {
.north,
.south,
.west,
.east {
position: absolute;
background-color: var(--line-color);
}
.north,
.south {
left: 50%;
width: var(--line-thickness);
transform: translateX(-50%);
}
.west,
.east {
top: 50%;
height: var(--line-thickness);
transform: translateY(-50%);
}
/* An empty cell passes a line through, out to the middle of the gaps */
.north {
top: calc(var(--depth-gap) / -2);
height: calc(50% + var(--depth-gap) / 2);
}
.south {
bottom: calc(var(--depth-gap) / -2);
height: calc(50% + var(--depth-gap) / 2);
}
.west {
left: calc(var(--sibling-gap) / -2);
width: calc(50% + var(--sibling-gap) / 2);
}
.east {
right: calc(var(--sibling-gap) / -2);
width: calc(50% + var(--sibling-gap) / 2);
}
/* The buttons are translucent, so around a node the lines stay in the gaps */
&[data-node="true"] {
.north {
top: auto;
bottom: 100%;
height: calc(var(--depth-gap) / 2);
}
.south {
bottom: auto;
top: 100%;
height: calc(var(--depth-gap) / 2);
}
.west {
left: auto;
right: 100%;
width: calc(var(--sibling-gap) / 2);
}
.east {
right: auto;
left: 100%;
width: calc(var(--sibling-gap) / 2);
}
}
}
.alternatives {
grid-column: 1 / -1;
display: flex;
justify-content: center;
gap: var(--sibling-gap);
/* Prices hang below the nodes */
padding-bottom: calc(var(--space-2) + var(--font-size-minor));
}
}
@@ -0,0 +1,244 @@
import { alias, formatCompact } from "@blitzkit/core";
import {
AugmentNodeType,
type AugmentGroup,
type AugmentNode,
type AugmentProgression,
} from "@blitzkit/protos";
import {
DoubleArrowDownIcon,
DoubleArrowUpIcon,
LightningBoltIcon,
StarFilledIcon,
} from "@radix-ui/react-icons";
import { useCallback, useMemo } from "react";
import { useLocale } from "../../hooks/useLocale";
import { useStrings } from "../../hooks/useStrings";
import { layoutAugmentTree } from "../../tankopedia/augmentTreeLayout";
import { AUGMENT_GROUP_ID } from "../../tankopedia/augments";
import { classNames } from "../../ui/classNames";
import { IconButton } from "../IconButton";
import { LoadoutSection } from "../LoadoutSection";
import shared from "../LoadoutTree/index.module.css";
import { Text } from "../Text";
import styles from "./index.module.css";
interface AugmentIconProps {
icon?: string;
isCommon: boolean;
}
function AugmentIcon({ icon, isCommon }: AugmentIconProps) {
if (icon !== undefined) {
return (
<img
alt=""
src={alias("api", `/icons/augments/${icon}.webp`)}
className={shared.icon}
/>
);
}
return isCommon ? (
<StarFilledIcon className={shared.icon} />
) : (
<LightningBoltIcon className={shared.icon} />
);
}
interface PriceProps {
xp: number;
}
function Price({ xp }: PriceProps) {
const locale = useLocale();
if (xp <= 0) return null;
return (
<div className={shared.price}>
<Text size="minor">{formatCompact(locale, xp)}</Text>
<img alt="xp" src={alias("api", "/icons/currencies/xp.webp")} />
</div>
);
}
interface AugmentButtonProps {
node: AugmentNode;
isSelected: boolean;
onToggle: (id: number) => void;
}
function AugmentButton({ node, isSelected, onToggle }: AugmentButtonProps) {
const isCommon = node.type === AugmentNodeType.AUGMENT_NODE_TYPE_COMMON;
const handleClick = useCallback(() => onToggle(node.id), [onToggle, node]);
return (
<IconButton
radius="1"
size="major"
variant={isSelected ? "surface" : "soft"}
color={isSelected ? (isCommon ? undefined : "amber") : "gray"}
className={shared.node}
data-notable={!isCommon}
onClick={handleClick}
>
<AugmentIcon
icon={node.attributes.find((attribute) => attribute.icon)?.icon}
isCommon={isCommon}
/>
<Price xp={node.xp_cost} />
</IconButton>
);
}
interface GroupButtonProps {
group: AugmentGroup;
// One of its alternatives is installed
isSelected: boolean;
onToggle: (id: number) => void;
}
// Where the branches meet; the choice itself hangs below
function GroupButton({ group, isSelected, onToggle }: GroupButtonProps) {
const handleClick = useCallback(() => onToggle(AUGMENT_GROUP_ID), [onToggle]);
return (
<IconButton
radius="1"
size="major"
variant={isSelected ? "surface" : "soft"}
color={isSelected ? "amber" : "gray"}
className={shared.node}
data-notable
onClick={handleClick}
>
<AugmentIcon icon={group.icon} isCommon={false} />
<Price xp={group.xp_cost} />
</IconButton>
);
}
interface ContentProps {
progression: AugmentProgression;
selected: number[];
onToggle: (id: number) => void;
}
function Content({ progression, selected, onToggle }: ContentProps) {
const { group } = progression;
const installed = useMemo(() => new Set(selected), [selected]);
const isGroupSelected =
group?.alternatives.some(({ id }) => installed.has(id)) ?? false;
const { cells, columns, rows } = useMemo(
() => layoutAugmentTree(progression),
[progression],
);
return (
<div
className={classNames(shared.tree, styles.tree)}
style={{
gridTemplateColumns: `repeat(${columns}, auto)`,
gridTemplateRows: `repeat(${rows}, auto) auto`,
}}
>
{cells.map((cell) => (
<div
key={`${cell.row},${cell.column}`}
className={classNames(shared.cell, styles.cell)}
data-node={cell.node !== undefined || cell.group !== undefined}
style={{ gridColumn: cell.column, gridRow: cell.row }}
>
{cell.north && <span className={styles.north} />}
{cell.south && <span className={styles.south} />}
{cell.west && <span className={styles.west} />}
{cell.east && <span className={styles.east} />}
{cell.node && (
<AugmentButton
node={cell.node}
isSelected={installed.has(cell.node.id)}
onToggle={onToggle}
/>
)}
{cell.group && (
<GroupButton
group={cell.group}
isSelected={isGroupSelected}
onToggle={onToggle}
/>
)}
</div>
))}
{group !== undefined && (
// The mutually exclusive choice, hanging below the cell that leads in
<div className={styles.alternatives} style={{ gridRow: rows + 1 }}>
{group.alternatives.map((node) => (
<AugmentButton
key={node.id}
node={node}
isSelected={installed.has(node.id)}
onToggle={onToggle}
/>
))}
</div>
)}
</div>
);
}
interface LoadoutAugmentsProps {
progression: AugmentProgression;
selected: number[];
onToggle: (id: number) => void;
onStock: () => void;
onMaximize: () => void;
}
export function LoadoutAugments({
progression,
selected,
onToggle,
onStock,
onMaximize,
}: LoadoutAugmentsProps) {
const strings = useStrings();
return (
<LoadoutSection
title={strings.tanks.loadout.augments}
actions={
<>
<IconButton
highContrast
color="gray"
size="minor"
variant="ghost"
onClick={onStock}
>
<DoubleArrowUpIcon />
</IconButton>
<IconButton
highContrast
color="gray"
size="minor"
variant="ghost"
onClick={onMaximize}
>
<DoubleArrowDownIcon />
</IconButton>
</>
}
>
<Content
progression={progression}
selected={selected}
onToggle={onToggle}
/>
</LoadoutSection>
);
}
@@ -1,7 +1,4 @@
.tree {
/* The game lays the tree out left to right; here depth runs top to bottom */
--depth-gap: var(--space-5);
--sibling-gap: var(--space-4);
--line-thickness: var(--space-1);
--line-border: var(--space-1) solid var(--gray-6);
@@ -9,12 +6,7 @@
margin-bottom: calc(var(--space-2) + var(--font-size-minor));
}
display: grid;
gap: var(--depth-gap) var(--sibling-gap);
.cell {
position: relative;
.trunk-left,
.trunk-right {
position: absolute;
@@ -71,41 +63,5 @@
.snake-right {
left: 100%;
}
.module {
position: relative;
.icon {
width: 2em;
height: 2em;
.module[data-major="true"] & {
transform: scale(1.25);
}
}
.price {
display: flex;
gap: var(--space-1);
font-size: var(--font-size-minor);
position: absolute;
top: 100%;
left: 50%;
transform: translateX(-50%);
margin-top: var(--space-2);
background-color: var(--gray-2);
svg,
img {
width: 1em;
height: 1em;
}
}
}
}
}
@@ -16,10 +16,12 @@ import { useStrings } from "../../hooks/useStrings";
import { useUnwrapper } from "../../hooks/useUnwrapper";
import { layoutModuleTree } from "../../tankopedia/moduleTreeLayout";
import type { TankState } from "../../tankopedia/tankState";
import { classNames } from "../../ui/classNames";
import { Discriminator } from "../Discriminator";
import { IconButton } from "../IconButton";
import { LinkI18n } from "../LinkI18n";
import { LoadoutSection } from "../LoadoutSection";
import shared from "../LoadoutTree/index.module.css";
import { Text } from "../Text";
import { Tooltip } from "../Tooltip";
import styles from "./index.module.css";
@@ -76,11 +78,11 @@ function Content({ tank, selected, onSelect }: ContentProps) {
tank.turrets
.flatMap((turret) => turret.guns)
.toReversed()
.map((gun) => [gun.id, gun])
.map((gun) => [gun.id, gun]),
),
],
]),
[tank]
[tank],
);
const resolve = useCallback(
@@ -88,7 +90,7 @@ function Content({ tank, selected, onSelect }: ContentProps) {
unlock.type === ModuleType.MODULE_TYPE_VEHICLE
? (tanks.tanks[unlock.id] as TankDefinition | undefined)
: modules.get(unlock.type)?.get(unlock.id),
[modules]
[modules],
);
const { cells, columns, rows } = useMemo(
@@ -107,9 +109,9 @@ function Content({ tank, selected, onSelect }: ContentProps) {
return children.filter((child) => resolve(child) !== undefined);
},
tank.module_positions
tank.module_positions,
),
[tank, resolve]
[tank, resolve],
);
// Prices hang below the modules, so room is only reserved if the bottom row has one
@@ -118,12 +120,12 @@ function Content({ tank, selected, onSelect }: ContentProps) {
(cell) =>
cell.position[0] === bottomRow &&
cell.unlock !== undefined &&
cell.unlock.cost!.value > 0
cell.unlock.cost!.value > 0,
);
return (
<div
className={styles.tree}
className={classNames(shared.tree, styles.tree)}
data-has-bottom-cost={hasBottomCost}
style={{
// Transposed: the layout's columns (depth) become rows
@@ -137,7 +139,7 @@ function Content({ tank, selected, onSelect }: ContentProps) {
return (
<div
key={cell.position.join(",")}
className={styles.cell}
className={classNames(shared.cell, styles.cell)}
style={{ gridColumn: cell.position[1], gridRow: cell.position[0] }}
>
{cell.trunkUp && <span className={styles["trunk-left"]} />}
@@ -209,9 +211,10 @@ function ModuleNode({
const button = (
<IconButton
radius="1"
size="major"
variant={isSelected ? "surface" : "soft"}
color={isSelected ? (isTop ? "amber" : undefined) : "gray"}
className={styles.module}
className={shared.node}
data-major={unlock.type === ModuleType.MODULE_TYPE_VEHICLE}
onClick={() => {
if (!isTank) onSelect(unlock);
@@ -224,16 +227,15 @@ function ModuleNode({
? tankIcon(unlock.id)
: alias(
"api",
`/icons/modules/${moduleIconNames[unlock.type]}.webp`
`/icons/modules/${moduleIconNames[unlock.type]}.webp`,
)
}
className={styles.icon}
/>
<Discriminator corner="top-left">{romanize(module.tier)}</Discriminator>
{unlock.cost!.value > 0 && (
<div className={styles.price}>
<div className={shared.price}>
<Text size="minor">{formatCompact(locale, unlock.cost!.value)}</Text>
<img
alt={unlock.cost!.type}
@@ -0,0 +1,41 @@
/* What the modules and the augments have in common; each draws its own lines */
.tree {
/* The game lays the tree out left to right; here depth runs top to bottom */
--depth-gap: var(--space-5);
--sibling-gap: var(--space-4);
display: grid;
gap: var(--depth-gap) var(--sibling-gap);
}
.cell {
position: relative;
}
.node {
position: relative;
.price {
display: flex;
gap: var(--space-1);
font-size: var(--font-size-minor);
position: absolute;
top: 100%;
left: 50%;
transform: translateX(-50%);
margin-top: var(--space-2);
background-color: var(--gray-2);
svg,
img {
width: 1em;
height: 1em;
}
}
}
@@ -8,12 +8,12 @@ import { useStrings } from "../hooks/useStrings";
import { TankopediaSortDirection } from "../stores/tankopediaPersistent";
import { TankSort } from "../stores/tankopediaSort";
import { sortableCharacteristics } from "../tankopedia/sortableCharacteristics";
import type { CharacteristicName } from "../types/characteristics";
import type { RenderedCharacteristicName } from "../types/characteristics";
import { Button } from "./Button";
import { DropdownMenu } from "./DropdownMenu";
interface ItemProps {
by: CharacteristicName;
by: RenderedCharacteristicName;
}
function Item({ by }: ItemProps) {
@@ -77,6 +77,8 @@ export function TankSearchSort() {
(item) => "name" in item && sortableCharacteristics.has(item.name),
);
if (items.length === 0) return null;
return (
<DropdownMenu.Sub key={group.name}>
<DropdownMenu.SubTrigger>
@@ -88,6 +88,10 @@
align-items: center;
gap: var(--space-3);
/* Same height with or without the number, so the bars line up */
font-size: var(--font-size-minor);
height: 1em;
.bar-wrapper {
flex: 1;
height: var(--space-1);
@@ -1,6 +1,6 @@
import { romanize } from "@blitzkit/core";
import { literals } from "@blitzkit/i18n/src/literals";
import { useRef } from "react";
import { Fragment, useRef } from "react";
import { characteristicsGroups } from "../../config/characteristicsGroups";
import { toys } from "../../config/toys";
import { useDuelModules } from "../../hooks/useDuelModules";
@@ -15,6 +15,7 @@ import type {
CharacteristicsGroup,
ComputedCharacteristics,
ToyName,
ToyRenderConfig,
} from "../../types/characteristics";
import { Heading } from "../Heading";
import { SegmentedControl } from "../SegmentedControl";
@@ -36,28 +37,35 @@ export function TankopediaCharacteristics({
<CompareOptions />
<div className={styles.characteristics}>
{characteristicsGroups.map((group) => {
const items = group.order.filter(
(item) => "name" in item && characteristics.has(item.name),
).length;
const shouldRender = items > 0;
if (!shouldRender) return null;
return (
<Group
key={group.name}
group={group}
characteristics={characteristics}
rankings={rankings}
/>
);
})}
{characteristicsGroups.map((group) => (
<Group
key={group.name}
group={group}
characteristics={characteristics}
rankings={rankings}
/>
))}
</div>
</div>
);
}
type GroupItem = CharacteristicsGroup["order"][number];
// A toy that needs a characteristic only shows for the tanks that have it
function hasToy(
{ requires }: ToyRenderConfig,
characteristics: ComputedCharacteristics,
) {
return requires === undefined || characteristics.has(requires);
}
function itemKey(item: GroupItem) {
if ("toy" in item) return `toy:${item.toy}`;
if ("label" in item) return `label:${item.label}`;
return item.name;
}
interface GroupProps {
group: CharacteristicsGroup;
characteristics: ComputedCharacteristics;
@@ -66,15 +74,25 @@ interface GroupProps {
function Group({ group, characteristics, rankings }: GroupProps) {
const strings = useStrings();
const toys = group.order.filter((item) => "toy" in item).length;
const characteristicsCount = group.order.filter(
(item) => "name" in item && characteristics.has(item.name),
).length;
const labelsCount =
characteristicsCount > 0
? group.order.filter((item) => "label" in item).length
: 0;
const items = characteristicsCount + labelsCount;
let toys = 0;
let characteristicsCount = 0;
let labelsCount = 0;
for (const item of group.order) {
if ("toy" in item) {
if (hasToy(item, characteristics)) toys++;
} else if ("label" in item) {
labelsCount++;
} else if (characteristics.has(item.name)) {
characteristicsCount++;
}
}
if (toys + characteristicsCount === 0) return null;
// Labels only head characteristics, so they go when there are none
const hasLabels = characteristicsCount > 0;
const items = characteristicsCount + (hasLabels ? labelsCount : 0);
const groupSpan = `calc(${toys} * var(--group-span) + ${items} + 2)`;
const contentSpan = `calc(${toys} * var(--group-span) + ${items})`;
@@ -105,11 +123,11 @@ function Group({ group, characteristics, rankings }: GroupProps) {
}}
>
{group.order.map((item) => (
<>
{"toy" in item && (
<ToyAssigner characteristics={characteristics} {...item} />
<Fragment key={itemKey(item)}>
{"toy" in item && hasToy(item, characteristics) && (
<ToyAssigner characteristics={characteristics} toy={item.toy} />
)}
{"label" in item && <Label {...item} />}
{"label" in item && hasLabels && <Label {...item} />}
{"name" in item && characteristics.has(item.name) && (
<Item
config={item}
@@ -117,7 +135,7 @@ function Group({ group, characteristics, rankings }: GroupProps) {
ranking={rankings.get(item.name)}
/>
)}
</>
</Fragment>
))}
<div className={styles.dead} />
@@ -165,18 +183,18 @@ function Item({ config, value, ranking }: ItemProps) {
<CharacteristicValue config={config} value={value} />
</div>
{ranking && (
<div className={styles.ranking}>
<Bar value={ranking.score} />
<div className={styles.ranking}>
{ranking ? <Bar value={ranking.score} /> : <BarStub />}
{ranking && (
<Text lowContrast size="minor" className={styles.number}>
{literals(strings.units.fraction, {
numerator: ranking.rank,
denominator: ranking.total,
})}
</Text>
</div>
)}
)}
</div>
</span>
);
}
@@ -229,6 +247,18 @@ function CompareOptions() {
);
}
// Unranked items get a full neutral bar
function BarStub() {
return (
<div className={styles["bar-wrapper"]}>
<div
className={styles.bar}
style={{ backgroundColor: "var(--gray-3)", width: "100%" }}
/>
</div>
);
}
interface BarProps {
value: number;
}
@@ -1,7 +1,9 @@
import { MAX_SKILL_LEVEL } from "@blitzkit/core";
import { useCallback } from "react";
import { useDuelModules } from "../../hooks/useDuelModules";
import { Tankopedia } from "../../stores/tankopedia";
import { selectModule } from "../../tankopedia/selectModule";
import { createAugments, toggleAugment } from "../../tankopedia/augments";
import { LoadoutConsumables } from "../LoadoutConsumables";
import { LoadoutEquipment } from "../LoadoutEquipment";
import { LoadoutModules } from "../LoadoutModules";
@@ -9,11 +11,13 @@ import { LoadoutProvisions } from "../LoadoutProvisions";
import { LoadoutShells } from "../LoadoutShells";
import { LoadoutSkills } from "../LoadoutSkills";
import { LoadoutStatus } from "../LoadoutStatus";
import { LoadoutAugments } from "../LoadoutAugments";
export function TankopediaLoadout() {
return (
<>
<Modules />
<Augments />
<Shells />
<Equipment />
<Provisions />
@@ -58,6 +62,47 @@ function Modules() {
);
}
function Augments() {
const protagonist = useDuelModules("protagonist");
const selected = Tankopedia.use((state) => state.protagonist.augments);
const progression = protagonist.tank.augment_progression;
const handleToggle = useCallback(
(id: number) => {
if (progression === undefined) return;
Tankopedia.mutate((draft) => {
toggleAugment(draft.protagonist, progression, id);
});
},
[progression],
);
const handleStock = useCallback(() => {
Tankopedia.mutate((draft) => {
draft.protagonist.augments = [];
});
}, []);
const handleMaximize = useCallback(() => {
Tankopedia.mutate((draft) => {
draft.protagonist.augments = createAugments(progression);
});
}, [progression]);
if (progression === undefined) return null;
return (
<LoadoutAugments
progression={progression}
selected={selected}
onToggle={handleToggle}
onStock={handleStock}
onMaximize={handleMaximize}
/>
);
}
function Shells() {
const protagonist = useDuelModules("protagonist");
@@ -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>
);
}