Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ui/chess/src/moveRootCtrl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface MoveRootCtrl {
pluginMove: (orig: Key, dest: Key, prom: Role | undefined) => void;
pluginMove: (orig: Key, dest: Key, prom: Role | undefined, preConfirmed?: boolean /* = false */) => void;
redraw: () => void;
flipNow: () => void;
offerDraw?: (v: boolean, immediately?: boolean) => void;
Expand All @@ -12,6 +12,7 @@ export interface MoveRootCtrl {
blindfold?: (v?: boolean) => boolean;
speakClock?: () => void;
goBerserk?: () => void;
confirmMoveToggle?: () => boolean;
}

export interface MoveUpdate {
Expand Down
25 changes: 12 additions & 13 deletions ui/round/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { make as makeSocket, type RoundSocket } from './socket';
import * as title from './title';
import * as blur from './blur';
import viewStatus from 'game/view/status';
import type { MoveMetadata as CgMoveMetadata } from 'chessground/types';
import { ClockController } from './clock/clockCtrl';
import { CorresClockController } from './corresClock/corresClockCtrl';
import MoveOn from './moveOn';
Expand Down Expand Up @@ -72,7 +71,7 @@ export default class RoundController implements MoveRootCtrl {
firstSeconds = true;
flip = false;
menu: Toggle;
confirmMoveToggle: Toggle = toggle(true);
confirmMoveToggle: Toggle;
loading = false;
loadingTimeout: number;
redirecting = false;
Expand Down Expand Up @@ -123,7 +122,7 @@ export default class RoundController implements MoveRootCtrl {
);

this.setQuietMode();

this.confirmMoveToggle = toggle(d.pref.submitMove);
this.moveOn = new MoveOn(this, 'move-on');
if (!opts.local) this.transientMove = new TransientMove(this.socket);

Expand Down Expand Up @@ -158,12 +157,12 @@ export default class RoundController implements MoveRootCtrl {
setTimeout(this.showExpiration, 250);
};

private onUserMove = (orig: Key, dest: Key, meta: CgMoveMetadata) => {
private onUserMove = (orig: Key, dest: Key, meta: MoveMetadata) => {
if (!this.keyboardMove?.usedSan) ab.move(this, meta, pubsub.emit);
if (!this.startPromotion(orig, dest, meta)) this.sendMove(orig, dest, undefined, meta);
};

private onUserNewPiece = (role: Role, key: Key, meta: CgMoveMetadata) => {
private onUserNewPiece = (role: Role, key: Key, meta: MoveMetadata) => {
if (!this.replaying() && crazyValid(this.data, role, key)) {
this.sendNewPiece(role, key, !!meta.predrop);
} else this.jump(this.ply);
Expand All @@ -178,7 +177,7 @@ export default class RoundController implements MoveRootCtrl {
} else site.sound.move({ name: 'move', filter: 'game' });
};

private startPromotion = (orig: Key, dest: Key, meta: CgMoveMetadata) =>
private startPromotion = (orig: Key, dest: Key, meta: MoveMetadata) =>
this.promotion.start(
orig,
dest,
Expand All @@ -190,7 +189,7 @@ export default class RoundController implements MoveRootCtrl {
this.keyboardMove?.justSelected(),
);

private onPremove = (orig: Key, dest: Key, meta: CgMoveMetadata) => this.startPromotion(orig, dest, meta);
private onPremove = (orig: Key, dest: Key, meta: MoveMetadata) => this.startPromotion(orig, dest, meta);

private onCancelPremove = () => this.promotion.cancelPrePromotion();

Expand Down Expand Up @@ -293,7 +292,7 @@ export default class RoundController implements MoveRootCtrl {

setTitle = (): void => title.set(this);

actualSendMove = (tpe: string, data: any, meta: MoveMetadata = {}): void => {
actualSendMove = (tpe: string, data: any, meta: MoveMetadata = { premove: false }): void => {
const socketOpts: SocketOpts = {
sign: this.sign,
ackable: true,
Expand All @@ -319,29 +318,29 @@ export default class RoundController implements MoveRootCtrl {
this.redraw();
};

pluginMove = (orig: Key, dest: Key, role?: Role): void => {
pluginMove = (orig: Key, dest: Key, role?: Role, preConfirmed?: boolean): void => {
if (!role) {
this.chessground.move(orig, dest);
this.chessground.state.movable.dests = undefined;
this.chessground.state.turnColor = opposite(this.chessground.state.turnColor);

if (this.startPromotion(orig, dest, { premove: false })) return;
}
this.sendMove(orig, dest, role, { premove: false });
this.sendMove(orig, dest, role, { premove: false, preConfirmed });
};

pluginUpdate = (fen: string): void => {
this.voiceMove?.update({ fen, canMove: this.canMove() });
this.keyboardMove?.update({ fen, canMove: this.canMove() });
};

sendMove = (orig: Key, dest: Key, prom: Role | undefined, meta: CgMoveMetadata): void => {
sendMove = (orig: Key, dest: Key, prom: Role | undefined, meta: MoveMetadata): void => {
const move: SocketMove = { u: orig + dest };
if (prom) move.u += prom === 'knight' ? 'n' : prom[0];
if (blur.get()) move.b = 1;
this.resign(false);

if (this.data.pref.submitMove && this.confirmMoveToggle() && !meta.premove) {
if (!meta.preConfirmed && this.confirmMoveToggle() && !meta.premove) {
if (site.sound.speech()) {
const spoken = `${speakable(sanOf(readFen(this.stepAt(this.ply).fen), move.u))}. confirm?`;
site.sound.say(spoken, false, true);
Expand All @@ -357,7 +356,7 @@ export default class RoundController implements MoveRootCtrl {
const drop: SocketDrop = { role, pos: key };
if (blur.get()) drop.b = 1;
this.resign(false);
if (this.data.pref.submitMove && this.confirmMoveToggle() && !isPredrop) {
if (this.confirmMoveToggle() && !isPredrop) {
this.toSubmit = drop;
this.redraw();
} else {
Expand Down
5 changes: 3 additions & 2 deletions ui/round/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { ChatCtrl, ChatPlugin } from 'chat';
import * as Prefs from 'common/prefs';
import type { EnhanceOpts } from 'common/richText';
import type { RoundSocket } from './socket';
import type { MoveMetadata as CgMoveMetadata } from 'chessground/types';

export { type RoundSocket } from './socket';
export { type CorresClockData } from './corresClock/corresClockCtrl';
Expand Down Expand Up @@ -196,8 +197,8 @@ export interface Pref {
resizeHandle: Prefs.ShowResizeHandle;
}

export interface MoveMetadata {
premove?: boolean;
export interface MoveMetadata extends CgMoveMetadata {
preConfirmed?: boolean;
justDropped?: Role;
justCaptured?: Piece;
}
Expand Down
4 changes: 3 additions & 1 deletion ui/round/src/view/boardMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export default function (ctrl: RoundController): LooseVNode {
),
menu.voiceInput(boolPrefXhrToggle('voice', !!ctrl.voiceMove), !spectator),
menu.keyboardInput(boolPrefXhrToggle('keyboardMove', !!ctrl.keyboardMove), !spectator),
!spectator && d.pref.submitMove ? menu.confirmMove(ctrl.confirmMoveToggle) : undefined,
!spectator && (d.pref.submitMove || ctrl.voiceMove)
? menu.confirmMove(ctrl.confirmMoveToggle)
: undefined,
]),
h('section.board-menu__links', [
h(
Expand Down
10 changes: 5 additions & 5 deletions ui/voice/src/move/voice.move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,9 @@ export function initModule({
// trim choices to clarity window
options = options.filter(([, m]) => m.cost - lowestCost <= clarityThreshold);

if (!timer() && options.length === 1 && options[0][1].cost < 0.3) {
if (!timer() && options.length === 1 && (options[0][1].cost < 0.3 || root.confirmMoveToggle?.())) {
console.info('chooseMoves', `chose '${options[0][0]}' cost=${options[0][1].cost}`);
submit(options[0][0]);
submit(options[0][0], false);
return true;
}
return ambiguate(options);
Expand All @@ -321,7 +321,7 @@ export function initModule({
if (preferred && timer()) {
choiceTimeout = setTimeout(
() => {
submit(options[0][0]);
submit(options[0][0], false);
choiceTimeout = undefined;
voice.mic.setRecognizer('default');
},
Expand Down Expand Up @@ -349,7 +349,7 @@ export function initModule({
buildSquares();
}

function submit(uci: Uci) {
function submit(uci: Uci, preConfirmed = true) {
clearMoveProgress();
if (uci.length < 3) {
const dests = [...new Set(ucis.filter(x => x.length === 4 && x.startsWith(uci)))];
Expand All @@ -362,7 +362,7 @@ export function initModule({
const role = promo(uci);
cg.cancelMove();
if (role) promote(cg, dest(uci), role);
root.pluginMove(src(uci), dest(uci), role);
root.pluginMove(src(uci), dest(uci), role, preConfirmed);
return true;
}

Expand Down