feat(nds): improve key input system
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user