feat(nds): improve key input system
This commit is contained in:
@@ -203,38 +203,15 @@ const { onRender } = useLoop();
|
||||
const physicalButtonsDown = new Set<string>();
|
||||
let mousePressedButton: string | null = null;
|
||||
|
||||
const keyToButton: Record<string, string> = {
|
||||
ArrowUp: "UP",
|
||||
ArrowDown: "DOWN",
|
||||
ArrowLeft: "LEFT",
|
||||
ArrowRight: "RIGHT",
|
||||
d: "A",
|
||||
s: "B",
|
||||
w: "X",
|
||||
a: "Y",
|
||||
D: "A",
|
||||
S: "B",
|
||||
W: "X",
|
||||
A: "Y",
|
||||
" ": "SELECT",
|
||||
Enter: "START",
|
||||
};
|
||||
|
||||
useKeyDown((key) => {
|
||||
const button = keyToButton[key];
|
||||
if (button) {
|
||||
physicalButtonsDown.add(button);
|
||||
window.dispatchEvent(
|
||||
new KeyboardEvent("keydown", { key: `NDS_${button}` }),
|
||||
);
|
||||
useKeyDown(({ ndsButton }) => {
|
||||
if (ndsButton) {
|
||||
physicalButtonsDown.add(ndsButton);
|
||||
}
|
||||
});
|
||||
|
||||
useKeyUp((key) => {
|
||||
const button = keyToButton[key];
|
||||
if (button) {
|
||||
physicalButtonsDown.delete(button);
|
||||
window.dispatchEvent(new KeyboardEvent("keyup", { key: `NDS_${button}` }));
|
||||
useKeyUp(({ ndsButton }) => {
|
||||
if (ndsButton) {
|
||||
physicalButtonsDown.delete(ndsButton);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user