Allow multiple PV moves to be played on click

pull/9400/head
Albert Ford 2021-07-12 09:34:38 -07:00
parent d790f5152b
commit 47d760e2ea
5 changed files with 30 additions and 7 deletions

View File

@ -112,6 +112,7 @@ export default class AnalyseCtrl {
cgConfig: any; // latest chessground config (useful for revert)
music?: any;
nvui?: NvuiPlugin;
pvUciQueue: Uci[];
constructor(readonly opts: AnalyseOpts, readonly redraw: Redraw) {
this.data = opts.data;
@ -523,7 +524,9 @@ export default class AnalyseCtrl {
}
this.jump(newPath);
this.redraw();
this.chessground.playPremove();
const queuedUci = this.pvUciQueue.shift();
if (queuedUci) this.playUci(queuedUci, this.pvUciQueue);
else this.chessground.playPremove();
}
addDests(dests: string, path: Tree.Path): void {
@ -799,7 +802,8 @@ export default class AnalyseCtrl {
this.redraw();
}
playUci(uci: Uci): void {
playUci(uci: Uci, uciQueue?: Uci[]): void {
this.pvUciQueue = uciQueue ?? [];
const move = parseUci(uci)!;
const to = makeSquare(move.to);
if (isNormal(move)) {
@ -821,6 +825,12 @@ export default class AnalyseCtrl {
);
}
playUciList(uciList: Uci[]): void {
this.pvUciQueue = uciList;
const firstUci = this.pvUciQueue.shift();
if (firstUci) this.playUci(firstUci, this.pvUciQueue);
}
explorerMove(uci: Uci) {
this.playUci(uci);
this.explorer.loading(true);

View File

@ -100,6 +100,7 @@ export interface ParentCtrl {
currentEvals(): NodeEvals;
ongoing: boolean;
playUci(uci: string): void;
playUciList(uciList: string[]): void;
getOrientation(): Color;
threatMode(): boolean;
getNode(): Tree.Node;

View File

@ -1,5 +1,5 @@
import * as winningChances from './winningChances';
import { defined } from 'common';
import { defined, notNull } from 'common';
import { Eval, CevalCtrl, ParentCtrl, NodeEvals } from './types';
import { h, VNode } from 'snabbdom';
import { Position } from 'chessops/chess';
@ -262,7 +262,13 @@ function getElUci(e: TouchEvent | MouseEvent): string | undefined {
);
}
function getElPvMoves(e: MouseEvent): (string | null)[] {
function getElUciList(e: TouchEvent | MouseEvent): string[] {
return getElPvMoves(e)
.filter(notNull)
.map(move => move.split('|')[1]);
}
function getElPvMoves(e: TouchEvent | MouseEvent): (string | null)[] {
const pvMoves: (string | null)[] = [];
$(e.target as HTMLElement)
@ -338,9 +344,9 @@ export function renderPvs(ctrl: ParentCtrl): VNode | undefined {
el.addEventListener('mouseout', () => ctrl.getCeval().setHovering(getElFen(el)));
for (const event of ['touchstart', 'mousedown']) {
el.addEventListener(event, (e: TouchEvent | MouseEvent) => {
const uci = getElUci(e);
if (uci) {
ctrl.playUci(uci);
const uciList = getElUciList(e);
if (uciList.length > (pvIndex ?? 0)) {
ctrl.playUciList(uciList.slice(0, (pvIndex ?? 0) + 1));
e.preventDefault();
}
});

View File

@ -174,6 +174,10 @@ export default function (opts: PuzzleOpts, redraw: Redraw): Controller {
sendMove(parseUci(uci)!);
}
function playUciList(uciList: Uci[]): void {
uciList.forEach(playUci);
}
function playUserMove(orig: Key, dest: Key, promotion?: Role): void {
sendMove({
from: parseSquare(orig)!,
@ -553,6 +557,7 @@ export default function (opts: PuzzleOpts, redraw: Redraw): Controller {
nextNodeBest,
userMove,
playUci,
playUciList,
showEvalGauge() {
return vm.showComputer() && ceval.enabled() && !outcome();
},

View File

@ -46,6 +46,7 @@ export interface Controller extends KeyboardController {
currentEvals(): NodeEvals;
ongoing: boolean;
playUci(uci: string): void;
playUciList(uciList: string[]): void;
getOrientation(): Color;
threatMode: Prop<boolean>;
getNode(): Tree.Node;