From 1f7b78dabceaf16d31c7b46948cc15ce5e219e3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=C3=A8sAbhi?= <43380238+tresabhi@users.noreply.github.com> Date: Fri, 18 Oct 2024 11:36:50 -0500 Subject: [PATCH] fix: reintroduce shell switching shortcut --- .../Tankopedia/HeroSection/index.tsx | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/website/src/components/Tankopedia/HeroSection/index.tsx b/packages/website/src/components/Tankopedia/HeroSection/index.tsx index f65797965..992ca89d1 100644 --- a/packages/website/src/components/Tankopedia/HeroSection/index.tsx +++ b/packages/website/src/components/Tankopedia/HeroSection/index.tsx @@ -1,6 +1,7 @@ import { fetchTankDefinitions, TankType } from '@blitzkit/core'; import { Box, Flex, Heading, Text } from '@radix-ui/themes'; -import { Suspense, useMemo, useRef } from 'react'; +import { times } from 'lodash-es'; +import { Suspense, useEffect, useMemo, useRef } from 'react'; import { NAVBAR_HEIGHT } from '../../../constants/navbar'; import { Var } from '../../../core/radix/var'; import { useFullScreen } from '../../../hooks/useFullScreen'; @@ -42,6 +43,26 @@ export function HeroSection() { return { value } satisfies ThicknessRange; }, [protagonist]); + const duelStore = Duel.useStore(); + const mutateDuel = Duel.useMutation(); + + useEffect(() => { + function handleKeyDown(event: KeyboardEvent) { + const { shells } = + duelStore.getState().antagonist.gun.gun_type!.value.base; + + times(3, (index) => { + if (event.key === `${index + 1}` && shells.length > index) { + mutateDuel((draft) => { + draft.antagonist.shell = shells[index]; + }); + } + }); + } + + window.addEventListener('keydown', handleKeyDown); + return () => window.removeEventListener('keydown', handleKeyDown); + }, []); return (