diff --git a/packages/website-ue/src/components/TankopediaLoadout/index.tsx b/packages/website-ue/src/components/TankopediaLoadout/index.tsx index a92a3ad85..c3cbf5e03 100644 --- a/packages/website-ue/src/components/TankopediaLoadout/index.tsx +++ b/packages/website-ue/src/components/TankopediaLoadout/index.tsx @@ -11,7 +11,6 @@ import { CornerBottomLeftIcon, DoubleArrowLeftIcon, DoubleArrowRightIcon, - ExclamationTriangleIcon, ResetIcon, TrashIcon, } from "@radix-ui/react-icons"; @@ -34,6 +33,7 @@ import { useTierPrices } from "../../hooks/useTierPrices"; import { useUpgradePreset } from "../../hooks/useUpgradePreset"; import { Tankopedia } from "../../stores/tankopedia"; import type { ComputedCharacteristics } from "../../tankopedia/computeCharacteristics"; +import { vehicleStatusKeys } from "../../tankopedia/tankState"; import { Button } from "../Button"; import { Heading } from "../Heading"; import { IconButton } from "../IconButton"; @@ -65,19 +65,7 @@ export function TankopediaLoadout({ characteristics }: TankopediaLoadoutProps) { function State() { const strings = useStrings(); - const isShooting = Tankopedia.use((state) => state.protagonist.isShooting); - const isGunDamaged = Tankopedia.use( - (state) => state.protagonist.isGunDamaged, - ); - const isTurretTraversing = Tankopedia.use( - (state) => state.protagonist.isTurretTraversing, - ); - const isHullTraversing = Tankopedia.use( - (state) => state.protagonist.isHullTraversing, - ); - const isCaughtOnFire = Tankopedia.use( - (state) => state.protagonist.isCaughtOnFire, - ); + const status = Tankopedia.use((state) => state.protagonist.status); return (
@@ -97,78 +85,22 @@ function State() {
- { - Tankopedia.mutate((draft) => { - draft.protagonist.isShooting = !draft.protagonist.isShooting; - }); - }} - > - - - - { - Tankopedia.mutate((draft) => { - draft.protagonist.isGunDamaged = !draft.protagonist.isGunDamaged; - }); - }} - > - - - - { - Tankopedia.mutate((draft) => { - draft.protagonist.isTurretTraversing = - !draft.protagonist.isTurretTraversing; - }); - }} - > - - - - { - Tankopedia.mutate((draft) => { - draft.protagonist.isHullTraversing = - !draft.protagonist.isHullTraversing; - }); - }} - > - - - - { - Tankopedia.mutate((draft) => { - draft.protagonist.isCaughtOnFire = - !draft.protagonist.isCaughtOnFire; - }); - }} - > - - + {vehicleStatusKeys.map((key) => ( + { + Tankopedia.mutate((draft) => { + draft.protagonist.status[key] = !draft.protagonist.status[key]; + }); + }} + > + + + ))}
); diff --git a/packages/website-ue/src/tankopedia/createTankState.ts b/packages/website-ue/src/tankopedia/createTankState.ts index 55f256997..24fbd5850 100644 --- a/packages/website-ue/src/tankopedia/createTankState.ts +++ b/packages/website-ue/src/tankopedia/createTankState.ts @@ -1,6 +1,11 @@ import type { Tank } from "@protos/tank"; import { alternativeLines } from "../config/modules"; -import { TerrainHardness, type TankState } from "./tankState"; +import { + TerrainHardness, + vehicleStatusKeys, + type TankState, + type VehicleStatusKey, +} from "./tankState"; export function createTankState({ tank, id }: Tank) { const upgrades: Record = {}; @@ -19,6 +24,12 @@ export function createTankState({ tank, id }: Tank) { } } + const status: Partial> = {}; + + for (const key of vehicleStatusKeys) { + status[key] = false; + } + return { id, @@ -32,10 +43,6 @@ export function createTankState({ tank, id }: Tank) { speed: 0, terrainHardness: TerrainHardness.Hard, - isShooting: false, - isGunDamaged: false, - isTurretTraversing: false, - isHullTraversing: false, - isCaughtOnFire: false, + status: status as Record, } satisfies TankState; } diff --git a/packages/website-ue/src/tankopedia/tankState.ts b/packages/website-ue/src/tankopedia/tankState.ts index 47fe10533..11851e44b 100644 --- a/packages/website-ue/src/tankopedia/tankState.ts +++ b/packages/website-ue/src/tankopedia/tankState.ts @@ -17,9 +17,27 @@ export interface TankState { speed: number; terrainHardness: TerrainHardness; - isShooting: boolean; - isGunDamaged: boolean; - isTurretTraversing: boolean; - isHullTraversing: boolean; - isCaughtOnFire: boolean; + status: Record; } + +export const vehicleStatusKeys = [ + "commander_dead", + "gunner_dead", + "driver_dead", + "loader_dead", + + "fuel_tank_damaged", + "engine_damaged", + "chassis_damaged", + "viewport_damaged", + "ammo_bay_damaged", + "gun_damaged", + "turret_damaged", + + "caught_on_fire", + "shooting", + "turret_traversing", + "hull_traversing", +] as const; + +export type VehicleStatusKey = (typeof vehicleStatusKeys)[number];