diff --git a/packages/website-ue/src/core/tankopedia/characteristics.ts b/packages/website-ue/src/core/tankopedia/characteristics.ts index 9259327d7..630c63dca 100644 --- a/packages/website-ue/src/core/tankopedia/characteristics.ts +++ b/packages/website-ue/src/core/tankopedia/characteristics.ts @@ -1,5 +1,7 @@ +import type { TankCatalogComponent } from "@protos/blitz_static_tank_component"; import { ShellUpgrageSingleChange_AttributeName, + StageParameters, TankAttributeChange_AttributeName, } from "@protos/blitz_static_tank_upgrade_single_stage"; import type { TankState } from "./tankState"; @@ -13,6 +15,8 @@ type Characteristic = (helpers: { shell: (name: ShellUpgrageSingleChange_AttributeName) => number; shellSafe: (name: ShellUpgrageSingleChange_AttributeName) => number | null; state: TankState; + tank: TankCatalogComponent; + parameters: StageParameters; }) => CharacteristicOutput; export type CharacteristicName = keyof typeof characteristics; @@ -208,20 +212,24 @@ export const characteristics = { ); }, - gun_depression({ attributeSafe }) { - return ( - attributeSafe( - TankAttributeChange_AttributeName.ATTRIBUTE_NAME_PITCH_LIMIT_DOWN - ) ?? -Infinity + gun_depression({ parameters }) { + const pitchLimit = parameters.pitch_limits_down.find( + (pitchLimit) => pitchLimit.angle === 0 ); + + if (!pitchLimit) throw new Error("No angle 0 depression pitch limit found"); + + return pitchLimit.limit; }, - gun_elevation({ attributeSafe }) { - return ( - attributeSafe( - TankAttributeChange_AttributeName.ATTRIBUTE_NAME_PITCH_LIMIT_UP - ) ?? -Infinity + gun_elevation({ parameters }) { + const pitchLimit = parameters.pitch_limits_up.find( + (pitchLimit) => pitchLimit.angle === 0 ); + + if (!pitchLimit) throw new Error("No angle 0 elevation pitch limit found"); + + return pitchLimit.limit; }, engine_power({ attribute }) { diff --git a/packages/website-ue/src/core/tankopedia/computeCharacteristics.ts b/packages/website-ue/src/core/tankopedia/computeCharacteristics.ts index 0fc573eb8..90027a518 100644 --- a/packages/website-ue/src/core/tankopedia/computeCharacteristics.ts +++ b/packages/website-ue/src/core/tankopedia/computeCharacteristics.ts @@ -1,8 +1,9 @@ +import type { TankCatalogComponent } from "@protos/blitz_static_tank_component"; import { ShellUpgrageSingleChange_AttributeName, TankAttributeChange_AttributeName, - type StageParameters, } from "@protos/blitz_static_tank_upgrade_single_stage"; +import { aggregateStageParameters } from "./aggregateStageParameters"; import { characteristics, type CharacteristicName, @@ -11,9 +12,14 @@ import { import type { TankState } from "./tankState"; export function computeCharacteristics( - parameters: StageParameters, + tank: TankCatalogComponent, state: TankState ) { + const parameters = aggregateStageParameters( + tank.base_stats!, + tank.upgrade_stages.slice(0, state.stage) + ); + const computed: Partial> = {}; @@ -81,9 +87,17 @@ export function computeCharacteristics( shell, shellSafe, state, + tank, + parameters, }); computed[name] = value; } - return computed as Record; + return { + characteristics: computed as Record< + CharacteristicName, + CharacteristicOutput + >, + parameters, + }; } diff --git a/packages/website-ue/src/pages/tanks/[slug]/_index.tsx b/packages/website-ue/src/pages/tanks/[slug]/_index.tsx index 46f56c86a..8832484f9 100644 --- a/packages/website-ue/src/pages/tanks/[slug]/_index.tsx +++ b/packages/website-ue/src/pages/tanks/[slug]/_index.tsx @@ -1,7 +1,6 @@ import { times } from "lodash-es"; import { Suspense, useMemo } from "react"; import { api } from "../../../core/api/dynamic"; -import { aggregateStageParameters } from "../../../core/tankopedia/aggregateStageParameters"; import { characteristicsOrder } from "../../../core/tankopedia/characteristicsOrder"; import { computeCharacteristics } from "../../../core/tankopedia/computeCharacteristics"; import { useAwait } from "../../../hooks/useAwait"; @@ -21,16 +20,8 @@ function Content({ id }: { id: string }) { Tankopedia.useInitialization(tank.upgrade_stages.length); const protagonist = Tankopedia.use((state) => state.protagonist); - const parameters = useMemo( - () => - aggregateStageParameters( - tank.base_stats!, - tank.upgrade_stages.slice(0, protagonist.stage) - ), - [protagonist] - ); - const characteristics = useMemo( - () => computeCharacteristics(parameters, protagonist), + const { characteristics, parameters } = useMemo( + () => computeCharacteristics(tank, protagonist), [protagonist] ); @@ -77,7 +68,7 @@ function Content({ id }: { id: string }) { {order.map((entry) => { if ("toy" in entry) { - return

toy: {entry.toy}

; + return

toy: {entry.toy}

; } else { const characteristic = characteristics[entry.name]; @@ -96,7 +87,7 @@ function Content({ id }: { id: string }) { } return ( -

+

{entry.name}: {rendered} {entry.units && `${entry.units}`}

); diff --git a/packages/website-ue/src/stores/tankopedia.ts b/packages/website-ue/src/stores/tankopedia.ts index 80b7740eb..209acc48d 100644 --- a/packages/website-ue/src/stores/tankopedia.ts +++ b/packages/website-ue/src/stores/tankopedia.ts @@ -6,5 +6,13 @@ interface Tankopedia { } export const Tankopedia = new Varuna((maxStage) => ({ - protagonist: { stage: maxStage, shell: 0 }, + protagonist: { + stage: maxStage, + shell: 0, + isGunDamaged: false, + isHullTraversing: false, + isShooting: false, + isTurretTraversing: false, + speed: 0, + }, }));