From a40f86f982782690f281ce70e81c59708a27ec59 Mon Sep 17 00:00:00 2001
From: tresabhi <43380238+tresabhi@users.noreply.github.com>
Date: Tue, 12 Nov 2024 20:58:05 -0600
Subject: [PATCH] feat: relative types
---
packages/core/lang/en-US.json | 7 +++
.../Characteristics/components/Heading.tsx | 48 +++++++++++++++++++
.../components/InfoWithDelta.tsx | 20 +++++++-
.../CharacteristicsSection/index.tsx | 5 +-
.../website/src/stores/tankopediaEphemeral.ts | 8 ++++
5 files changed, 83 insertions(+), 5 deletions(-)
create mode 100644 packages/website/src/components/Tankopedia/CharacteristicsSection/components/Characteristics/components/Heading.tsx
diff --git a/packages/core/lang/en-US.json b/packages/core/lang/en-US.json
index f46678260..a16b18879 100644
--- a/packages/core/lang/en-US.json
+++ b/packages/core/lang/en-US.json
@@ -59,6 +59,13 @@
"3": "TD"
},
+ "tank_class_short_plural_lowercase": {
+ "0": "lights",
+ "1": "mediums",
+ "2": "heavies",
+ "3": "TDs"
+ },
+
"tank_class_medium": {
"-1": "unrecognized",
"0": "Light",
diff --git a/packages/website/src/components/Tankopedia/CharacteristicsSection/components/Characteristics/components/Heading.tsx b/packages/website/src/components/Tankopedia/CharacteristicsSection/components/Characteristics/components/Heading.tsx
new file mode 100644
index 000000000..b9da3251d
--- /dev/null
+++ b/packages/website/src/components/Tankopedia/CharacteristicsSection/components/Characteristics/components/Heading.tsx
@@ -0,0 +1,48 @@
+import { TIER_ROMAN_NUMERALS } from '@blitzkit/core';
+import strings from '@blitzkit/core/lang/en-US.json';
+import { Flex, Heading, SegmentedControl, Text } from '@radix-ui/themes';
+import { Duel } from '../../../../../../stores/duel';
+import {
+ TankopediaEphemeral,
+ TankopediaRelativeAgainst,
+} from '../../../../../../stores/tankopediaEphemeral';
+
+export function CharacteristicsHeading() {
+ const relativeAgainst = TankopediaEphemeral.use(
+ (state) => state.relativeAgainst,
+ );
+ const tank = Duel.use((state) => state.protagonist.tank);
+ const mutateTankopediaEphemeral = TankopediaEphemeral.useMutation();
+
+ return (
+
+ Characteristics
+
+ Compare against
+ {
+ mutateTankopediaEphemeral((draft) => {
+ draft.relativeAgainst = Number(value) as TankopediaRelativeAgainst;
+ });
+ }}
+ >
+
+ Tier {TIER_ROMAN_NUMERALS[tank.tier]}{' '}
+ {strings.common.tank_class_short_plural_lowercase[tank.class]}
+
+
+ All of tier {TIER_ROMAN_NUMERALS[tank.tier]}
+
+
+ All tanks
+
+
+
+ );
+}
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 4a94a1231..730cfb0d3 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
@@ -15,6 +15,10 @@ import {
import { tankToDuelMember } from '../../../../../../core/blitzkit/tankToDuelMember';
import { useDelta } from '../../../../../../hooks/useDelta';
import { Duel } from '../../../../../../stores/duel';
+import {
+ TankopediaEphemeral,
+ TankopediaRelativeAgainst,
+} from '../../../../../../stores/tankopediaEphemeral';
import { Info, type InfoProps } from './Info';
interface InfoWithDeltaProps extends InfoProps {
@@ -39,6 +43,9 @@ export function InfoWithDelta({
deltaType,
...props
}: InfoWithDeltaProps) {
+ const relativeAgainst = TankopediaEphemeral.use(
+ (state) => state.relativeAgainst,
+ );
const uhWhatDoICallThisVariable =
typeof value === 'function' ? value(stats)! : (stats[value] as number);
const delta = useDelta(uhWhatDoICallThisVariable);
@@ -47,7 +54,15 @@ export function InfoWithDelta({
const defaultSkills = createDefaultSkills(skillDefinitions);
return Object.values(tankDefinitions.tanks)
- .filter((tank) => tank.tier === protagonistTank.tier)
+ .filter(
+ (tank) =>
+ (relativeAgainst === TankopediaRelativeAgainst.Class &&
+ tank.tier === protagonistTank.tier &&
+ tank.class === protagonistTank.class) ||
+ (relativeAgainst === TankopediaRelativeAgainst.Tier &&
+ tank.tier === protagonistTank.tier) ||
+ relativeAgainst === TankopediaRelativeAgainst.All,
+ )
.map((tank) => {
const member = tankToDuelMember(tank, provisionDefinitions);
@@ -85,7 +100,7 @@ export function InfoWithDelta({
return othersValue !== undefined;
});
- }, []);
+ }, [relativeAgainst]);
const betterTanks = others.filter((tank) => {
const othersValue =
typeof value === 'function' ? value(tank)! : (tank[value] as number);
@@ -116,6 +131,7 @@ export function InfoWithDelta({
size="1"
value={goodness * 100}
color={color}
+ style={{ height: '0.125rem' }}
/>
{betterTanks.length + 1} / {others.length}
diff --git a/packages/website/src/components/Tankopedia/CharacteristicsSection/index.tsx b/packages/website/src/components/Tankopedia/CharacteristicsSection/index.tsx
index db5cdbd14..9cab5255f 100644
--- a/packages/website/src/components/Tankopedia/CharacteristicsSection/index.tsx
+++ b/packages/website/src/components/Tankopedia/CharacteristicsSection/index.tsx
@@ -1,5 +1,6 @@
import { Flex, Heading } from '@radix-ui/themes';
import { Characteristics } from './components/Characteristics';
+import { CharacteristicsHeading } from './components/Characteristics/components/Heading';
import { Consumables } from './components/Consumables';
import { Equipment } from './components/Equipment';
import { Miscellaneous } from './components/Miscellaneous';
@@ -38,9 +39,7 @@ export function CharacteristicsSection() {
gap="6"
width="100%"
>
-
- Characteristics
-
+
diff --git a/packages/website/src/stores/tankopediaEphemeral.ts b/packages/website/src/stores/tankopediaEphemeral.ts
index d7a2f35e6..4698a2f30 100644
--- a/packages/website/src/stores/tankopediaEphemeral.ts
+++ b/packages/website/src/stores/tankopediaEphemeral.ts
@@ -71,9 +71,16 @@ export type ArmorPiercingLayer =
gap: number;
};
+export enum TankopediaRelativeAgainst {
+ Class,
+ Tier,
+ All,
+}
+
interface TankopediaEphemeral {
shot?: Shot;
skills: Record;
+ relativeAgainst: TankopediaRelativeAgainst;
controlsEnabled: boolean;
model: ModelDefinition;
editStatic: boolean;
@@ -101,6 +108,7 @@ export const TankopediaEphemeral = createContextualStore(
(model: ModelDefinition) => {
return create()(
subscribeWithSelector(() => ({
+ relativeAgainst: TankopediaRelativeAgainst.Class,
editStatic: false,
skills: createDefaultSkills(skillDefinitions),
model,