diff --git a/package.json b/package.json index 8e86fd0481..e2abeae2bd 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "ui/dasher", "ui/editor", "ui/game", + "ui/nvui", "ui/insight", "ui/learn", "ui/lobby", diff --git a/ui/nvui/package.json b/ui/nvui/package.json new file mode 100644 index 0000000000..b1503002a8 --- /dev/null +++ b/ui/nvui/package.json @@ -0,0 +1,33 @@ +{ + "name": "nvui", + "version": "1.0.0", + "description": "lichess.org non-visual user interface", + "main": "dist/main.js", + "types": "dist/main", + "repository": { + "type": "git", + "url": "https://github.com/ornicar/lila" + }, + "keywords": [ + "chess", + "lichess", + "non-visual", + "blind", + "accessibility" + ], + "author": "Thibault Duplessis", + "license": "AGPL-3.0", + "bugs": { + "url": "https://github.com/ornicar/lila/issues" + }, + "homepage": "https://github.com/ornicar/lila", + "scripts": { + "compile": "tsc" + }, + "devDependencies": { + "@types/lichess": "1.0.0", + "game": "1.0.0", + "typescript": "^3" + }, + "dependencies": {} +} diff --git a/ui/nvui/src/chess.ts b/ui/nvui/src/chess.ts new file mode 100644 index 0000000000..fb3240a8db --- /dev/null +++ b/ui/nvui/src/chess.ts @@ -0,0 +1,28 @@ +import { h } from 'snabbdom' +import { VNode } from 'snabbdom/vnode' +// import { GameData } from 'game'; +import { Pieces } from 'chessground/types'; + +export function piecesHtml(pieces: Pieces, style: string): VNode { + return h('div', ['white', 'black'].map(color => { + const lists: any = []; + ['king', 'queen', 'rook', 'bishop', 'knight', 'pawn'].forEach(role => { + const keys = []; + for (let key in pieces) { + if (pieces[key]!.color === color && pieces[key]!.role === role) keys.push(key); + } + if (keys.length) lists.push([`${role}${keys.length > 1 ? 's' : ''}`, ...keys]); + }); + return h('div', [ + h('h3', `${color} pieces`), + ...lists.map((l: any) => + `${l[0]}: ${l.slice(1).map((k: string) => renderKey(k, style)).join(', ')}` + ).join(', ') + ]); + })); +} + +const anna: { [letter: string]: string } = { a: 'anna', b: 'bella', c: 'cesar', d: 'david', e: 'eva', f: 'felix', g: 'gustav', h: 'hector' }; +export function renderKey(key: string, style: string): string { + return (style === 'anna' || style === 'full') ? `${anna[key[0]]} ${key[1]}` : key; +} diff --git a/ui/nvui/src/main.ts b/ui/nvui/src/main.ts new file mode 100644 index 0000000000..31d94319bb --- /dev/null +++ b/ui/nvui/src/main.ts @@ -0,0 +1,3 @@ +import * as chess from './chess'; + +export { chess }; diff --git a/ui/nvui/tsconfig.json b/ui/nvui/tsconfig.json new file mode 100644 index 0000000000..d069412405 --- /dev/null +++ b/ui/nvui/tsconfig.json @@ -0,0 +1,18 @@ +{ + "include": ["src/*.ts"], + "exclude": [], + "compilerOptions": { + "outDir": "./dist", + "declaration": true, + "noImplicitAny": true, + "strictNullChecks": true, + "noUnusedLocals": true, + "noEmitOnError": true, + "alwaysStrict": true, + "noImplicitReturns": true, + "noImplicitThis": true, + "noUnusedParameters": true, + "target": "es5", + "lib": ["DOM", "ES5"] + } +} diff --git a/ui/round/package.json b/ui/round/package.json index 2326d421ce..5ae1cd2365 100644 --- a/ui/round/package.json +++ b/ui/round/package.json @@ -38,6 +38,7 @@ "chessground": "^7.3", "common": "1.0.0", "game": "1.0.0", + "nvui": "1.0.0", "snabbdom": "ornicar/snabbdom#0.7.1-lichess" } } diff --git a/ui/round/src/plugins/nvui.ts b/ui/round/src/plugins/nvui.ts index 74ad0aca1a..d18c31bbd4 100644 --- a/ui/round/src/plugins/nvui.ts +++ b/ui/round/src/plugins/nvui.ts @@ -13,6 +13,7 @@ import { Step, DecodedDests, Position, Redraw } from '../interfaces'; import { Player } from 'game'; import { files } from 'chessground/types'; import { invRanks } from 'chessground/util'; +import { renderKey } from 'nvui/chess'; type Sans = { [key: string]: Uci; @@ -284,11 +285,6 @@ function readSan(s: Step, style: string) { return move; } -const anna: { [letter: string]: string } = { a: 'anna', b: 'bella', c: 'cesar', d: 'david', e: 'eva', f: 'felix', g: 'gustav', h: 'hector' }; -function annaKey(key: string, style: string): string { - return (style === 'anna' || style === 'full') ? `${anna[key[0]]} ${key[1]}` : key; -} - function renderPlayer(ctrl: RoundController, player: Player) { return player.ai ? ctrl.trans('aiNameLevelAiLevel', 'Stockfish', player.ai) : userHtml(ctrl, player); }