Support up to 25 queued premoves with projected board state
This commit is contained in:
parent
3ccab53b41
commit
14263d3c32
6 changed files with 304 additions and 82 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { Chess } from '../../shared/chess';
|
||||
import { MAX_PREMOVES } from '../../shared/premove';
|
||||
import { categoryLabel, formatTimeControl } from '../../shared/timeControl';
|
||||
import type { ActiveGameState, Color, ServerWsMessage } from '../../shared/types';
|
||||
import { apiRequest, wsClient } from '../api';
|
||||
|
|
@ -51,8 +52,8 @@ export function mountGameView(container: HTMLElement, ctx: AppContext, gameId: s
|
|||
onMove(uci) {
|
||||
wsClient.send({ type: 'game:move', gameId, uci });
|
||||
},
|
||||
onPremoveChange(premoveUci) {
|
||||
renderPremoveBanner(premoveUci);
|
||||
onPremoveChange(premoveQueueUci) {
|
||||
renderPremoveBanner(premoveQueueUci);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -212,20 +213,37 @@ export function mountGameView(container: HTMLElement, ctx: AppContext, gameId: s
|
|||
clock.update(ms, g.clockRunning && isTurn, g.category === 'unlimited');
|
||||
}
|
||||
|
||||
function renderPremoveBanner(premoveUci: string | null): void {
|
||||
function formatPremoveStep(uci: string): string {
|
||||
const from = uci.slice(0, 2);
|
||||
const to = uci.slice(2, 4);
|
||||
const promo = uci.length === 5 ? `=${uci.charAt(4).toUpperCase()}` : '';
|
||||
return `${from}→${to}${promo}`;
|
||||
}
|
||||
|
||||
function renderPremoveBanner(queueUci: string[]): void {
|
||||
clearNode(premoveBannerEl);
|
||||
if (!premoveUci || premoveUci.length < 4) {
|
||||
if (!queueUci || queueUci.length === 0) {
|
||||
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()}` : '';
|
||||
const maxPreview = 5;
|
||||
const formatted = queueUci.slice(0, maxPreview).map(formatPremoveStep).join(', ');
|
||||
const suffix = queueUci.length > maxPreview ? `, +${queueUci.length - maxPreview} more` : '';
|
||||
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);
|
||||
premoveBannerEl.appendChild(
|
||||
el('span', { className: 'premove-text' }, `Premoves (${queueUci.length}/${MAX_PREMOVES}): ${formatted}${suffix}`)
|
||||
);
|
||||
|
||||
const btns = el('div', { className: 'btn-row' });
|
||||
if (queueUci.length > 1) {
|
||||
const undoBtn = el('button', { type: 'button', className: 'btn btn-xs' }, 'Undo');
|
||||
undoBtn.addEventListener('click', () => board.popPremove());
|
||||
btns.appendChild(undoBtn);
|
||||
}
|
||||
const clearBtn = el('button', { type: 'button', className: 'btn btn-xs' }, 'Clear');
|
||||
clearBtn.addEventListener('click', () => board.clearPremove());
|
||||
btns.appendChild(clearBtn);
|
||||
premoveBannerEl.appendChild(btns);
|
||||
}
|
||||
|
||||
function updateDynamicHeaderBars(g: ActiveGameState): void {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue