From bc60b4b42c2ad36366a86356864008bb38a2e00e Mon Sep 17 00:00:00 2001 From: tresabhi <43380238+tresabhi@users.noreply.github.com> Date: Tue, 12 Nov 2024 15:40:57 -0600 Subject: [PATCH] feat: key based tankopedia --- .../src/components/Compare/CompareRow.tsx | 5 +- .../components/InfoWithDelta.tsx | 12 +- .../components/Characteristics/index.tsx | 594 ++++++++++++------ 3 files changed, 402 insertions(+), 209 deletions(-) diff --git a/packages/website/src/components/Compare/CompareRow.tsx b/packages/website/src/components/Compare/CompareRow.tsx index 1956e4588..9335d16eb 100644 --- a/packages/website/src/components/Compare/CompareRow.tsx +++ b/packages/website/src/components/Compare/CompareRow.tsx @@ -13,8 +13,8 @@ import { StickyRowHeaderCell } from '../StickyRowHeaderCell'; interface CompareRowProps { name: string; value: - | keyof Awaited - | ((member: Awaited) => number | undefined); + | keyof TankCharacteristics + | ((member: TankCharacteristics) => number | undefined); display?: ( member: Awaited, ) => number | string | undefined; @@ -38,7 +38,6 @@ export function CompareRow({ const mutateCompareEphemeral = CompareEphemeral.useMutation(); const sorting = CompareEphemeral.use((state) => state.sorting); const deltaMode = ComparePersistent.use((state) => state.deltaMode); - const values = stats.map((stat) => typeof value === 'function' ? value(stat)! : (stat[value] as number), ); diff --git a/packages/website/src/components/Tankopedia/CharacteristicsSection/components/Characteristics/components/InfoWithDelta.tsx b/packages/website/src/components/Tankopedia/CharacteristicsSection/components/Characteristics/components/InfoWithDelta.tsx index 975720b1a..f6c5a5a9a 100644 --- a/packages/website/src/components/Tankopedia/CharacteristicsSection/components/Characteristics/components/InfoWithDelta.tsx +++ b/packages/website/src/components/Tankopedia/CharacteristicsSection/components/Characteristics/components/InfoWithDelta.tsx @@ -1,16 +1,20 @@ +import type { TankCharacteristics } from '../../../../../../core/blitzkit/tankCharacteristics'; import { useDelta } from '../../../../../../hooks/useDelta'; import { type InfoProps, Info } from './Info'; interface InfoWithDeltaProps extends InfoProps { - children: number; + stats: TankCharacteristics; + value: keyof TankCharacteristics | (() => number | undefined); } -export function InfoWithDelta({ children, ...props }: InfoWithDeltaProps) { - const delta = useDelta(children); +export function InfoWithDelta({ value, stats, ...props }: InfoWithDeltaProps) { + const uhWhatDoICallThisVariable = + typeof value === 'function' ? value()! : (stats[value] as number); + const delta = useDelta(uhWhatDoICallThisVariable); return ( - {children} + {uhWhatDoICallThisVariable} ); } diff --git a/packages/website/src/components/Tankopedia/CharacteristicsSection/components/Characteristics/index.tsx b/packages/website/src/components/Tankopedia/CharacteristicsSection/components/Characteristics/index.tsx index 6f6f84000..2c3513429 100644 --- a/packages/website/src/components/Tankopedia/CharacteristicsSection/components/Characteristics/index.tsx +++ b/packages/website/src/components/Tankopedia/CharacteristicsSection/components/Characteristics/index.tsx @@ -181,21 +181,25 @@ export function Characteristics() { {GUN_TYPE_NAMES[gun.gun_type!.$case]} - - {stats.dpm} - + {gun.gun_type!.$case === 'auto_reloader' && ( - {stats.dpmEffective!} - + value="dpmEffective" + /> )} {gun.gun_type!.$case !== 'regular' && ( - {stats.shells} + )} {gun.gun_type!.$case === 'auto_reloader' ? ( <> @@ -205,56 +209,62 @@ export function Characteristics() { {stats.shellReloads!.map((reload, index) => ( - {reload} - + value={() => reload} + /> ))} ) : ( - {stats.shellReload!} - + value="shellReload" + /> )} {(gun.gun_type!.$case === 'auto_loader' || gun.gun_type!.$case === 'auto_reloader') && ( - {stats.intraClip!} - + value="intraClip" + /> )} - - {stats.penetration} - + {typeof shell.penetration !== 'number' && ( <> - {lerp( - shell.penetration.near, - shell.penetration.far, - (penetrationDistance * - penetrationLossOverDistanceCoefficient) / - 500, - ) * penetrationCoefficient} - + value={() => + lerp( + shell.penetration.near, + shell.penetration.far, + (penetrationDistance * + penetrationLossOverDistanceCoefficient) / + 500, + ) * penetrationCoefficient + } + /> Distance )} - - {stats.damage} - + {gun.gun_type!.$case !== 'regular' && ( - - {stats.clipDamage!} - + )} - - {stats.moduleDamage} - + {isExplosive(shell.type) && ( - - {stats.explosionRadius!} - + )} - - {stats.caliber} - - - {stats.shellNormalization} - + + {!isExplosive(shell.type) && ( - {stats.shellRicochet!} - + value="shellRicochet" + /> )} - - {stats.shellVelocity} - - - {stats.shellRange} - - - {stats.shellCapacity} - + + + - {stats.aimTime} - + value="aimTime" + /> - {stats.dispersion} - + value="dispersion" + /> - {stats.dispersionMoving} - + value="dispersionMoving" + /> - {stats.dispersionHullTraversing} - + value="dispersionHullTraversing" + /> - {stats.dispersionTurretTraversing} - + value="dispersionTurretTraversing" + /> - {stats.dispersionShooting} - + value="dispersionShooting" + /> - {stats.dispersionGunDamaged} - + value="dispersionGunDamaged" + /> - - {stats.gunDepression} - - - {stats.gunElevation} - + + {gunModelDefinition.pitch.front && ( <> - - {stats.gunFrontalDepression!} - - - {stats.gunFrontalElevation!} - + + )} {gunModelDefinition.pitch.back && ( <> - - {stats.gunRearDepression!} - - - {stats.gunRearElevation!} - + + )} {turretModelDefinition.yaw && ( <> - - {stats.azimuthLeft!} - - - {stats.azimuthRight!} - + + )} @@ -459,28 +536,34 @@ export function Characteristics() { - - {stats.crewCount} - + {tank.crew.map((member) => { return ( 1 ? ` x ${member.count}` : '' }`} unit="%" decimals={0} - > - {(member.type === CrewType.COMMANDER - ? commanderMastery - : commanderMastery * 1.1) * 100} - + value={() => + (member.type === CrewType.COMMANDER + ? commanderMastery + : commanderMastery * 1.1) * 100 + } + /> {member.substitute.length > 0 && ( } - > - {commanderMastery * 1.05 * 100} - + value={() => commanderMastery * 1.05 * 100} + /> )} ); @@ -511,123 +593,231 @@ export function Characteristics() { Maneuverability - - {stats.speedForwards} - - - {stats.speedBackwards} - - - {stats.enginePower} - + + + - {stats.weight} - + value="weight" + /> - - {stats.hardTerrainCoefficient} - - - {stats.mediumTerrainCoefficient} - - - {stats.softTerrainCoefficient} - - - - {stats.hardTerrainCoefficientRaw} - + + + + + - {stats.mediumTerrainCoefficientRaw} - + value="mediumTerrainCoefficientRaw" + /> - {stats.softTerrainCoefficientRaw} - + value="softTerrainCoefficientRaw" + /> - - {stats.powerToWeightRatioHardTerrain} - - - {stats.powerToWeightRatioMediumTerrain} - - - {stats.powerToWeightRatioSoftTerrain} - - - {stats.turretTraverseSpeed} - + + + + - - {stats.hullTraverseHardTerrain} - - - {stats.hullTraverseMediumTerrain} - - - {stats.hullTraverseSoftTerrain} - + + + Survivability - - {stats.health} - + - {stats.fireChance * 100} - - - {stats.viewRange} - + value={() => stats.fireChance * 100} + /> + - - {stats.camouflageStill * 100} - - - {stats.camouflageMoving * 100} - - - {stats.camouflageShootingStill * 100} - - - {stats.camouflageShootingMoving * 100} - - - {stats.camouflageCaughtOnFire * 100} - - - {stats.width} - - - {stats.height} - - - {stats.length} - - - {stats.volume} - + stats.camouflageStill * 100} + stats={stats} + indent + name="Still" + decimals={2} + /> + stats.camouflageMoving * 100} + stats={stats} + indent + name="Moving" + decimals={2} + /> + stats.camouflageShootingStill * 100} + /> + stats.camouflageShootingMoving * 100} + /> + stats.camouflageCaughtOnFire * 100} + /> + + + +