Skip to content

Commit

Permalink
fix eruda clicks
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed Sep 25, 2023
1 parent 34e566a commit 8c7b6f6
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,19 +634,30 @@ async function connect(connectOptions: {

registerListener(document, 'pointerlockchange', changeCallback, false)

let holdingTouch: { touch: Touch, elem: HTMLElement } | undefined
document.body.addEventListener('touchend', (e) => {
if (!isGameActive(true)) return
if (holdingTouch?.touch.identifier !== e.changedTouches[0].identifier) return
holdingTouch.elem.click()
holdingTouch = undefined
})
document.body.addEventListener('touchstart', (e) => {
if (!isGameActive(true)) return
e.preventDefault()
holdingTouch = {
touch: e.touches[0],
elem: e.composedPath()[0] as HTMLElement
}
}, { passive: false })

const cameraControlEl = hud

// after what time of holding the finger start breaking the block
/** after what time of holding the finger start breaking the block */
const touchStartBreakingBlockMs = 500
let virtualClickActive = false
let virtualClickTimeout
let screenTouches = 0
let capturedPointer: { id; x; y; sourceX; sourceY; activateCameraMove; time } | null
document.body.addEventListener('touchstart', (e) => {
if (isGameActive(true)) {
e.preventDefault()
}
}, { passive: false })
registerListener(document, 'pointerdown', (e) => {
const clickedEl = e.composedPath()[0]
if (!isGameActive(true) || !miscUiState.currentTouch || clickedEl !== cameraControlEl || e.pointerId === undefined) {
Expand Down

0 comments on commit 8c7b6f6

Please sign in to comment.