Switch chessboard to tap-tap interaction and fix/enhance premoving
This commit is contained in:
parent
e2e085b341
commit
02b8bafb1e
6 changed files with 364 additions and 294 deletions
|
|
@ -50,6 +50,9 @@ export function mountGameView(container: HTMLElement, ctx: AppContext, gameId: s
|
|||
mode: 'readonly',
|
||||
onMove(uci) {
|
||||
wsClient.send({ type: 'game:move', gameId, uci });
|
||||
},
|
||||
onPremoveChange(premoveUci) {
|
||||
renderPremoveBanner(premoveUci);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -64,13 +67,14 @@ export function mountGameView(container: HTMLElement, ctx: AppContext, gameId: s
|
|||
const current = board.getOrientation();
|
||||
orientationOverride = current === 'w' ? 'b' : 'w';
|
||||
board.setOrientation(orientationOverride);
|
||||
renderLayout();
|
||||
if (game) updateDynamicHeaderBars(game);
|
||||
}
|
||||
});
|
||||
|
||||
// Dynamic UI refs updated without tearing down Board / Clocks
|
||||
const topPlayerBar = el('div', { className: 'player-bar' });
|
||||
const bottomPlayerBar = el('div', { className: 'player-bar' });
|
||||
const premoveBannerEl = el('div', { className: 'premove-banner hidden' });
|
||||
const liveNoticeEl = el('div', { className: 'live-notice hidden' });
|
||||
const statusBannerEl = el('div', { className: 'game-status-banner hidden' });
|
||||
const actionsEl = el('div', { className: 'game-actions' });
|
||||
|
|
@ -106,6 +110,7 @@ export function mountGameView(container: HTMLElement, ctx: AppContext, gameId: s
|
|||
boardCol.appendChild(topPlayerBar);
|
||||
boardCol.appendChild(board.root);
|
||||
boardCol.appendChild(bottomPlayerBar);
|
||||
boardCol.appendChild(premoveBannerEl);
|
||||
boardCol.appendChild(liveNoticeEl);
|
||||
layout.appendChild(boardCol);
|
||||
|
||||
|
|
@ -207,25 +212,23 @@ export function mountGameView(container: HTMLElement, ctx: AppContext, gameId: s
|
|||
clock.update(ms, g.clockRunning && isTurn, g.category === 'unlimited');
|
||||
}
|
||||
|
||||
function renderLayout(): void {
|
||||
if (destroyed) return;
|
||||
if (errorMsg) {
|
||||
clearNode(container);
|
||||
const errPage = el('div', { className: 'page-container narrow-page' });
|
||||
const card = el('div', { className: 'card' });
|
||||
const body = el('div', { className: 'card-body' });
|
||||
body.appendChild(el('div', { className: 'alert alert-error' }, errorMsg));
|
||||
const back = el('button', { type: 'button', className: 'btn' }, 'Back to Lobby');
|
||||
back.addEventListener('click', () => ctx.navigate('/'));
|
||||
body.appendChild(back);
|
||||
card.appendChild(body);
|
||||
errPage.appendChild(card);
|
||||
container.appendChild(errPage);
|
||||
function renderPremoveBanner(premoveUci: string | null): void {
|
||||
clearNode(premoveBannerEl);
|
||||
if (!premoveUci || premoveUci.length < 4) {
|
||||
premoveBannerEl.className = 'premove-banner hidden';
|
||||
return;
|
||||
}
|
||||
const from = premoveUci.slice(0, 2);
|
||||
const to = premoveUci.slice(2, 4);
|
||||
const promo = premoveUci.length === 5 ? `=${premoveUci.charAt(4).toUpperCase()}` : '';
|
||||
premoveBannerEl.className = 'premove-banner';
|
||||
premoveBannerEl.appendChild(el('span', null, `Premove queued: ${from} → ${to}${promo}`));
|
||||
const cancelBtn = el('button', { type: 'button', className: 'btn btn-xs' }, 'Cancel');
|
||||
cancelBtn.addEventListener('click', () => board.clearPremove());
|
||||
premoveBannerEl.appendChild(cancelBtn);
|
||||
}
|
||||
|
||||
if (!game) return;
|
||||
const g = game;
|
||||
function updateDynamicHeaderBars(g: ActiveGameState): void {
|
||||
const orient = effectiveOrientation(g);
|
||||
const topColor: Color = orient === 'w' ? 'b' : 'w';
|
||||
const bottomColor: Color = orient;
|
||||
|
|
@ -260,6 +263,28 @@ export function mountGameView(container: HTMLElement, ctx: AppContext, gameId: s
|
|||
} else {
|
||||
statusBannerEl.className = 'game-status-banner hidden';
|
||||
}
|
||||
}
|
||||
|
||||
function renderLayout(): void {
|
||||
if (destroyed) return;
|
||||
if (errorMsg) {
|
||||
clearNode(container);
|
||||
const errPage = el('div', { className: 'page-container narrow-page' });
|
||||
const card = el('div', { className: 'card' });
|
||||
const body = el('div', { className: 'card-body' });
|
||||
body.appendChild(el('div', { className: 'alert alert-error' }, errorMsg));
|
||||
const back = el('button', { type: 'button', className: 'btn' }, 'Back to Lobby');
|
||||
back.addEventListener('click', () => ctx.navigate('/'));
|
||||
body.appendChild(back);
|
||||
card.appendChild(body);
|
||||
errPage.appendChild(card);
|
||||
container.appendChild(errPage);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!game) return;
|
||||
const g = game;
|
||||
updateDynamicHeaderBars(g);
|
||||
|
||||
// Action buttons
|
||||
renderActions(g);
|
||||
|
|
@ -481,11 +506,11 @@ export function mountGameView(container: HTMLElement, ctx: AppContext, gameId: s
|
|||
}
|
||||
}
|
||||
|
||||
// Countdown tick for disconnect / abort banners
|
||||
// Countdown tick for disconnect / abort banners (updates header bars without disturbing board selection/premoves)
|
||||
const countdownTimer = window.setInterval(() => {
|
||||
if (!game || game.finished) return;
|
||||
if (game.white.disconnectDeadlineMs || game.black.disconnectDeadlineMs || (game.abortDeadlineMs && game.movesUci.length < 2)) {
|
||||
renderLayout();
|
||||
updateDynamicHeaderBars(game);
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
|
|
@ -538,7 +563,7 @@ export function mountGameView(container: HTMLElement, ctx: AppContext, gameId: s
|
|||
game.black.connected = msg.blackConnected;
|
||||
game.black.disconnectDeadlineMs = msg.blackDisconnectDeadlineMs;
|
||||
game.spectatorCount = msg.spectatorCount;
|
||||
renderLayout();
|
||||
updateDynamicHeaderBars(game);
|
||||
} else if (msg.type === 'game:chat' && game && msg.gameId === gameId) {
|
||||
game.chat.push(msg.message);
|
||||
renderChat(game);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue