diff --git a/app/components/NDS2D.vue b/app/components/NDS2D.vue index c42b621..e00abef 100644 --- a/app/components/NDS2D.vue +++ b/app/components/NDS2D.vue @@ -49,6 +49,20 @@ useKeyUp(({ ndsButton }) => { useMouseUp(releaseButton); +const handleTouchEnd = (event: TouchEvent) => { + releaseButton(); + + const touch = event.changedTouches[0]; + if (!touch) return; + + document.dispatchEvent( + new MouseEvent("mouseup", { + clientX: touch.clientX, + clientY: touch.clientY, + }), + ); +}; + const ndsScale = computed(() => { const scaleX = (windowSize.width.value - 40) / 235; const scaleY = (windowSize.height.value - 40) / 431; @@ -118,21 +132,29 @@ watch( class="nds2d-d-pad-tip nds2d-tip-up" :class="{ pressed: buttonsDown.has('UP') }" @mousedown.prevent="pressButton('UP')" + @touchstart.prevent="pressButton('UP')" + @touchend="handleTouchEnd" >
@@ -145,6 +167,8 @@ watch( class="nds2d-button nds2d-btn-x" :class="{ pressed: buttonsDown.has('X') }" @mousedown.prevent="pressButton('X')" + @touchstart.prevent="pressButton('X')" + @touchend="handleTouchEnd" > X @@ -152,6 +176,8 @@ watch( class="nds2d-button nds2d-btn-a" :class="{ pressed: buttonsDown.has('A') }" @mousedown.prevent="pressButton('A')" + @touchstart.prevent="pressButton('A')" + @touchend="handleTouchEnd" > A @@ -159,6 +185,8 @@ watch( class="nds2d-button nds2d-btn-b" :class="{ pressed: buttonsDown.has('B') }" @mousedown.prevent="pressButton('B')" + @touchstart.prevent="pressButton('B')" + @touchend="handleTouchEnd" > B @@ -166,6 +194,8 @@ watch( class="nds2d-button nds2d-btn-y" :class="{ pressed: buttonsDown.has('Y') }" @mousedown.prevent="pressButton('Y')" + @touchstart.prevent="pressButton('Y')" + @touchend="handleTouchEnd" > Y @@ -174,12 +204,16 @@ watch( class="nds2d-small-button nds2d-start" :class="{ pressed: buttonsDown.has('START') }" @mousedown.prevent="pressButton('START')" + @touchstart.prevent="pressButton('START')" + @touchend="handleTouchEnd" >
START
SELECT