Commit 0abd3f92 authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: domino drag-drop touchend fallback + auto-pass when blocked

- Added touchend listener as fallback in DominoDrag for browsers/envs
  where pointerup doesn't fire after touch events
- Added auto-pass (1.5s timeout) when player is blocked and boneyard
  is empty — prevents game from stalling
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 18c0006d
...@@ -30,6 +30,7 @@ export class DominoDrag { ...@@ -30,6 +30,7 @@ export class DominoDrag {
document.addEventListener('pointermove', this._onMove); document.addEventListener('pointermove', this._onMove);
document.addEventListener('pointerup', this._onUp); document.addEventListener('pointerup', this._onUp);
document.addEventListener('pointercancel', this._onUp); document.addEventListener('pointercancel', this._onUp);
document.addEventListener('touchend', this._onUp);
juice.hapticLight?.(); juice.hapticLight?.();
audio.play('click'); audio.play('click');
...@@ -114,6 +115,7 @@ export class DominoDrag { ...@@ -114,6 +115,7 @@ export class DominoDrag {
document.removeEventListener('pointermove', this._onMove); document.removeEventListener('pointermove', this._onMove);
document.removeEventListener('pointerup', this._onUp); document.removeEventListener('pointerup', this._onUp);
document.removeEventListener('pointercancel', this._onUp); document.removeEventListener('pointercancel', this._onUp);
document.removeEventListener('touchend', this._onUp);
this.board.clearGhost(); this.board.clearGhost();
...@@ -170,5 +172,6 @@ export class DominoDrag { ...@@ -170,5 +172,6 @@ export class DominoDrag {
document.removeEventListener('pointermove', this._onMove); document.removeEventListener('pointermove', this._onMove);
document.removeEventListener('pointerup', this._onUp); document.removeEventListener('pointerup', this._onUp);
document.removeEventListener('pointercancel', this._onUp); document.removeEventListener('pointercancel', this._onUp);
document.removeEventListener('touchend', this._onUp);
} }
} }
...@@ -16,6 +16,7 @@ import { DominoDrag } from '../components/drag.js'; ...@@ -16,6 +16,7 @@ import { DominoDrag } from '../components/drag.js';
let state, board, hand, drag, liveSession; let state, board, hand, drag, liveSession;
let botTimeout = null; let botTimeout = null;
let autoPassTimeout = null;
export function mountGame(el, params) { export function mountGame(el, params) {
const { mode = 'bot', matchId, playerIndex = 0, players, botLevel = 'intermediate' } = params; const { mode = 'bot', matchId, playerIndex = 0, players, botLevel = 'intermediate' } = params;
...@@ -867,7 +868,11 @@ function updateUI(el) { ...@@ -867,7 +868,11 @@ function updateUI(el) {
} else if (isMyTurn && !hasMove && state.boneyard.length === 0 && !state.gameOver) { } else if (isMyTurn && !hasMove && state.boneyard.length === 0 && !state.gameOver) {
if (drawBtn) drawBtn.style.display = 'none'; if (drawBtn) drawBtn.style.display = 'none';
if (passBtn) passBtn.style.display = ''; if (passBtn) passBtn.style.display = '';
if (!autoPassTimeout) {
autoPassTimeout = setTimeout(() => { autoPassTimeout = null; passTurn(el); }, 1500);
}
} else { } else {
if (autoPassTimeout) { clearTimeout(autoPassTimeout); autoPassTimeout = null; }
if (drawBtn) { drawBtn.style.display = ''; drawBtn.style.animation = ''; } if (drawBtn) { drawBtn.style.display = ''; drawBtn.style.animation = ''; }
if (passBtn) passBtn.style.display = 'none'; if (passBtn) passBtn.style.display = 'none';
} }
...@@ -934,6 +939,7 @@ async function createServerRecord() { ...@@ -934,6 +939,7 @@ async function createServerRecord() {
export function unmountGame() { export function unmountGame() {
if (botTimeout) { clearTimeout(botTimeout); botTimeout = null; } if (botTimeout) { clearTimeout(botTimeout); botTimeout = null; }
if (autoPassTimeout) { clearTimeout(autoPassTimeout); autoPassTimeout = null; }
liveSession?.cleanup?.(); liveSession?.cleanup?.();
mp.stopDisconnectWatch?.(); mp.stopDisconnectWatch?.();
board?.destroy(); board?.destroy();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment