diff --git a/packages/website-ue/astro.config.ts b/packages/website-ue/astro.config.ts index aaf08b1d2..32be19137 100644 --- a/packages/website-ue/astro.config.ts +++ b/packages/website-ue/astro.config.ts @@ -8,7 +8,7 @@ import AstroPWA from "@vite-pwa/astro"; import favicons from "astro-favicons"; import { defineConfig } from "astro/config"; import packageJSON from "../../package.json"; -import { tools } from "./src/constants/tools"; +import { tools } from "./src/core/tools/tools"; const POSSIBLE_TARGETS = ["app", "web"]; diff --git a/packages/website-ue/src/core/blitz/aggregateStages.ts b/packages/website-ue/src/core/tankopedia/aggregateStageParameters.ts similarity index 99% rename from packages/website-ue/src/core/blitz/aggregateStages.ts rename to packages/website-ue/src/core/tankopedia/aggregateStageParameters.ts index 8fbebadcf..d95ee6b01 100644 --- a/packages/website-ue/src/core/blitz/aggregateStages.ts +++ b/packages/website-ue/src/core/tankopedia/aggregateStageParameters.ts @@ -183,7 +183,7 @@ function patch(stage0: StageParameters, stage1: StageParameters) { } } -export function aggregateStages( +export function aggregateStageParameters( base: StageParameters, stages: StageParameters[], stage: number diff --git a/packages/website-ue/src/constants/characteristics.ts b/packages/website-ue/src/core/tankopedia/characteristics.ts similarity index 50% rename from packages/website-ue/src/constants/characteristics.ts rename to packages/website-ue/src/core/tankopedia/characteristics.ts index feec52090..7d2702fc5 100644 --- a/packages/website-ue/src/constants/characteristics.ts +++ b/packages/website-ue/src/core/tankopedia/characteristics.ts @@ -3,31 +3,21 @@ import { TankAttributeChange_AttributeName, } from "@protos/blitz_static_tank_upgrade_single_stage"; -export enum CharacteristicsGroup { - Firepower = "firepower", - Maneuverability = "maneuverability", - Survivability = "survivability", - Miscellaneous = "miscellaneous", -} +export type CharacteristicOutput = number | string | null; interface Characteristic { - render: (helpers: { - characteristic: (name: CharacteristicName) => number; + value: (helpers: { + characteristic: (name: CharacteristicName) => CharacteristicOutput; attribute: (name: TankAttributeChange_AttributeName) => number; shell: (name: ShellUpgrageSingleChange_AttributeName) => number; - }) => number | string | null; + }) => CharacteristicOutput; } -type CharacteristicName = keyof typeof characteristics; - -type CharacteristicsOrder = { - group: CharacteristicsGroup; - characteristics: CharacteristicName[]; -}[]; +export type CharacteristicName = keyof typeof characteristics; export const characteristics = { gun_type: { - render({ attribute }) { + value({ attribute }) { const isPump = attribute( TankAttributeChange_AttributeName.ATTRIBUTE_NAME_IS_PUMP ); @@ -45,7 +35,7 @@ export const characteristics = { }, damage: { - render({ shell }) { + value({ shell }) { return shell( ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_ARMOR_DAMAGE ); @@ -53,29 +43,10 @@ export const characteristics = { }, dpm: { - render({ characteristic }) { + value({ characteristic }) { const damage = characteristic("damage"); return 1; }, }, } satisfies Record; - -export const characteristicsOrder: CharacteristicsOrder = [ - { - group: CharacteristicsGroup.Firepower, - characteristics: ["gun_type", "dpm"], - }, - { - group: CharacteristicsGroup.Maneuverability, - characteristics: [], - }, - { - group: CharacteristicsGroup.Survivability, - characteristics: [], - }, - { - group: CharacteristicsGroup.Miscellaneous, - characteristics: [], - }, -]; diff --git a/packages/website-ue/src/core/tankopedia/characteristicsGroups.ts b/packages/website-ue/src/core/tankopedia/characteristicsGroups.ts new file mode 100644 index 000000000..8ee6689e1 --- /dev/null +++ b/packages/website-ue/src/core/tankopedia/characteristicsGroups.ts @@ -0,0 +1,25 @@ +import type { CharacteristicName } from "./characteristics"; + +type CharacteristicsOrder = { + group: string; + order: CharacteristicName[]; +}[]; + +export const characteristicsGroups = [ + { + group: "firepower", + order: ["gun_type", "dpm"], + }, + { + group: "maneuverability", + order: [], + }, + { + group: "survivability", + order: [], + }, + { + group: "miscellaneous", + order: [], + }, +] satisfies CharacteristicsOrder; diff --git a/packages/website-ue/src/core/tankopedia/renderCharacteristics.ts b/packages/website-ue/src/core/tankopedia/renderCharacteristics.ts new file mode 100644 index 000000000..2c74b9e16 --- /dev/null +++ b/packages/website-ue/src/core/tankopedia/renderCharacteristics.ts @@ -0,0 +1,56 @@ +import type { + ShellUpgrageSingleChange_AttributeName, + StageParameters, + TankAttributeChange_AttributeName, +} from "@protos/blitz_static_tank_upgrade_single_stage"; +import { + characteristics, + type CharacteristicName, + type CharacteristicOutput, +} from "./characteristics"; + +export function renderCharacteristics( + parameters: StageParameters, + shellId: number +) { + const computed: Partial> = + {}; + + function characteristic(name: CharacteristicName) { + if (name in computed) return computed[name] as CharacteristicOutput; + throw new Error(`${name} not computed yet`); + } + + function attribute(name: TankAttributeChange_AttributeName) { + const attribute = parameters.attributes.find( + (attribute) => attribute.attribute_name === name + ); + + if (!attribute) throw new Error(`Attribute ${name} not found`); + (""); + + return attribute.value; + } + + function shell(name: ShellUpgrageSingleChange_AttributeName) { + const shell = parameters.shells_upgrades.find( + (shell) => shell.shell_id === name + ); + + if (!shell) throw new Error(`Shell ${name} not found`); + + const attribute = shell.changes.find( + (change) => change.attribute_name === name + ); + + if (!attribute) throw new Error(`Shell attribute ${name} not found`); + + return attribute.value; + } + + for (const _name in characteristics) { + const name = _name as CharacteristicName; + const _characteristic = characteristics[name]; + const value = _characteristic.value({ characteristic, attribute, shell }); + } +} diff --git a/packages/website-ue/src/constants/tools.ts b/packages/website-ue/src/core/tools/tools.ts similarity index 100% rename from packages/website-ue/src/constants/tools.ts rename to packages/website-ue/src/core/tools/tools.ts diff --git a/packages/website-ue/src/pages/api/tanks/characteristics/order.json.ts b/packages/website-ue/src/pages/api/tanks/characteristics/order.json.ts index 6165a752f..7249cd392 100644 --- a/packages/website-ue/src/pages/api/tanks/characteristics/order.json.ts +++ b/packages/website-ue/src/pages/api/tanks/characteristics/order.json.ts @@ -1,4 +1,4 @@ -import { _characteristicsOrder } from "../../../../constants/characteristics"; +import { _characteristicsOrder } from "../../../../core/tankopedia/characteristics"; export function GET() { return Response.json(_characteristicsOrder); diff --git a/packages/website-ue/src/pages/tanks/[slug]/_index.tsx b/packages/website-ue/src/pages/tanks/[slug]/_index.tsx index 31816b2ea..76359aa40 100644 --- a/packages/website-ue/src/pages/tanks/[slug]/_index.tsx +++ b/packages/website-ue/src/pages/tanks/[slug]/_index.tsx @@ -1,7 +1,8 @@ import { times } from "lodash-es"; import { Suspense, useMemo } from "react"; import { api } from "../../../core/api/dynamic"; -import { aggregateStages } from "../../../core/blitz/aggregateStages"; +import { aggregateStageParameters } from "../../../core/tankopedia/aggregateStageParameters"; +import { characteristics } from "../../../core/tankopedia/characteristics"; import { useAwait } from "../../../hooks/useAwait"; import { Tankopedia } from "../../../stores/tankopedia"; @@ -18,7 +19,8 @@ function Content({ id }: { id: string }) { const stage = Tankopedia.use((state) => state.stage); const parameters = useMemo( - () => aggregateStages(tank.base_stats!, tank.upgrade_stages, stage), + () => + aggregateStageParameters(tank.base_stats!, tank.upgrade_stages, stage), [stage] ); @@ -39,26 +41,17 @@ function Content({ id }: { id: string }) { ))} -
-      

{tank.name?.value}

- -

Characteristics

- - {/* {_characteristicsOrder.map((group) => ( + {characteristicsOrder.map(({ group, order }) => ( <> -

{CharacteristicsGroup[group.group]}

+

{group}

- {group.attributes.map( - (attribute) => - attribute.name in attributes && ( -

- {TankAttributeChange_AttributeName[attribute.name]}:{" "} - {attributes[attribute.name]} -

- ) - )} + {order.map((name) => { + const characteristic = characteristics[name]; + + return {}; + })} - ))} */} + ))} ); }