From 371dcad568a41d176ed13cd44431ced09946f8d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Wed, 10 Jan 2024 17:57:41 -0600 Subject: [PATCH] feat: shell swapping --- .../components/Model/components/TankArmor.tsx | 7 +- .../tankopedia/[id]/components/VersusBar.tsx | 82 +++++++++--------- src/components/ModuleButton.tsx | 86 +++++++++++++------ src/core/blitz/numericPenetration.ts | 5 ++ 4 files changed, 107 insertions(+), 73 deletions(-) create mode 100644 src/core/blitz/numericPenetration.ts diff --git a/src/app/tools/tankopedia/[id]/components/Model/components/TankArmor.tsx b/src/app/tools/tankopedia/[id]/components/Model/components/TankArmor.tsx index e8613130f..2f1a6bcf0 100644 --- a/src/app/tools/tankopedia/[id]/components/Model/components/TankArmor.tsx +++ b/src/app/tools/tankopedia/[id]/components/Model/components/TankArmor.tsx @@ -5,6 +5,7 @@ import { GLTFLoader } from 'three-stdlib'; import { ArmorMesh } from '../../../../../../../components/ArmorMesh'; import { HeadsUpDisplay } from '../../../../../../../components/HeadsUpDisplay'; import { X_AXIS } from '../../../../../../../constants/axis'; +import { numericPenetration } from '../../../../../../../core/blitz/numericPenetration'; import { asset } from '../../../../../../../core/blitzkrieg/asset'; import { ModelDefinitions, @@ -97,7 +98,7 @@ export function TankArmor(props: TankArmorProps) { key={node.uuid} geometry={(node as Mesh).geometry} thickness={thickness} - penetration={252} + penetration={numericPenetration(antagonist.shell.penetration)} ricochet={antagonist.shell.ricochet} caliber={antagonist.shell.caliber} normalization={antagonist.shell.normalization} @@ -123,7 +124,7 @@ export function TankArmor(props: TankArmorProps) { position={turretOrigin} geometry={(node as Mesh).geometry} thickness={thickness} - penetration={252} + penetration={numericPenetration(antagonist.shell.penetration)} ricochet={antagonist.shell.ricochet} caliber={antagonist.shell.caliber} normalization={antagonist.shell.normalization} @@ -155,7 +156,7 @@ export function TankArmor(props: TankArmorProps) { position={turretOrigin.clone().add(gunOrigin)} geometry={(node as Mesh).geometry} thickness={thickness} - penetration={252} + penetration={numericPenetration(antagonist.shell.penetration)} ricochet={antagonist.shell.ricochet} caliber={antagonist.shell.caliber} normalization={antagonist.shell.normalization} diff --git a/src/app/tools/tankopedia/[id]/components/VersusBar.tsx b/src/app/tools/tankopedia/[id]/components/VersusBar.tsx index 398a9da67..62ee62f49 100644 --- a/src/app/tools/tankopedia/[id]/components/VersusBar.tsx +++ b/src/app/tools/tankopedia/[id]/components/VersusBar.tsx @@ -18,8 +18,7 @@ import { import { go } from 'fuzzysort'; import { debounce } from 'lodash'; import { use, useRef, useState } from 'react'; -import { ModuleButtons } from '../../../../../components/ModuleButton'; -import { asset } from '../../../../../core/blitzkrieg/asset'; +import { ModuleButton } from '../../../../../components/ModuleButton'; import { SHELL_NAMES, tankDefinitions, @@ -169,7 +168,12 @@ export function VersusBar() { {antagonist.tank.turrets.map((turret, index) => ( - { mutateTankopedia((draft) => { @@ -184,24 +188,8 @@ export function VersusBar() { }} selected={antagonist.turret.id === turret.id} tier={turret.tier} - type="turret" - style={{ - margin: -0.5, - borderTopLeftRadius: - index === 0 ? undefined : 0, - borderBottomLeftRadius: - index === 0 ? undefined : 0, - borderTopRightRadius: - index === - antagonist.tank.turrets.length - 1 - ? undefined - : 0, - borderBottomRightRadius: - index === - antagonist.tank.turrets.length - 1 - ? undefined - : 0, - }} + type="module" + module="turret" /> ))} @@ -209,7 +197,12 @@ export function VersusBar() { {antagonist.turret.guns.map((gun, index) => ( - { mutateTankopedia((draft) => { if (!draft.areTanksAssigned) return; @@ -219,24 +212,8 @@ export function VersusBar() { }} selected={antagonist.gun.id === gun.id} tier={gun.tier} - type="gun" - style={{ - margin: -0.5, - borderTopLeftRadius: - index === 0 ? undefined : 0, - borderBottomLeftRadius: - index === 0 ? undefined : 0, - borderTopRightRadius: - index === - antagonist.turret.guns.length - 1 - ? undefined - : 0, - borderBottomRightRadius: - index === - antagonist.turret.guns.length - 1 - ? undefined - : 0, - }} + type="module" + module="gun" /> ))} @@ -278,8 +255,27 @@ export function VersusBar() { Calibrated - - + */} diff --git a/src/components/ModuleButton.tsx b/src/components/ModuleButton.tsx index 2f66cb107..125f4a593 100644 --- a/src/components/ModuleButton.tsx +++ b/src/components/ModuleButton.tsx @@ -1,20 +1,35 @@ import { Button, Text } from '@radix-ui/themes'; import { ComponentProps } from 'react'; import { asset } from '../core/blitzkrieg/asset'; -import { TIER_ROMAN_NUMERALS, Tier } from '../core/blitzkrieg/tankDefinitions'; +import { + ShellType, + TIER_ROMAN_NUMERALS, + Tier, +} from '../core/blitzkrieg/tankDefinitions'; -interface ModuleButtonProps - extends Omit, 'type'> { - type: string; - tier: Tier; +type ModuleButtonProps = Omit, 'type'> & { selected?: boolean; -} + first?: boolean; + last?: boolean; + rowChild?: boolean; +} & ( + | { + type: 'module'; + module: string; + tier: Tier; + } + | { + type: 'shell'; + shell: ShellType; + } + ); -export function ModuleButtons({ - type, - tier, +export function ModuleButton({ selected, style, + first = true, + last = true, + rowChild, ...props }: ModuleButtonProps) { return ( @@ -27,34 +42,51 @@ export function ModuleButtons({ width: 48, height: 40, position: 'relative', + borderTopLeftRadius: first ? undefined : 0, + borderTopRightRadius: last ? undefined : 0, + borderBottomLeftRadius: first ? undefined : 0, + borderBottomRightRadius: last ? undefined : 0, + margin: rowChild ? -0.5 : 'unset', ...style, }} - {...props} + {...(props as unknown as ComponentProps)} > - - {TIER_ROMAN_NUMERALS[tier]} - + {props.type === 'module' && ( + + {TIER_ROMAN_NUMERALS[props.tier]} + + )} ); } diff --git a/src/core/blitz/numericPenetration.ts b/src/core/blitz/numericPenetration.ts new file mode 100644 index 000000000..e182dbdb0 --- /dev/null +++ b/src/core/blitz/numericPenetration.ts @@ -0,0 +1,5 @@ +import { Vector2Tuple } from 'three'; + +export function numericPenetration(penetration: number | Vector2Tuple) { + return typeof penetration === 'number' ? penetration : penetration[0]; +}