migrate compare and tankopedia loadout to new data-driven components, splitting the old monolithic loadout and compare UI into smaller pieces and adding shared Table, Dialog and Scroller primitives

This commit is contained in:
tresabhi committed 2026-11-14 01:17:38 -06:00
1 parent 287aba853f
commit c311a6ab8b
111 files changed
+4009 -3917

No files matched your search

@@ -1,8 +1,14 @@
import sharp from "sharp";
import { vfs } from "../../../core/blitzkit/vfs";
export { getStaticPaths } from "../_index";
export async function GET() {
const bytes = await vfs.file("Data/Gfx/UI/Hangar/IconCamouflage.packed.webp");
return new Response(bytes);
const buffer = await sharp(
await vfs.file("Data/Gfx/UI/Hangar/IconCamouflage.packed.webp"),
)
.trim()
.toBuffer();
return new Response(new Uint8Array(buffer));
}
@@ -47,8 +47,6 @@ export const getStaticPaths = mixStaticPaths(_getStaticPaths, async () => {
),
);
console.log(consumable);
if (!styleSheet) {
console.warn(
`No style sheet found for consumable ${consumable.icon}; skipping...`,
@@ -0,0 +1,28 @@
.page {
/* Fixed to the viewport so the table scrolls, not the page */
height: 100dvh;
display: flex;
flex-direction: column;
align-items: center;
box-sizing: border-box;
.top {
display: flex;
flex-direction: column;
align-items: center;
gap: var(--space-4);
padding: var(--space-4);
}
.table {
flex: 1;
min-height: 0;
align-self: stretch;
overflow: hidden;
display: flex;
justify-content: center;
}
}
@@ -1,112 +1,55 @@
import { createDefaultSkills } from "@blitzkit/core";
import { useEffect, useMemo, useState } from "react";
import { createDefaultEnvironment } from "@blitzkit/core";
import { useEffect } from "react";
import { api } from "../../../../api/dynamic";
import { CompareTable } from "../../../../components/Compare/CompareTable";
import { Controls } from "../../../../components/Compare/Controls";
import { DamageWarning } from "../../../../components/DamageWarning";
import { tankCharacteristics } from "../../../../core/blitzkit/tankCharacteristics";
import { CompareControls } from "../../../../components/CompareControls";
import { CompareTable } from "../../../../components/CompareTable";
import { EmptyState } from "../../../../components/EmptyState";
import { tankToCompareMember } from "../../../../core/blitzkit/tankToCompareMember";
import {
type LocaleAcceptorProps,
LocaleProvider,
useLocale,
} from "../../../../hooks/useLocale";
import { withErrorWrapper } from "../../../../hocs/withErrorWrapper";
import { withLocale } from "../../../../hocs/withLocale";
import { useStrings } from "../../../../hooks/useStrings";
import { CompareEphemeral } from "../../../../stores/compareEphemeral";
import styles from "./_index.module.css";
const [
modelDefinitions,
equipmentDefinitions,
provisionDefinitions,
skillDefinitions,
tankDefinitions,
] = await Promise.all([
api.models(),
api.equipment(),
api.provisions(),
const [skillDefinitions, tankDefinitions] = await Promise.all([
api.skills(),
api.tanks(),
]);
export function Page({ locale }: LocaleAcceptorProps) {
CompareEphemeral.useInitialization(createDefaultSkills(skillDefinitions));
export const Page = withLocale(
withErrorWrapper(() => {
CompareEphemeral.useInitialization(
createDefaultEnvironment(skillDefinitions),
);
return (
<LocaleProvider locale={locale}>
<Content />
</LocaleProvider>
);
}
return <Content />;
}),
);
function Content() {
const strings = useStrings();
const members = CompareEphemeral.use((state) => state.members);
const equalize = CompareEphemeral.use((state) => state.equalize);
const [addTankDialogOpen, setAddTankDialogOpen] = useState(false);
const crewSkills = CompareEphemeral.use((state) => state.crewSkills);
const { strings } = useLocale();
const stats = useMemo<ReturnType<typeof tankCharacteristics>[]>(
() =>
members.map((thisMember) =>
tankCharacteristics(
{
...thisMember,
crewSkills,
stockEngine: thisMember.tank.engines[0],
stockGun: thisMember.tank.turrets[0].guns[0],
stockTrack: thisMember.tank.tracks[0],
stockTurret: thisMember.tank.turrets[0],
applyReactiveArmor: members.some(
(member) =>
member.key !== thisMember.key &&
member.consumables.includes(33),
),
applyDynamicArmor: members.some(
(member) =>
member.key !== thisMember.key &&
member.consumables.includes(73),
),
applySpallLiner: members.some(
(member) =>
member.key !== thisMember.key &&
member.provisions.includes(101),
),
assaultDistance: thisMember.assaultDistance,
equalize,
},
{
equipmentDefinitions: equipmentDefinitions,
provisionDefinitions: provisionDefinitions,
tankModelDefinition: modelDefinitions.models[thisMember.tank.id],
},
),
),
[members, crewSkills, equalize],
);
// Tanks come from the url on load
useEffect(() => {
const search = new URLSearchParams(window.location.search);
const tanksQuery = search.get("tanks");
const tanks = new URLSearchParams(window.location.search).get("tanks");
if (tanksQuery === null) return;
const tanks = tanksQuery.split(",").map(Number);
if (tanks === null) return;
CompareEphemeral.mutate((draft) => {
draft.members = [];
tanks.forEach((id) => {
const tank = tankDefinitions.tanks[id];
if (tank === undefined) return;
draft.members.push(tankToCompareMember(tank, provisionDefinitions));
});
draft.members = tanks
.split(",")
.map((id) => tankDefinitions.tanks[Number(id)])
.filter((tank) => tank !== undefined)
.map(tankToCompareMember);
});
}, []);
// ...and are written back whenever they change
useEffect(() => {
const search = new URLSearchParams(window.location.search);
search.set("tanks", members.map((member) => member.tank.id).join(","));
search.set("tanks", members.map(({ state }) => state.tank).join(","));
window.history.replaceState(
{},
@@ -116,36 +59,23 @@ function Content() {
}, [members]);
return (
<>
<Flex justify="center" gap="4" align="center" direction="column">
<DamageWarning />
<Controls
addTankDialogOpen={addTankDialogOpen}
onAddTankDialogOpenChange={setAddTankDialogOpen}
/>
</Flex>
<div className={styles.page}>
<div className={styles.top}>
<CompareControls />
</div>
{members.length > 0 && (
<Flex justify="center" flexGrow="1" position="relative">
<CompareTable stats={stats} />
</Flex>
<div className={styles.table}>
<CompareTable />
</div>
)}
{members.length === 0 && (
<Flex
align="center"
justify="center"
direction="column"
style={{ flex: 1 }}
>
<Heading color="gray">
{strings.website.tools.compare.no_tanks.title}
</Heading>
<Text color="gray">
{strings.website.tools.compare.no_tanks.body}
</Text>
</Flex>
<EmptyState
title={strings.compare.no_tanks.title}
body={strings.compare.no_tanks.body}
/>
)}
</>
</div>
);
}
@@ -1,6 +1,5 @@
---
import ToolOpenGraph from "../../../../components/ToolOpenGraph.astro";
import { tools } from "../../../../constants/tools";
import ColorScale from "../../../../components/ColorScale.astro";
import BaseLayout from "../../../../layouts/BaseLayout.astro";
import { Page } from "./_index";
@@ -9,8 +8,13 @@ export { getStaticPaths } from "../index.astro";
const { locale } = Astro.props;
---
<ToolOpenGraph {locale} tool={tools.compare} />
<BaseLayout accent="pink" {locale}>
<ColorScale color="red" />
<ColorScale color="red" alpha />
<ColorScale color="jade" />
<ColorScale color="amber" />
<ColorScale color="amber" alpha />
<ColorScale color="blue" />
<BaseLayout {locale} noFooter>
<Page {locale} client:load />
</BaseLayout>
@@ -5,7 +5,7 @@ import { GuessRenderer } from "../../../../components/GuessRenderer";
import { GuessRendererLoader } from "../../../../components/GuessRendererLoader";
import { withErrorWrapper } from "../../../../hocs/withErrorWrapper";
import { withLocale } from "../../../../hocs/withLocale";
import { DuelModule, useDuel } from "../../../../hooks/useDuel";
import { useDuelModules } from "../../../../hooks/useDuelModules";
import { Guess, GuessState } from "../../../../stores/guess";
import { Tankopedia } from "../../../../stores/tankopedia";
import { createTankState } from "../../../../tankopedia/createTankState";
@@ -42,12 +42,11 @@ function Container({ skeleton }: MaybeSkeletonComponentProps) {
}
function Content({ skeleton }: MaybeSkeletonComponentProps) {
const tank = useDuel("protagonist", DuelModule.Tank);
const protagonist = useDuelModules("protagonist");
const tiers = Guess.use((state) => state.tiers);
useEffect(() => {
const isTankAlreadyCompliant = tiers.includes(tank.tier);
const isTankAlreadyCompliant = tiers.includes(protagonist.tank.tier);
if (isTankAlreadyCompliant) return;
@@ -17,7 +17,6 @@
.content {
padding: var(--space-5);
padding-right: calc(var(--space-5) - var(--scrollbar-width));
display: flex;
flex-direction: column;
@@ -1,12 +1,15 @@
import { useMemo } from "react";
import { api } from "../../../../../api/dynamic";
import { Scroller } from "../../../../../components/Scroller";
import {
Scroller,
ScrollerOrientation,
} from "../../../../../components/Scroller";
import type { ThicknessRange } from "../../../../../components/TankStaticArmor";
import { TankopediaCharacteristics } from "../../../../../components/TankopediaCharacteristics";
import { TankopediaGameModeAbilities } from "../../../../../components/TankopediaGameModeAbilities";
import { TankopediaVideos } from "../../../../../components/TankopediaVideos";
import { TankopediaLoadout } from "../../../../../components/TankopediaLoadout";
import { TankopediaSandbox } from "../../../../../components/TankopediaSandbox";
import { TankopediaVideos } from "../../../../../components/TankopediaVideos";
import { defaultEqualizer } from "../../../../../config/equalizer";
import { withErrorWrapper } from "../../../../../hocs/withErrorWrapper";
import { withLocale } from "../../../../../hocs/withLocale";
@@ -37,7 +40,7 @@ export const Page = withErrorWrapper(
const thicknessRange = useMemo(() => {
const entries = Object.values(tanks.tanks);
const filtered = entries.filter(
(thisTank) => thisTank.tier === protagonistTank.tier,
(thisTank) => thisTank.tier === protagonistTank.tier
);
const value =
(filtered.reduce((accumulator, thisTank) => {
@@ -56,9 +59,12 @@ export const Page = withErrorWrapper(
return (
<div className={styles.page}>
<Scroller className={styles.loadout} orientation="vertical">
<Scroller
className={styles.loadout}
orientation={ScrollerOrientation.Vertical}
>
<div className={styles.content}>
<TankopediaLoadout characteristics={characteristics} />
<TankopediaLoadout />
</div>
</Scroller>
@@ -74,5 +80,5 @@ export const Page = withErrorWrapper(
</div>
</div>
);
}),
})
);