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

@@ -28,7 +28,7 @@ export interface CharacteristicRank {
score: number;
}
function rankingValue(
export function rankingValue(
name: CharacteristicName,
value?: CharacteristicReturnType,
) {
@@ -0,0 +1,14 @@
import { api } from "../api/dynamic";
import type { TankState } from "./tankState";
const models = await api.models();
// Turns the ids held in a tank state into their model definitions
export function resolveTankModels(state: TankState) {
const tank = models.models[state.tank];
const turret = tank.turrets[state.turret];
const gun = turret.guns[state.gun];
const track = tank.tracks[state.track];
return { tank, turret, gun, track };
}
@@ -0,0 +1,17 @@
import { api } from "../api/dynamic";
import type { TankState } from "./tankState";
const tanks = await api.tanks();
// Turns the ids held in a tank state into their definitions
export function resolveTankModules(state: TankState) {
// TODO: consider changing array to a map just like modules
const tank = tanks.tanks[state.tank];
const turret = tank.turrets.find(({ id }) => id === state.turret)!;
const gun = turret.guns.find(({ id }) => id === state.gun)!;
const shell = gun.shells.find(({ id }) => id === state.shell)!;
const engine = tank.engines.find(({ id }) => id === state.engine)!;
const track = tank.tracks.find(({ id }) => id === state.track)!;
return { tank, turret, gun, shell, engine, track };
}
@@ -0,0 +1,48 @@
import { ModuleType, type TankDefinition, type Unlock } from "@blitzkit/protos";
import type { TankState } from "./tankState";
type ModuleState = Pick<
TankState,
"turret" | "gun" | "shell" | "engine" | "track"
>;
// Selecting a turret or gun may force the other to change with it
export function selectModule(
draft: ModuleState,
tank: TankDefinition,
unlock: Unlock,
) {
switch (unlock.type) {
case ModuleType.MODULE_TYPE_TURRET: {
const turret = tank.turrets.find((t) => t.id === unlock.id)!;
const gun =
turret.guns.find((g) => g.id === draft.gun) ?? turret.guns.at(-1)!;
draft.turret = turret.id;
draft.gun = gun.id;
draft.shell = gun.shells[0].id;
break;
}
case ModuleType.MODULE_TYPE_GUN: {
const current = tank.turrets.find((t) => t.id === draft.turret)!;
const turret = current.guns.some((g) => g.id === unlock.id)
? current
: tank.turrets.find((t) => t.guns.some((g) => g.id === unlock.id))!;
const gun = turret.guns.find((g) => g.id === unlock.id)!;
draft.turret = turret.id;
draft.gun = gun.id;
draft.shell = gun.shells[0].id;
break;
}
case ModuleType.MODULE_TYPE_ENGINE:
draft.engine = unlock.id;
break;
case ModuleType.MODULE_TYPE_TRACKS:
draft.track = unlock.id;
break;
}
}