replay moves with arrow keys from the keyboard move input
This commit is contained in:
parent
96d81313d9
commit
4ec83e197e
|
@ -193,14 +193,14 @@ export default class RoundController {
|
|||
userJump = (ply: Ply): void => {
|
||||
this.cancelMove();
|
||||
this.chessground.selectSquare(null);
|
||||
if (ply != this.ply && this.jump(ply)) speech.userJump(this, ply);
|
||||
if (ply != this.ply && this.jump(ply)) speech.userJump(this, this.ply);
|
||||
else this.redraw();
|
||||
};
|
||||
|
||||
isPlaying = () => game.isPlayerPlaying(this.data);
|
||||
|
||||
jump = (ply: Ply): boolean => {
|
||||
if (ply < round.firstPly(this.data) || ply > round.lastPly(this.data)) return false;
|
||||
ply = Math.max(round.firstPly(this.data), Math.min(round.lastPly(this.data), ply));
|
||||
const isForwardStep = ply === this.ply + 1;
|
||||
this.ply = ply;
|
||||
this.justDropped = undefined;
|
||||
|
|
|
@ -25,6 +25,7 @@ export interface KeyboardMove {
|
|||
hasSelected(): cg.Key | undefined;
|
||||
confirmMove(): void;
|
||||
usedSan: boolean;
|
||||
jump(delta: number): void;
|
||||
}
|
||||
|
||||
export function ctrl(root: RoundController, step: Step, redraw: Redraw): KeyboardMove {
|
||||
|
@ -82,7 +83,11 @@ export function ctrl(root: RoundController, step: Step, redraw: Redraw): Keyboar
|
|||
confirmMove() {
|
||||
root.submitMove(true);
|
||||
},
|
||||
usedSan
|
||||
usedSan,
|
||||
jump(delta: number) {
|
||||
root.userJump(root.ply + delta);
|
||||
redraw();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -103,7 +108,8 @@ export function render(ctrl: KeyboardMove) {
|
|||
confirmMove: ctrl.confirmMove,
|
||||
san: ctrl.san,
|
||||
drop: ctrl.drop,
|
||||
promote: ctrl.promote
|
||||
promote: ctrl.promote,
|
||||
jump: ctrl.jump
|
||||
}));
|
||||
});
|
||||
})
|
||||
|
|
|
@ -67,7 +67,11 @@ function makeBindings(opts: any, submit: Function, clear: Function) {
|
|||
focusChat();
|
||||
clear();
|
||||
}
|
||||
else if (v === '' && e.which === 13) opts.confirmMove();
|
||||
else if (v === '' && e.which == 13) opts.confirmMove();
|
||||
else if (e.which == 37) opts.jump(-1);
|
||||
else if (e.which == 38) opts.jump(-999);
|
||||
else if (e.which == 39) opts.jump(1);
|
||||
else if (e.which == 40) opts.jump(999);
|
||||
else submit(v, e.which === 13);
|
||||
});
|
||||
opts.input.addEventListener('focus', function() {
|
||||
|
@ -76,6 +80,10 @@ function makeBindings(opts: any, submit: Function, clear: Function) {
|
|||
opts.input.addEventListener('blur', function() {
|
||||
opts.setFocus(false);
|
||||
});
|
||||
// prevent default on arrow keys: they only replay moves
|
||||
opts.input.addEventListener('keydown', function(e: KeyboardEvent) {
|
||||
if (e.which > 36 && e.which < 41) e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
function sanToUci(san: string, sans: DecodedDests): Key[] | undefined {
|
||||
|
|
Loading…
Reference in a new issue