From 4a2575a7bd8fd884d4b652725ca56dafc031dea3 Mon Sep 17 00:00:00 2001 From: Pihkaal Date: Mon, 23 Feb 2026 14:32:26 +0100 Subject: [PATCH] feat(2d-nds): physical buttons --- app/components/NDS2D.vue | 202 +++++++++++++++++++++++++++++++++------ 1 file changed, 175 insertions(+), 27 deletions(-) diff --git a/app/components/NDS2D.vue b/app/components/NDS2D.vue index 20df45d..a3f5dab 100644 --- a/app/components/NDS2D.vue +++ b/app/components/NDS2D.vue @@ -6,6 +6,49 @@ const app = useAppStore(); const windowSize = useWindowSize(); const hintsContainer = useTemplateRef("hintsContainer"); +const buttonsDown = reactive(new Set()); +let mousePressedButton: string | null = null; + +const dPadStyle = computed(() => { + const rx = + (buttonsDown.has("UP") ? -1 : 0) + (buttonsDown.has("DOWN") ? 1 : 0); + const ry = + (buttonsDown.has("LEFT") ? -1 : 0) + (buttonsDown.has("RIGHT") ? 1 : 0); + if (!rx && !ry) return {}; + return { transform: `rotateX(${rx * 12}deg) rotateY(${ry * 12}deg)` }; +}); + +const pressButton = (button: string) => { + if (mousePressedButton) { + buttonsDown.delete(mousePressedButton); + window.dispatchEvent( + new KeyboardEvent("keyup", { key: `NDS_${mousePressedButton}` }), + ); + } + buttonsDown.add(button); + mousePressedButton = button; + window.dispatchEvent(new KeyboardEvent("keydown", { key: `NDS_${button}` })); +}; + +const releaseButton = () => { + if (!mousePressedButton) return; + buttonsDown.delete(mousePressedButton); + window.dispatchEvent( + new KeyboardEvent("keyup", { key: `NDS_${mousePressedButton}` }), + ); + mousePressedButton = null; +}; + +useKeyDown(({ ndsButton }) => { + if (ndsButton) buttonsDown.add(ndsButton); +}); + +useKeyUp(({ ndsButton }) => { + if (ndsButton) buttonsDown.delete(ndsButton); +}); + +useMouseUp(releaseButton); + const ndsScale = computed(() => { const scaleX = (windowSize.width.value - 40) / 235; const scaleY = (windowSize.height.value - 40) / 431; @@ -59,25 +102,77 @@ defineExpose({ ndsScale });
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
X
-
A
-
B
-
Y
+
+ X +
+
+ A +
+
+ B +
+
+ Y +
-
-
+
+
START
+
+
SELECT