From c6b7918525b7bf3b72743e1b1152c25c5ffa50f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Thu, 18 Dec 2025 16:45:02 -0600 Subject: [PATCH] feat: shells --- .../src/core/tankopedia/characteristics.ts | 30 +++++++---------- .../core/tankopedia/computeCharacteristics.ts | 19 ++++++++--- .../website-ue/src/layouts/BaseLayout.astro | 9 +++++ .../src/pages/tanks/[slug]/_index.tsx | 33 ++++++++++++++++--- .../src/pages/tanks/[slug]/index.astro | 5 ++- 5 files changed, 69 insertions(+), 27 deletions(-) create mode 100644 packages/website-ue/src/layouts/BaseLayout.astro diff --git a/packages/website-ue/src/core/tankopedia/characteristics.ts b/packages/website-ue/src/core/tankopedia/characteristics.ts index 37ce5e4ed..c15bdfe0c 100644 --- a/packages/website-ue/src/core/tankopedia/characteristics.ts +++ b/packages/website-ue/src/core/tankopedia/characteristics.ts @@ -6,18 +6,10 @@ import { export type CharacteristicOutput = number | null; type Characteristic = (helpers: { - characteristic: ( - name: CharacteristicName, - error?: boolean - ) => CharacteristicOutput; - attribute: ( - name: TankAttributeChange_AttributeName, - error?: boolean - ) => number; - shell: ( - name: ShellUpgrageSingleChange_AttributeName, - error?: boolean - ) => number; + characteristic: (name: CharacteristicName) => CharacteristicOutput; + attribute: (name: TankAttributeChange_AttributeName) => number; + shell: (name: ShellUpgrageSingleChange_AttributeName) => number; + shellSafe: (name: ShellUpgrageSingleChange_AttributeName) => number | null; }) => CharacteristicOutput; export type CharacteristicName = keyof typeof characteristics; @@ -96,8 +88,8 @@ export const characteristics = { return shell(ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_CALIBER); }, - normalization({ shell }) { - return shell( + normalization({ shellSafe }) { + return shellSafe( ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_NORMALIZATION ); }, @@ -112,15 +104,17 @@ export const characteristics = { return shell(ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_SPEED); }, - shell_range({ shell }) { - return shell( + shell_range({ shellSafe }) { + const maxDistance = shellSafe( ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_MAX_DISTANCE ); + return maxDistance === null ? Infinity : maxDistance; }, - shell_capacity({ shell }) { - return shell( + shell_capacity({ shellSafe }) { + const count = shellSafe( ShellUpgrageSingleChange_AttributeName.ATTRIBUTE_NAME_MAX_COUNT ); + return count === -1 || count === null ? Infinity : count; }, } satisfies Record; diff --git a/packages/website-ue/src/core/tankopedia/computeCharacteristics.ts b/packages/website-ue/src/core/tankopedia/computeCharacteristics.ts index cc7d59713..4d60b3328 100644 --- a/packages/website-ue/src/core/tankopedia/computeCharacteristics.ts +++ b/packages/website-ue/src/core/tankopedia/computeCharacteristics.ts @@ -36,7 +36,7 @@ export function computeCharacteristics( return attribute.value; } - function shell(name: ShellUpgrageSingleChange_AttributeName) { + function shellSafe(name: ShellUpgrageSingleChange_AttributeName) { const shell = parameters.shells_upgrades.find( (shell) => shell.shell_id === state.shell ); @@ -51,18 +51,29 @@ export function computeCharacteristics( (change) => change.attribute_name === name ); - if (!attribute) { + return attribute ? attribute.value : null; + } + + function shell(name: ShellUpgrageSingleChange_AttributeName) { + const attribute = shellSafe(name); + + if (attribute === null) { throw new Error( `Shell attribute ${ShellUpgrageSingleChange_AttributeName[name]} (${name}) not found` ); } - return attribute.value; + return attribute; } for (const _name in characteristics) { const name = _name as CharacteristicName; - const value = characteristics[name]({ characteristic, attribute, shell }); + const value = characteristics[name]({ + characteristic, + attribute, + shell, + shellSafe, + }); computed[name] = value; } diff --git a/packages/website-ue/src/layouts/BaseLayout.astro b/packages/website-ue/src/layouts/BaseLayout.astro new file mode 100644 index 000000000..2fcdb01e5 --- /dev/null +++ b/packages/website-ue/src/layouts/BaseLayout.astro @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/packages/website-ue/src/pages/tanks/[slug]/_index.tsx b/packages/website-ue/src/pages/tanks/[slug]/_index.tsx index 2ca6d1290..03b96902f 100644 --- a/packages/website-ue/src/pages/tanks/[slug]/_index.tsx +++ b/packages/website-ue/src/pages/tanks/[slug]/_index.tsx @@ -35,6 +35,8 @@ function Content({ id }: { id: string }) { return ( <> +

{id}

+
{times(tank.upgrade_stages.length, (index) => ( + ))} +
+ {characteristicsGroups.map(({ group, order }) => ( <> -

{group}

+

{group}

{order.map((entry) => { if ("toy" in entry) { @@ -64,12 +84,17 @@ function Content({ id }: { id: string }) { let rendered: string | number = characteristic; if (typeof rendered === "number") { - if (entry.decimals !== undefined) - rendered = rendered.toFixed(entry.decimals); + if (rendered === Infinity) { + rendered = "∞"; + } else { + if (entry.decimals !== undefined) { + rendered = rendered.toFixed(entry.decimals); + } + } } return ( -

+

{entry.name}: {rendered}

); diff --git a/packages/website-ue/src/pages/tanks/[slug]/index.astro b/packages/website-ue/src/pages/tanks/[slug]/index.astro index 9bf18209b..a9734d7fb 100644 --- a/packages/website-ue/src/pages/tanks/[slug]/index.astro +++ b/packages/website-ue/src/pages/tanks/[slug]/index.astro @@ -1,6 +1,7 @@ --- import type { GetStaticPaths } from "astro"; import { api } from "../../../core/api/dynamic"; +import BaseLayout from "../../../layouts/BaseLayout.astro"; import { Page } from "./_index"; export const getStaticPaths = (async () => { @@ -15,4 +16,6 @@ export const getStaticPaths = (async () => { const { id } = Astro.props; --- - + + +