2026-05-11 16:49:14 -05:00
|
|
|
import { romanize } from "@blitzkit/core";
|
2026-05-15 10:54:36 -05:00
|
|
|
import { Grade } from "@protos/game/proto/legacy/blitz_static_standard_grades_enum";
|
|
|
|
|
import type { StandardPrice } from "@protos/game/proto/legacy/blitz_static_standard_price";
|
|
|
|
|
import type { UpgradeLine } from "@protos/game/proto/legacy/blitz_static_tank_upgrade_line";
|
|
|
|
|
import type { StageParameters } from "@protos/game/proto/legacy/blitz_static_tank_upgrade_single_stage";
|
|
|
|
|
import { useMemo } from "react";
|
|
|
|
|
import { useProtagonist } from "../../hooks/useProtagonist";
|
2026-04-29 16:27:13 -05:00
|
|
|
import { useStrings } from "../../hooks/useStrings";
|
2026-05-15 10:54:36 -05:00
|
|
|
import { useUpgradePreset } from "../../hooks/useUpgradePreset";
|
2026-04-29 16:27:13 -05:00
|
|
|
import { Tankopedia } from "../../stores/tankopedia";
|
|
|
|
|
import { Heading } from "../Heading";
|
|
|
|
|
import { IconButton } from "../IconButton";
|
2026-05-15 10:54:36 -05:00
|
|
|
import { Price } from "../Price";
|
2026-04-29 16:27:13 -05:00
|
|
|
import { Section } from "../Section";
|
2026-05-11 16:49:14 -05:00
|
|
|
import { Text } from "../Text";
|
2026-04-29 16:27:13 -05:00
|
|
|
import styles from "./index.module.css";
|
|
|
|
|
|
|
|
|
|
export function TankopediaLoadout() {
|
|
|
|
|
const strings = useStrings();
|
|
|
|
|
|
2026-05-15 10:54:36 -05:00
|
|
|
const tank = useProtagonist();
|
2026-04-29 16:27:13 -05:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Section>
|
|
|
|
|
<Heading size="3">{strings.tanks.loadout.modules}</Heading>
|
|
|
|
|
|
|
|
|
|
<div className={styles.lines}>
|
|
|
|
|
{tank.tank!.upgrade_lines.map((line) => (
|
2026-05-11 17:00:30 -05:00
|
|
|
<Line
|
|
|
|
|
key={line.name}
|
2026-05-15 10:54:36 -05:00
|
|
|
name={line.name}
|
2026-05-11 17:00:30 -05:00
|
|
|
lines={tank.tank!.upgrade_lines}
|
|
|
|
|
/>
|
2026-04-29 16:27:13 -05:00
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
</Section>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface LineProps {
|
2026-05-15 10:54:36 -05:00
|
|
|
name: string;
|
2026-05-11 17:00:30 -05:00
|
|
|
lines: UpgradeLine[];
|
2026-04-29 16:27:13 -05:00
|
|
|
}
|
|
|
|
|
|
2026-05-11 17:00:30 -05:00
|
|
|
const mergeLines = {
|
|
|
|
|
alternative_guns: "guns",
|
|
|
|
|
} as Record<string, string>;
|
|
|
|
|
|
2026-05-15 10:54:36 -05:00
|
|
|
function Line({ name, lines }: LineProps) {
|
2026-05-11 17:00:30 -05:00
|
|
|
const combinedLines = useMemo(() => {
|
2026-05-15 10:54:36 -05:00
|
|
|
const names: string[] = [name];
|
2026-05-11 17:00:30 -05:00
|
|
|
|
|
|
|
|
for (const key in mergeLines) {
|
2026-05-15 10:54:36 -05:00
|
|
|
if (mergeLines[key] === name && lines.some((line) => line.name === key)) {
|
|
|
|
|
names.push(key);
|
2026-05-11 17:00:30 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-15 10:54:36 -05:00
|
|
|
return names;
|
|
|
|
|
}, [name]);
|
2026-04-29 16:27:13 -05:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className={styles.line}>
|
2026-05-15 10:54:36 -05:00
|
|
|
{!(name in mergeLines) &&
|
|
|
|
|
combinedLines.map((name) => (
|
|
|
|
|
<LineInner key={name} name={name} lines={lines} />
|
|
|
|
|
))}
|
2026-04-29 16:27:13 -05:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-05-11 17:00:30 -05:00
|
|
|
|
2026-05-15 10:54:36 -05:00
|
|
|
function LineInner({ name, lines }: LineProps) {
|
|
|
|
|
const line = lines.find((line) => line.name === name)!;
|
2026-05-11 17:00:30 -05:00
|
|
|
|
2026-05-15 10:54:36 -05:00
|
|
|
return line.stages.map((stage, index) => (
|
|
|
|
|
<LineElement key={index} index={index} lineName={name} stage={stage} />
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface LineElementProps {
|
|
|
|
|
index: number;
|
|
|
|
|
lineName: string;
|
|
|
|
|
stage: StageParameters;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function LineElement({ index, lineName, stage }: LineElementProps) {
|
|
|
|
|
const upgrades = Tankopedia.use((state) => state.protagonist.upgrades);
|
|
|
|
|
const tank = useProtagonist();
|
2026-05-11 17:00:30 -05:00
|
|
|
const strings = useStrings();
|
2026-05-15 10:54:36 -05:00
|
|
|
const upgradePreset = useUpgradePreset(tank.tank!.tank_upgrade_preset);
|
|
|
|
|
|
|
|
|
|
let price: StandardPrice | undefined;
|
|
|
|
|
|
|
|
|
|
switch (stage.grade) {
|
|
|
|
|
case Grade.GRADE_COMMON:
|
|
|
|
|
price = upgradePreset.common_grade_price;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Grade.GRADE_RARE:
|
|
|
|
|
price = upgradePreset.rare_grade_price;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Grade.GRADE_EPIC:
|
|
|
|
|
price = upgradePreset.unique_grade_price;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case Grade.GRADE_LEGENDARY:
|
|
|
|
|
price = upgradePreset.legendary_grade_price;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const override of upgradePreset.prices_overrides) {
|
|
|
|
|
if (override.stage_tech_name !== stage.tech_name) continue;
|
|
|
|
|
price = override.price;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isSelected = upgrades[lineName] === index;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<IconButton
|
|
|
|
|
color={isSelected ? undefined : "gray"}
|
|
|
|
|
variant={isSelected ? "surface" : "soft"}
|
|
|
|
|
radius="1"
|
|
|
|
|
className={styles.stage}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
Tankopedia.mutate((draft) => {
|
|
|
|
|
draft.protagonist.upgrades[lineName] = index;
|
|
|
|
|
|
|
|
|
|
for (const required of stage.required_upgrades) {
|
|
|
|
|
for (const line of tank.tank!.upgrade_lines) {
|
|
|
|
|
let i = 0;
|
2026-05-11 17:00:30 -05:00
|
|
|
|
2026-05-15 10:54:36 -05:00
|
|
|
for (const stage of line.stages) {
|
|
|
|
|
if (stage.tech_name === required) {
|
|
|
|
|
draft.protagonist.upgrades[line.name] = Math.max(
|
|
|
|
|
draft.protagonist.upgrades[line.name],
|
|
|
|
|
i,
|
|
|
|
|
);
|
2026-05-11 17:00:30 -05:00
|
|
|
}
|
2026-05-15 10:54:36 -05:00
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const line of tank.tank!.upgrade_lines) {
|
|
|
|
|
let i = draft.protagonist.upgrades[line.name];
|
2026-05-11 17:00:30 -05:00
|
|
|
|
2026-05-15 10:54:36 -05:00
|
|
|
while (i > 0) {
|
|
|
|
|
const currentStage = line.stages[i];
|
|
|
|
|
const valid = currentStage.required_upgrades.every((required) => {
|
2026-05-11 17:00:30 -05:00
|
|
|
for (const line of tank.tank!.upgrade_lines) {
|
2026-05-15 10:54:36 -05:00
|
|
|
const idx = draft.protagonist.upgrades[line.name];
|
|
|
|
|
|
|
|
|
|
if (line.stages[idx]?.tech_name === required) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-05-11 17:00:30 -05:00
|
|
|
|
2026-05-15 10:54:36 -05:00
|
|
|
return false;
|
|
|
|
|
});
|
2026-05-11 17:00:30 -05:00
|
|
|
|
2026-05-15 10:54:36 -05:00
|
|
|
if (valid) break;
|
2026-05-11 17:00:30 -05:00
|
|
|
|
2026-05-15 10:54:36 -05:00
|
|
|
i--;
|
|
|
|
|
}
|
2026-05-11 17:00:30 -05:00
|
|
|
|
2026-05-15 10:54:36 -05:00
|
|
|
draft.protagonist.upgrades[line.name] = i;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<img
|
|
|
|
|
className={styles.icon}
|
|
|
|
|
src={`/api/tanks/modules/${stage.stage_type}.webp`}
|
|
|
|
|
/>
|
|
|
|
|
{/* {stage.display_name} */}
|
2026-05-11 17:00:30 -05:00
|
|
|
|
2026-05-15 10:54:36 -05:00
|
|
|
<Text lowContrast size="minor" className={styles.tier}>
|
|
|
|
|
{lineName in mergeLines
|
|
|
|
|
? strings.tanks.loadout.alternative
|
|
|
|
|
: romanize(stage.number)}
|
|
|
|
|
</Text>
|
2026-05-11 17:00:30 -05:00
|
|
|
|
2026-05-15 10:54:36 -05:00
|
|
|
{price && <Price className={styles.price} price={price} />}
|
|
|
|
|
</IconButton>
|
|
|
|
|
);
|
2026-05-11 17:00:30 -05:00
|
|
|
}
|