From 172b410d82981fa863d3a4d6a2456d7014a90f5c 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 18:01:33 -0600 Subject: [PATCH] feat: key press shell switching --- src/app/tools/tankopedia/[id]/page.tsx | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/app/tools/tankopedia/[id]/page.tsx b/src/app/tools/tankopedia/[id]/page.tsx index c9b3b309d..711960985 100644 --- a/src/app/tools/tankopedia/[id]/page.tsx +++ b/src/app/tools/tankopedia/[id]/page.tsx @@ -39,10 +39,35 @@ export default function Page({ params }: { params: { id: string } }) { }; }); + function handleKeyDown(event: KeyboardEvent) { + if (event.key === '1') { + mutateTankopedia((draft) => { + if (!draft.areTanksAssigned) return; + draft.antagonist.shell = draft.antagonist.gun.shells[0]; + }); + } else if (event.key === '2') { + mutateTankopedia((draft) => { + if (!draft.areTanksAssigned) return; + if (draft.antagonist.gun.shells[1]) + draft.antagonist.shell = draft.antagonist.gun.shells[1]; + }); + } else if (event.key === '3') { + mutateTankopedia((draft) => { + if (!draft.areTanksAssigned) return; + if (draft.antagonist.gun.shells[2]) + draft.antagonist.shell = draft.antagonist.gun.shells[2]; + }); + } + } + + window.addEventListener('keydown', handleKeyDown); + return () => { mutateTankopedia((draft) => { draft.areTanksAssigned = false; }); + + window.removeEventListener('keydown', handleKeyDown); }; }, [id]);