diff --git a/packages/website/src/components/TankopediaLoadout/index.tsx b/packages/website/src/components/TankopediaLoadout/index.tsx index 71bd8b29d..80746c99f 100644 --- a/packages/website/src/components/TankopediaLoadout/index.tsx +++ b/packages/website/src/components/TankopediaLoadout/index.tsx @@ -1,3 +1,4 @@ +import { useProtagonist } from "../../hooks/useProtagonist"; import type { ComputedCharacteristics } from "../../types/characteristics"; interface TankopediaLoadoutProps { diff --git a/packages/website/src/hooks/useProtagonist.ts b/packages/website/src/hooks/useProtagonist.ts new file mode 100644 index 000000000..5f471a3f1 --- /dev/null +++ b/packages/website/src/hooks/useProtagonist.ts @@ -0,0 +1,10 @@ +import { api } from "../blitzkit/api"; +import { Tankopedia } from "../stores/tankopedia"; +import { useAwait } from "./useAwait"; + +export function useProtagonist() { + const id = Tankopedia.use((state) => state.protagonist.tank); + const tank = useAwait(() => api.tank(id), `tank-${id}`); + + return tank; +} diff --git a/packages/website/src/stores/tankopedia.ts b/packages/website/src/stores/tankopedia.ts index bd5fabaf7..35e06fc7e 100644 --- a/packages/website/src/stores/tankopedia.ts +++ b/packages/website/src/stores/tankopedia.ts @@ -1,11 +1,7 @@ import { createDefaultSkills, - EngineDefinition, - GunDefinition, ShellDefinition, TankDefinition, - TrackDefinition, - TurretDefinition, type ModelDefinition, } from "@blitzkit/core"; import type { Vector3 } from "three"; @@ -14,8 +10,10 @@ import { api } from "../blitzkit/api"; import type { ArmorType } from "../components/Armor/components/SpacedArmorScene"; import type { ExternalModuleVariant } from "../components/Armor/components/SpacedArmorSceneComponent"; import type { XP_MULTIPLIERS } from "../components/Tankopedia/TechTreeSection"; -import { createTankState } from "../tankopedia/createTankState"; -import type { EquipmentMatrix } from "./duel"; +import { + createTankState, + type EquipmentMatrix, +} from "../tankopedia/createTankState"; import { TankopediaDisplay } from "./tankopediaPersistent/constants"; export interface ShotLayerBase { @@ -84,14 +82,15 @@ export enum TankopediaRelativeAgainst { } export interface TankState { - tank: TankDefinition; - model: ModelDefinition; + tank: number; - engine: EngineDefinition; - turret: TurretDefinition; - gun: GunDefinition; - shell: ShellDefinition; - track: TrackDefinition; + engine: number; + turret: number; + gun: number; + shell: number; + track: number; + + model: ModelDefinition; equipment_matrix: EquipmentMatrix; diff --git a/packages/website/src/tankopedia/createTankState.ts b/packages/website/src/tankopedia/createTankState.ts index d7cf5ce41..eb8140f08 100644 --- a/packages/website/src/tankopedia/createTankState.ts +++ b/packages/website/src/tankopedia/createTankState.ts @@ -1,8 +1,13 @@ import { createDefaultProvisions, type TankDefinition } from "@blitzkit/core"; import { api } from "../blitzkit/api"; -import type { EquipmentMatrix } from "../stores/duel"; import type { TankState } from "../stores/tankopedia"; +export type EquipmentMatrix = [ + [number, number, number], + [number, number, number], + [number, number, number], +]; + const models = await api.models(); const provisions = await api.provisions(); const scripts = await api.scripts(); @@ -18,14 +23,14 @@ export function createTankState(tank: TankDefinition) { const gun = turret.guns.at(-1)!; return { - tank, + tank: tank.id, model: models.models[turret.id], - engine: tank.engines.at(-1)!, - turret, - gun, - shell: gun.shells[0], - track: tank.tracks.at(-1)!, + engine: tank.engines.at(-1)!.id, + turret: turret.id, + gun: gun.id, + shell: gun.shells[0].id, + track: tank.tracks.at(-1)!.id, equipment_matrix: genericDefaultEquipmentMatrix,