feat(nds): improve key input system

This commit is contained in:
2026-02-10 16:28:54 +01:00
parent a586c149d8
commit 14b9ee6119
16 changed files with 59 additions and 102 deletions

View File

@@ -12,63 +12,6 @@ const bottomScreen = useTemplateRef<ScreenInstance>("bottomScreen");
const topScreenCanvas = computed(() => topScreen.value?.canvas ?? null);
const bottomScreenCanvas = computed(() => bottomScreen.value?.canvas ?? null);
const a = useAchievementsStore();
const keyToButton: Record<string, string> = {
ArrowUp: "UP",
ArrowDown: "DOWN",
ArrowLeft: "LEFT",
ArrowRight: "RIGHT",
d: "A",
s: "B",
z: "X",
q: "Y",
D: "A",
S: "B",
Z: "X",
Q: "Y",
" ": "SELECT",
Enter: "START",
};
// events are dispatched from NDS.vue in 3d mode
// events are dispatched from here in 2d mode
// that's a bit dirty but who cares, there is a lot of dirty things going on here
// like who choose Nuxt to build such an app
useKeyDown((key) => {
if (app.settings.renderingMode === "3d") return;
const button = keyToButton[key];
if (button) {
window.dispatchEvent(
new KeyboardEvent("keydown", { key: `NDS_${button}` }),
);
}
// testing purpose only
if (key === "m") {
a.reset();
} else if (key === "o") {
for (const ach of ACHIEVEMENTS) {
a.unlock(ach.id);
}
} else if (key === "p") {
for (const ach of ACHIEVEMENTS) {
if (!a.isUnlocked(ach.id)) {
a.unlock(ach.id);
break;
}
}
}
});
useKeyUp((key) => {
if (app.settings.renderingMode === "3d") return;
const button = keyToButton[key];
if (button) {
window.dispatchEvent(new KeyboardEvent("keyup", { key: `NDS_${button}` }));
}
});
</script>
<template>