Cleanup, start board key handlers

pull/7772/head
Tait Hoyem 2020-12-15 21:08:09 -07:00
parent e2767a0ad3
commit 9cef38aac3
2 changed files with 11 additions and 15 deletions

View File

@ -178,19 +178,6 @@ export function renderBoard(pieces: Pieces, pov: Color, pieceStyle: PieceStyle,
return orig;
}
}
/*
const doFileHeaders = (pov: Color): VNode => {
let fileHeaders = [
h('th'),
...files.map(file => h('th', {attrs: {scope: 'col'}}, file)),
h('th')
]
if (pov === 'black') fileHeaders.reverse();
return h('tr', fileHeaders);
}
const doRankHeader = (rank: Rank): VNode => {
return h('th', {attrs: {scope: 'row'}}, rank);
}*/
const doPieceButton = (rank: Rank, file: File, letter: string, text: string): VNode => {
return h('button', {
attrs: { rank: rank, file: file, piece: letter.toLowerCase()}

View File

@ -118,10 +118,11 @@ lichess.RoundNVUI = function(redraw: Redraw) {
h('div.board', {
hook: onInsert(el => {
const $board = $(el as HTMLTableElement);
$board.on('keypress', boardHandler());
// looking for specific elements tightly couples this file and nvui/chess.ts
// unsure if a bad thing?
const $buttons = $board.find('button');
$buttons.on('click', onPieceSelect());
$buttons.on('click', selectionHandler());
$buttons.on('keydown', arrowKeyHandler());
$buttons.on('keypress', pieceJumpingHandler());
})
@ -170,6 +171,14 @@ lichess.RoundNVUI = function(redraw: Redraw) {
const promotionRegex = /^([a-h]x?)?[a-h](1|8)=\w$/;
function boardHandler() {
return (ev: KeyboardEvent) => {
if (!ev.key.match(/^[1-8!@#$%^&*]$/)) return true;
console.log(ev.key);
return false;
}
}
function pieceJumpingHandler() {
return (ev: KeyboardEvent) => {
if (!ev.key.match(/^[kqrbnp]$/i)) return true;
@ -241,7 +250,7 @@ function arrowKeyHandler() {
};
}
function onPieceSelect() {
function selectionHandler() {
return (ev: MouseEvent) => {
// this depends on the current document structure. This may not be advisable in case the structure wil change.
const $evBtn = $(ev.target as HTMLButtonElement);