mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 02:37:05 +02:00
feat: key press shell switching
This commit is contained in:
1 parent
371dcad568
commit
172b410d82
1 file changed
+25
@@ -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]);
|
||||
|
||||
|
||||
Reference in new issue
Block a user