round blind mode command shortcuts

This commit is contained in:
Thibault Duplessis 2019-11-10 14:47:22 -06:00
parent 106c20f397
commit eeea77f965
2 changed files with 16 additions and 9 deletions

View file

@ -3,13 +3,13 @@ import { Pieces } from 'chessground/types';
export const commands = {
piece: {
help: '/p: Read locations of a piece type. Example: /p N, /p k.',
help: 'p: Read locations of a piece type. Example: p N, p k.',
apply(c: string, pieces: Pieces, style: Style): string | undefined {
return tryC(c, /^p ([p|n|b|r|q|k])$/i, p => renderPieceKeys(pieces, p, style));
}
},
scan: {
help: '/scan: Read pieces on a rank or file. Example: /scan a, /scan 1.',
help: 'scan: Read pieces on a rank or file. Example: scan a, scan 1.',
apply(c: string, pieces: Pieces): string | undefined {
return tryC(c, /^scan ([a-h1-8])$/i, p => renderPiecesOn(pieces, p));
}

View file

@ -121,14 +121,14 @@ window.lichess.RoundNVUI = function(redraw: Redraw) {
h('h2', 'Commands'),
h('p', [
'Type these commands in the move input.', h('br'),
'/c: Read clocks.', h('br'),
'/l: Read last move.', h('br'),
'c: Read clocks.', h('br'),
'l: Read last move.', h('br'),
commands.piece.help, h('br'),
commands.scan.help, h('br'),
'/abort: Abort game.', h('br'),
'/resign: Resign game.', h('br'),
'/draw: Offer or accept draw.', h('br'),
'/takeback: Offer or accept take back.', h('br')
'abort: Abort game.', h('br'),
'resign: Resign game.', h('br'),
'draw: Offer or accept draw.', h('br'),
'takeback: Offer or accept take back.', h('br')
]),
h('h2', 'Promotion'),
h('p', [
@ -145,7 +145,8 @@ const promotionRegex = /^([a-h]x?)?[a-h](1|8)=\w$/;
function onSubmit(ctrl: RoundController, notify: (txt: string) => void, style: () => Style, $input: JQuery) {
return function() {
const input = castlingFlavours($input.val());
let input = castlingFlavours($input.val().trim());
if (isShortCommand(input)) input = '/' + input;
if (input[0] === '/') onCommand(ctrl, notify, input.slice(1), style());
else {
const d = ctrl.data,
@ -169,6 +170,12 @@ function onSubmit(ctrl: RoundController, notify: (txt: string) => void, style: (
};
}
const shortCommands = ['c', 'clock', 'l', 'last', 'abort', 'resign', 'draw', 'takeback', 'p', 'scan'];
function isShortCommand(input: string): boolean {
return shortCommands.includes(input.split(' ')[0]);
}
function onCommand(ctrl: RoundController, notify: (txt: string) => void, c: string, style: Style) {
if (c == 'c' || c == 'clock') notify($('.nvui .botc').text() + ', ' + $('.nvui .topc').text());
else if (c == 'l' || c == 'last') notify($('.lastMove').text());