Compare commits

...
5 Commits
Author SHA1 Message Date
tresabhi 6d2573ee95 softer buttons 2026-05-11 17:18:44 -05:00
tresabhi 4c77cc2282 feat: dynamic color scales 2026-05-11 17:08:44 -05:00
tresabhi 32f6916266 combined alternative modules 2026-05-11 17:00:30 -05:00
tresabhi 3a91e082d5 feat: compact icons 2026-05-11 16:49:14 -05:00
tresabhi 2184c1c703 feat: pitch limits and modules 2026-05-11 16:17:15 -05:00
12 changed files with 272 additions and 113 deletions

No files matched your search

+2 -1
View File
@@ -199,7 +199,8 @@
"tanks": {
"loadout": {
"modules": "Modules"
"modules": "Modules",
"alternative": "Alt"
},
"search": {
@@ -27,9 +27,12 @@
background-color: var(--accent-8);
}
&[data-variant="surface"] {
&[data-variant="surface"],
&[data-variant="soft"] {
background-color: var(--accent-3);
}
outline: var(--space-1) solid var(--accent-4);
&[data-variant="surface"] {
outline: var(--space-1) solid var(--accent-6);
}
}
@@ -6,7 +6,7 @@ import styles from "./index.module.css";
export interface ButtonProps extends ComponentProps<"button"> {
color?: Color;
radius?: `${1 | 2 | 3}` | "max";
variant?: "solid" | "surface";
variant?: "solid" | "surface" | "soft";
}
export const LIGHT_TEXT_COLORS = new Set<Color>([
@@ -35,14 +35,10 @@ export function Button({
return (
<button
className={classNames("composable-radius", styles.button, className)}
data-color={color}
data-accent={color}
data-variant={variant}
data-light-text={variant === "solid"}
data-radius={radius}
style={{
backgroundColor: color ? `var(--${color}-9)` : undefined,
...style,
}}
{...props}
/>
);
@@ -18,6 +18,15 @@ for (let i = 0; i < 12; i++) {
styles += `--${alias}-${alpha ? "a" : ""}${n}:var(--${color}-${alpha ? "a" : ""}${n});`;
}
styles += "}";
styles += `*[data-accent='${alias}']{`;
for (let i = 0; i < 12; i++) {
const n = i + 1;
styles += `--accent-${alpha ? "a" : ""}${n}:var(--${alias}-${alpha ? "a" : ""}${n});`;
}
styles += "}";
---
@@ -39,6 +39,15 @@ for (let i = 0; i < 12; i++) {
styles += `--${color}-${alpha ? "a" : ""}${n}:${value};`;
}
styles += "}";
styles += `*[data-accent='${color}']{`;
for (let i = 0; i < 12; i++) {
const n = i + 1;
styles += `--accent-${alpha ? "a" : ""}${n}:var(--${color}-${alpha ? "a" : ""}${n});`;
}
styles += "}";
---
@@ -3,5 +3,5 @@
aspect-ratio: 1 / 1;
font-size: 2rem;
font-size: 1.75em;
}
@@ -1,13 +1,7 @@
import { classNames } from "../../core/ui/classNames";
import type { Color } from "../../core/ui/color";
import { Button, type ButtonProps } from "../Button";
import styles from "./index.module.css";
export interface IconButtonProps extends ButtonProps {
color?: Color;
variant?: "solid";
}
export function IconButton({ className, ...props }: ButtonProps) {
return (
<Button
@@ -1,19 +1,29 @@
.lines {
display: flex;
flex-direction: column;
gap: var(--space-3);
.line {
display: flex;
flex-direction: column;
align-items: center;
gap: var(--space-2);
gap: var(--space-3);
.stage {
position: relative;
img {
width: 1em;
height: 1em;
transform: translate(var(--space-1), var(--space-1));
}
.tier {
position: absolute;
left: var(--space-2);
top: var(--space-2);
}
}
}
@@ -1,6 +1,6 @@
import type { UpgradeLine } from "@blitzkit/closed/protos/game/proto/legacy/blitz_static_tank_upgrade_line";
import { CaretDownIcon } from "@radix-ui/react-icons";
import { Fragment } from "react";
import { romanize } from "@blitzkit/core";
import { Fragment, useMemo } from "react";
import { api } from "../../core/api/dynamic";
import { useAwait } from "../../hooks/useAwait";
import { useStrings } from "../../hooks/useStrings";
@@ -8,6 +8,7 @@ import { Tankopedia } from "../../stores/tankopedia";
import { Heading } from "../Heading";
import { IconButton } from "../IconButton";
import { Section } from "../Section";
import { Text } from "../Text";
import styles from "./index.module.css";
export function TankopediaLoadout() {
@@ -22,7 +23,11 @@ export function TankopediaLoadout() {
<div className={styles.lines}>
{tank.tank!.upgrade_lines.map((line) => (
<Line key={line.name} line={line} />
<Line
key={line.name}
line={line.name}
lines={tank.tank!.upgrade_lines}
/>
))}
</div>
</Section>
@@ -30,85 +35,115 @@ export function TankopediaLoadout() {
}
interface LineProps {
line: UpgradeLine;
line: string;
lines: UpgradeLine[];
}
function Line({ line }: LineProps) {
const upgrades = Tankopedia.use((state) => state.protagonist.upgrades);
const id = Tankopedia.use((state) => state.protagonist.id);
const tank = useAwait(() => api.tank(id), `tank-${id}`);
const mergeLines = {
alternative_guns: "guns",
} as Record<string, string>;
function Line({ line, lines }: LineProps) {
const combinedLines = useMemo(() => {
const lines: string[] = [line];
for (const key in mergeLines) {
if (mergeLines[key] === line) {
lines.push(key);
}
}
return lines;
}, [line]);
return (
<div className={styles.line}>
{line.stages.map((stage, index) => {
const isSelected = upgrades[line.name] === index;
return (
<Fragment key={stage.tech_name}>
{index !== 0 && <CaretDownIcon width="1em" height="1em" />}
<IconButton
variant={isSelected ? "solid" : "surface"}
radius="1"
className={styles.stage}
onClick={() => {
Tankopedia.mutate((draft) => {
draft.protagonist.upgrades[line.name] = index;
for (const required of stage.required_upgrades) {
for (const line of tank.tank!.upgrade_lines) {
let i = 0;
for (const stage of line.stages) {
if (stage.tech_name === required) {
draft.protagonist.upgrades[line.name] = Math.max(
draft.protagonist.upgrades[line.name],
i,
);
}
i++;
}
}
}
for (const line of tank.tank!.upgrade_lines) {
let i = draft.protagonist.upgrades[line.name];
while (i > 0) {
const currentStage = line.stages[i];
const valid = currentStage.required_upgrades.every(
(required) => {
for (const line of tank.tank!.upgrade_lines) {
const idx = draft.protagonist.upgrades[line.name];
if (line.stages[idx]?.tech_name === required) {
return true;
}
}
return false;
},
);
if (valid) break;
i--;
}
draft.protagonist.upgrades[line.name] = i;
}
});
}}
>
<img src={`/api/tanks/modules/${stage.stage_type}.webp`} />
{/* {stage.display_name} */}
{/* {stage.grade} */}
{/* {stage.number} */}
</IconButton>
</Fragment>
);
})}
{!(line in mergeLines) &&
combinedLines.map((line) => <LineInner line={line} lines={lines} />)}
</div>
);
}
function LineInner({ line, lines }: LineProps) {
const id = Tankopedia.use((state) => state.protagonist.id);
const upgrades = Tankopedia.use((state) => state.protagonist.upgrades);
const tank = useAwait(() => api.tank(id), `tank-${id}`);
const strings = useStrings();
return lines
.find((l) => l.name === line)!
.stages.map((stage, index) => {
const isSelected = upgrades[line] === index;
return (
<Fragment key={stage.tech_name}>
<IconButton
color={isSelected ? undefined : "gray"}
variant={isSelected ? "surface" : "soft"}
radius="1"
className={styles.stage}
onClick={() => {
Tankopedia.mutate((draft) => {
draft.protagonist.upgrades[line] = index;
for (const required of stage.required_upgrades) {
for (const line of tank.tank!.upgrade_lines) {
let i = 0;
for (const stage of line.stages) {
if (stage.tech_name === required) {
draft.protagonist.upgrades[line.name] = Math.max(
draft.protagonist.upgrades[line.name],
i,
);
}
i++;
}
}
}
for (const line of tank.tank!.upgrade_lines) {
let i = draft.protagonist.upgrades[line.name];
while (i > 0) {
const currentStage = line.stages[i];
const valid = currentStage.required_upgrades.every(
(required) => {
for (const line of tank.tank!.upgrade_lines) {
const idx = draft.protagonist.upgrades[line.name];
if (line.stages[idx]?.tech_name === required) {
return true;
}
}
return false;
},
);
if (valid) break;
i--;
}
draft.protagonist.upgrades[line.name] = i;
}
});
}}
>
<img src={`/api/tanks/modules/${stage.stage_type}.webp`} />
{/* {stage.display_name} */}
{/* {stage.grade} */}
<Text lowContrast size="minor" className={styles.tier}>
{line in mergeLines
? strings.tanks.loadout.alternative
: romanize(stage.number)}
</Text>
</IconButton>
</Fragment>
);
});
}
@@ -2,6 +2,8 @@ import type { TankCatalogComponent } from "@blitzkit/closed/protos/game/proto/le
import { StandardSinglePrice } from "@protos/game/proto/legacy/blitz_static_standard_single_price";
import { PenetrationGroup } from "@protos/game/proto/legacy/blitz_static_tank_penetration_group";
import {
ModuleUpgrade,
ModuleUpgrade_Modifier,
PenetrationGroupUpgrade,
PitchLimit,
ShellUpgrade,
@@ -108,8 +110,63 @@ function patch(stage0: StageParameters, stage1: StageParameters) {
}
}
if (stage1.modules_upgrades.length > 0) {
throw new Error("Modules upgrades not implemented");
for (const upgrade1 of stage1.modules_upgrades) {
let value1: number;
switch (upgrade1.modifier) {
case ModuleUpgrade_Modifier.MODIFIER_OVERRIDE:
value1 = upgrade1.value!;
break;
case ModuleUpgrade_Modifier.MODIFIER_MULTIPLY:
case ModuleUpgrade_Modifier.MODIFIER_ADD:
const upgrade0 = stage0.modules_upgrades.find(
(base) =>
base.module === upgrade1.module &&
base.attribute_name === upgrade1.attribute_name,
);
if (!upgrade0) {
throw new Error(
`Missing module upgrade ${upgrade1.module} ${upgrade1.attribute_name} to modify`,
);
}
case ModuleUpgrade_Modifier.MODIFIER_MULTIPLY: {
value1 = upgrade0!.value! * upgrade1.value!;
break;
}
case ModuleUpgrade_Modifier.MODIFIER_ADD: {
value1 = upgrade0!.value! + upgrade1.value!;
break;
}
default:
throw new Error(
`Unhandled module upgrade modifier ${
ModuleUpgrade_Modifier[upgrade1.modifier]
}`,
);
}
const upgrade0 = ModuleUpgrade.create({
module: upgrade1.module,
attribute_name: upgrade1.attribute_name,
modifier: ModuleUpgrade_Modifier.MODIFIER_OVERRIDE,
value: value1,
});
const index0 = stage0.modules_upgrades.findIndex(
(upgrade) =>
upgrade.module === upgrade1.module &&
upgrade.attribute_name === upgrade1.attribute_name,
);
if (index0 === -1) {
stage0.modules_upgrades.push(upgrade0);
} else {
stage0.modules_upgrades[index0] = upgrade0;
}
}
for (const shellUpgrades1 of stage1.shells_upgrades) {
@@ -149,23 +206,20 @@ function patch(stage0: StageParameters, stage1: StageParameters) {
stage0.pump_reload_times = [...stage1.pump_reload_times];
}
if (stage1.pitch_limits_up.length > 0 && stage0.pitch_limits_up.length > 0) {
throw new Error("Pitch limits not implemented");
if (stage1.pitch_limits_up.length > 0) {
stage0.pitch_limits_up = [];
for (const pitchLimitUp1 of stage1.pitch_limits_up) {
stage0.pitch_limits_up.push(PitchLimit.create(pitchLimitUp1));
}
}
for (const pitchLimitUp1 of stage1.pitch_limits_up) {
stage0.pitch_limits_up.push(PitchLimit.create(pitchLimitUp1));
}
if (stage1.pitch_limits_down.length > 0) {
stage0.pitch_limits_down = [];
if (
stage1.pitch_limits_down.length > 0 &&
stage0.pitch_limits_down.length > 0
) {
throw new Error("Pitch limits not implemented");
}
for (const pitchLimitDown1 of stage1.pitch_limits_down) {
stage0.pitch_limits_down.push(PitchLimit.create(pitchLimitDown1));
for (const pitchLimitDown1 of stage1.pitch_limits_down) {
stage0.pitch_limits_down.push(PitchLimit.create(pitchLimitDown1));
}
}
for (const visualChange1 of stage1.visual_changes) {
@@ -1,12 +1,12 @@
import { normalizeAngleDeg } from "@blitzkit/core";
import type { PitchLimit } from "@protos/blitz_static_tank_upgrade_single_stage";
import type { PitchLimit } from "@protos/game/proto/legacy/blitz_static_tank_upgrade_single_stage";
import { clamp, degToRad, lerp, radToDeg } from "three/src/math/MathUtils.js";
export function applyPitchYawLimits(
givenPitch: number,
givenYaw: number,
pitchLimitsUp: PitchLimit[],
pitchLimitsDown: PitchLimit[]
pitchLimitsDown: PitchLimit[],
) {
const givenYawDeg = normalizeAngleDeg(radToDeg(givenYaw));
const givenPitchDeg = normalizeAngleDeg(radToDeg(givenPitch));
@@ -0,0 +1,48 @@
// Source - https://stackoverflow.com/a/9083076
// Posted by Rene Pot, modified by community. See post 'Timeline' for change history
// Retrieved 2026-05-11, License - CC BY-SA 4.0
const keys = [
"",
"C",
"CC",
"CCC",
"CD",
"D",
"DC",
"DCC",
"DCCC",
"CM",
"",
"X",
"XX",
"XXX",
"XL",
"L",
"LX",
"LXX",
"LXXX",
"XC",
"",
"I",
"II",
"III",
"IV",
"V",
"VI",
"VII",
"VIII",
"IX",
];
export function romanize(number: number) {
let digits = String(+number).split("");
let roman = "";
let i = 3;
while (i--) {
roman = (keys[+digits.pop()! + i * 10] || "") + roman;
}
return Array(+digits.join("") + 1).join("M") + roman;
}