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 {
document.addEventListener('pointermove', this._onMove);
document.addEventListener('pointerup', this._onUp);
document.addEventListener('pointercancel', this._onUp);
document.addEventListener('touchend', this._onUp);
juice.hapticLight?.();
audio.play('click');
......@@ -114,6 +115,7 @@ export class DominoDrag {
document.removeEventListener('pointermove', this._onMove);
document.removeEventListener('pointerup', this._onUp);
document.removeEventListener('pointercancel', this._onUp);
document.removeEventListener('touchend', this._onUp);
this.board.clearGhost();
......@@ -170,5 +172,6 @@ export class DominoDrag {
document.removeEventListener('pointermove', this._onMove);
document.removeEventListener('pointerup', this._onUp);
document.removeEventListener('pointercancel', this._onUp);
document.removeEventListener('touchend', this._onUp);
}
}
......@@ -16,6 +16,7 @@ import { DominoDrag } from '../components/drag.js';
let state, board, hand, drag, liveSession;
let botTimeout = null;
let autoPassTimeout = null;
export function mountGame(el, params) {
const { mode = 'bot', matchId, playerIndex = 0, players, botLevel = 'intermediate' } = params;
......@@ -867,7 +868,11 @@ function updateUI(el) {
} else if (isMyTurn && !hasMove && state.boneyard.length === 0 && !state.gameOver) {
if (drawBtn) drawBtn.style.display = 'none';
if (passBtn) passBtn.style.display = '';
if (!autoPassTimeout) {
autoPassTimeout = setTimeout(() => { autoPassTimeout = null; passTurn(el); }, 1500);
}
} else {
if (autoPassTimeout) { clearTimeout(autoPassTimeout); autoPassTimeout = null; }
if (drawBtn) { drawBtn.style.display = ''; drawBtn.style.animation = ''; }
if (passBtn) passBtn.style.display = 'none';
}
......@@ -934,6 +939,7 @@ async function createServerRecord() {
export function unmountGame() {
if (botTimeout) { clearTimeout(botTimeout); botTimeout = null; }
if (autoPassTimeout) { clearTimeout(autoPassTimeout); autoPassTimeout = null; }
liveSession?.cleanup?.();
mp.stopDisconnectWatch?.();
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