From ad1ad8002622af3ea45166d5347f7d1c0cf7c85f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Thu, 25 Jan 2024 11:50:43 -0600 Subject: [PATCH] feat: consumable buttons --- .vscode/settings.json | 1 + scripts/buildAssets/definitions.ts | 9 +++- .../tankopedia/[id]/components/Configure.tsx | 33 +++++++++++++++ src/components/ModuleButton.tsx | 41 +++++++++++-------- .../blitzkrieg/checkConsumableInclusivity.ts | 40 ++++++++++++++++++ src/core/blitzkrieg/consumablesDefinitions.ts | 20 +++++---- src/stores/tankopedia.ts | 2 + 7 files changed, 120 insertions(+), 26 deletions(-) create mode 100644 src/core/blitzkrieg/checkConsumableInclusivity.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 8de5aaa43..c5334eed5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -46,6 +46,7 @@ "glsl", "GLTF", "immer", + "Inclusivity", "JOINTINDEX", "JOINTWEIGHT", "kranvagn", diff --git a/scripts/buildAssets/definitions.ts b/scripts/buildAssets/definitions.ts index f02e7070b..eae2b8548 100644 --- a/scripts/buildAssets/definitions.ts +++ b/scripts/buildAssets/definitions.ts @@ -7,7 +7,10 @@ import { readYAML } from '../../src/core/blitz/readYAML'; import { readYAMLDVPL } from '../../src/core/blitz/readYAMLDVPL'; import { toUniqueId } from '../../src/core/blitz/toUniqueId'; import { commitAssets } from '../../src/core/blitzkrieg/commitAssets'; -import { ConsumableDefinitions } from '../../src/core/blitzkrieg/consumablesDefinitions'; +import { + ConsumableDefinitionFilterCategory, + ConsumableDefinitions, +} from '../../src/core/blitzkrieg/consumablesDefinitions'; import { EquipmentDefinitions, EquipmentPreset, @@ -666,7 +669,9 @@ export async function buildDefinitions(production: boolean) { } else if ('extendedTags' in excludeRaw) { consumableDefinitions[consumable.id].exclude!.push({ type: 'category', - categories: excludeRaw.extendedTags.split(' '), + categories: excludeRaw.extendedTags.split( + ' ', + ) as ConsumableDefinitionFilterCategory[], }); } else throw new SyntaxError('Unhandled exclude type'); } diff --git a/src/app/tools/tankopedia/[id]/components/Configure.tsx b/src/app/tools/tankopedia/[id]/components/Configure.tsx index 1ae2712bb..48d1a6f3f 100644 --- a/src/app/tools/tankopedia/[id]/components/Configure.tsx +++ b/src/app/tools/tankopedia/[id]/components/Configure.tsx @@ -1,6 +1,8 @@ import { Flex, Heading } from '@radix-ui/themes'; import { use } from 'react'; import { ModuleButton } from '../../../../../components/ModuleButton'; +import { checkConsumableInclusivity } from '../../../../../core/blitzkrieg/checkConsumableInclusivity'; +import { consumableDefinitions } from '../../../../../core/blitzkrieg/consumablesDefinitions'; import { equipmentDefinitions } from '../../../../../core/blitzkrieg/equipmentDefinitions'; import { TIER_ROMAN_NUMERALS } from '../../../../../core/blitzkrieg/tankDefinitions'; import { mutateDuel, useDuel } from '../../../../../stores/duel'; @@ -12,11 +14,13 @@ import { export function Configure() { const protagonist = useDuel((state) => state.protagonist!); const awaitedEquipmentDefinitions = use(equipmentDefinitions); + const awaitedConsumableDefinitions = use(consumableDefinitions); const equipmentRows = awaitedEquipmentDefinitions.presets[protagonist.tank.equipment]; const equipmentMatrix = useTankopediaTemporary( (state) => state.equipmentMatrix, ); + const consumables = useTankopediaTemporary((state) => state.consumables); return ( @@ -118,6 +122,35 @@ export function Configure() { Consumables + + {Object.values(awaitedConsumableDefinitions) + .filter((consumable) => + checkConsumableInclusivity( + consumable, + protagonist.tank, + protagonist.gun, + ), + ) + .map((consumable) => ( + { + mutateTankopediaTemporary((draft) => { + if (draft.consumables.includes(consumable.id)) { + draft.consumables = draft.consumables.filter( + (id) => id !== consumable.id, + ); + } else { + draft.consumables.push(consumable.id); + } + }); + }} + /> + ))} diff --git a/src/components/ModuleButton.tsx b/src/components/ModuleButton.tsx index 024289bd2..a0f90c8c3 100644 --- a/src/components/ModuleButton.tsx +++ b/src/components/ModuleButton.tsx @@ -1,5 +1,5 @@ import { Button, Text } from '@radix-ui/themes'; -import { ComponentProps } from 'react'; +import { CSSProperties, ComponentProps } from 'react'; import { asset } from '../core/blitzkrieg/asset'; type ModuleButtonProps = Omit, 'type'> & { @@ -21,6 +21,10 @@ type ModuleButtonProps = Omit, 'type'> & { type: 'equipment'; equipment: number; } + | { + type: 'consumable'; + consumable: number; + } ); export function ModuleButton({ @@ -30,10 +34,26 @@ export function ModuleButton({ last = false, rowChild, discriminator, + disabled, ...props }: ModuleButtonProps) { + const imageStyles: CSSProperties = { + width: 32, + height: 32, + position: 'absolute', + opacity: disabled ? 0.5 : 1, + transform: 'scale(0.75)', + }; + + if (props.type === 'module') { + imageStyles.top = '50%'; + imageStyles.left = '50%'; + imageStyles.transform = 'translate(calc(-50% + 2px), calc(-50% + 2px))'; + } + return (