use opening from explorer
parent
eb6aca471f
commit
652cc0c448
|
@ -265,7 +265,6 @@ declare namespace Tree {
|
||||||
ceval?: ClientEval;
|
ceval?: ClientEval;
|
||||||
eval?: ServerEval;
|
eval?: ServerEval;
|
||||||
tbhit: TablebaseHit | undefined | null;
|
tbhit: TablebaseHit | undefined | null;
|
||||||
opening?: Opening;
|
|
||||||
glyphs?: Glyph[];
|
glyphs?: Glyph[];
|
||||||
clock?: Clock;
|
clock?: Clock;
|
||||||
parentClock?: Clock;
|
parentClock?: Clock;
|
||||||
|
@ -302,11 +301,6 @@ declare namespace Tree {
|
||||||
shapes?: Shape[]
|
shapes?: Shape[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Opening {
|
|
||||||
name: string;
|
|
||||||
eco: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
type GlyphId = number;
|
type GlyphId = number;
|
||||||
|
|
||||||
interface Glyph {
|
interface Glyph {
|
||||||
|
|
|
@ -13,7 +13,6 @@
|
||||||
@import '../../../tree/css/tree';
|
@import '../../../tree/css/tree';
|
||||||
@import '../../../ceval/css/ceval';
|
@import '../../../ceval/css/ceval';
|
||||||
@import '../../../ceval/css/eval-gauge';
|
@import '../../../ceval/css/eval-gauge';
|
||||||
@import '../../../chess/css/opening';
|
|
||||||
@import '../../../chess/css/control';
|
@import '../../../chess/css/control';
|
||||||
@import '../../../chess/css/promotion';
|
@import '../../../chess/css/promotion';
|
||||||
@import '../../../chess/css/variant-style';
|
@import '../../../chess/css/variant-style';
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
@import '../../../common/css/component/fbt';
|
@import '../../../common/css/component/fbt';
|
||||||
@import '../../../common/css/form/cmn-toggle';
|
@import '../../../common/css/form/cmn-toggle';
|
||||||
@import '../../../tree/css/tree';
|
@import '../../../tree/css/tree';
|
||||||
@import '../../../chess/css/opening';
|
|
||||||
@import '../../../chess/css/control';
|
@import '../../../chess/css/control';
|
||||||
@import '../../../chess/css/zh-pocket';
|
@import '../../../chess/css/zh-pocket';
|
||||||
|
|
||||||
|
|
|
@ -504,8 +504,8 @@ export default class AnalyseCtrl {
|
||||||
this.chessground.playPremove();
|
this.chessground.playPremove();
|
||||||
}
|
}
|
||||||
|
|
||||||
addDests(dests: string, path: Tree.Path, opening?: Tree.Opening): void {
|
addDests(dests: string, path: Tree.Path): void {
|
||||||
this.tree.addDests(dests, path, opening);
|
this.tree.addDests(dests, path);
|
||||||
if (path === this.path) {
|
if (path === this.path) {
|
||||||
this.showGround();
|
this.showGround();
|
||||||
// this.redraw();
|
// this.redraw();
|
||||||
|
|
|
@ -61,7 +61,7 @@ export default function(root: AnalyseCtrl, opts, allow: boolean): ExplorerCtrl {
|
||||||
const fen = root.node.fen;
|
const fen = root.node.fen;
|
||||||
const request: JQueryPromise<ExplorerData> = (withGames && tablebaseRelevant(effectiveVariant, fen)) ?
|
const request: JQueryPromise<ExplorerData> = (withGames && tablebaseRelevant(effectiveVariant, fen)) ?
|
||||||
xhr.tablebase(opts.tablebaseEndpoint, effectiveVariant, fen) :
|
xhr.tablebase(opts.tablebaseEndpoint, effectiveVariant, fen) :
|
||||||
xhr.opening(opts.endpoint, effectiveVariant, fen, config.data, withGames);
|
xhr.opening(opts.endpoint, effectiveVariant, root.nodeList[0].fen, root.nodeList.slice(1).map(s => s.uci!), config.data, withGames);
|
||||||
|
|
||||||
request.then((res: ExplorerData) => {
|
request.then((res: ExplorerData) => {
|
||||||
cache[fen] = res;
|
cache[fen] = res;
|
||||||
|
@ -77,7 +77,7 @@ export default function(root: AnalyseCtrl, opts, allow: boolean): ExplorerCtrl {
|
||||||
}, 250, true);
|
}, 250, true);
|
||||||
|
|
||||||
const empty = {
|
const empty = {
|
||||||
opening: true,
|
isOpening: true,
|
||||||
moves: {}
|
moves: {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ export default function(root: AnalyseCtrl, opts, allow: boolean): ExplorerCtrl {
|
||||||
if (node.ply > 50 && !tablebaseRelevant(effectiveVariant, node.fen)) {
|
if (node.ply > 50 && !tablebaseRelevant(effectiveVariant, node.fen)) {
|
||||||
cache[node.fen] = empty;
|
cache[node.fen] = empty;
|
||||||
}
|
}
|
||||||
const cached = cache[root.node.fen];
|
const cached = cache[node.fen];
|
||||||
if (cached) {
|
if (cached) {
|
||||||
movesAway(cached.moves.length ? 0 : movesAway() + 1);
|
movesAway(cached.moves.length ? 0 : movesAway() + 1);
|
||||||
loading(false);
|
loading(false);
|
||||||
|
@ -135,7 +135,7 @@ export default function(root: AnalyseCtrl, opts, allow: boolean): ExplorerCtrl {
|
||||||
const masterCache = {};
|
const masterCache = {};
|
||||||
return (fen: Fen): JQueryPromise<OpeningData> => {
|
return (fen: Fen): JQueryPromise<OpeningData> => {
|
||||||
if (masterCache[fen]) return $.Deferred().resolve(masterCache[fen]).promise() as JQueryPromise<OpeningData>;
|
if (masterCache[fen]) return $.Deferred().resolve(masterCache[fen]).promise() as JQueryPromise<OpeningData>;
|
||||||
return xhr.opening(opts.endpoint, 'standard', fen, {
|
return xhr.opening(opts.endpoint, 'standard', fen, [], {
|
||||||
db: {
|
db: {
|
||||||
selected: prop('masters')
|
selected: prop('masters')
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { view as renderConfig } from './explorerConfig';
|
||||||
import { bind, dataIcon } from '../util';
|
import { bind, dataIcon } from '../util';
|
||||||
import { winnerOf } from './explorerUtil';
|
import { winnerOf } from './explorerUtil';
|
||||||
import AnalyseCtrl from '../ctrl';
|
import AnalyseCtrl from '../ctrl';
|
||||||
import { isOpening, isTablebase, TablebaseMoveStats, OpeningMoveStats, OpeningGame } from './interfaces';
|
import { isOpening, isTablebase, TablebaseMoveStats, OpeningData, OpeningMoveStats, OpeningGame } from './interfaces';
|
||||||
|
|
||||||
function resultBar(move: OpeningMoveStats): VNode {
|
function resultBar(move: OpeningMoveStats): VNode {
|
||||||
const sum = move.white + move.draws + move.black;
|
const sum = move.white + move.draws + move.black;
|
||||||
|
@ -46,18 +46,26 @@ function moveTableAttributes(ctrl: AnalyseCtrl, fen: Fen) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function showMoveTable(ctrl: AnalyseCtrl, moves: OpeningMoveStats[], fen: Fen): VNode | null {
|
function showMoveTable(ctrl: AnalyseCtrl, data: OpeningData): VNode | null {
|
||||||
if (!moves.length) return null;
|
if (!data.moves.length) return null;
|
||||||
const trans = ctrl.trans.noarg;
|
const trans = ctrl.trans.noarg;
|
||||||
return h('table.moves', [
|
return h('table.moves', [
|
||||||
h('thead', [
|
h('thead', [
|
||||||
|
data.opening ? h('tr', [
|
||||||
|
h('th.title', {
|
||||||
|
attrs: {
|
||||||
|
colspan: 3,
|
||||||
|
title: `${data.opening.eco} ${data.opening.name}`,
|
||||||
|
}
|
||||||
|
}, [h('strong', data.opening.eco), ' ', data.opening.name])
|
||||||
|
]) : null,
|
||||||
h('tr', [
|
h('tr', [
|
||||||
h('th.title', trans('move')),
|
h('th.title', trans('move')),
|
||||||
h('th.title', trans('games')),
|
h('th.title', trans('games')),
|
||||||
h('th.title', trans('whiteDrawBlack'))
|
h('th.title', trans('whiteDrawBlack'))
|
||||||
])
|
])
|
||||||
]),
|
]),
|
||||||
h('tbody', moveTableAttributes(ctrl, fen), moves.map(move => {
|
h('tbody', moveTableAttributes(ctrl, data.fen), data.moves.map(move => {
|
||||||
return h('tr', {
|
return h('tr', {
|
||||||
key: move.uci,
|
key: move.uci,
|
||||||
attrs: {
|
attrs: {
|
||||||
|
@ -237,7 +245,7 @@ function show(ctrl: AnalyseCtrl) {
|
||||||
const trans = ctrl.trans.noarg,
|
const trans = ctrl.trans.noarg,
|
||||||
data = ctrl.explorer.current();
|
data = ctrl.explorer.current();
|
||||||
if (data && isOpening(data)) {
|
if (data && isOpening(data)) {
|
||||||
const moveTable = showMoveTable(ctrl, data.moves, data.fen),
|
const moveTable = showMoveTable(ctrl, data),
|
||||||
recentTable = showGameTable(ctrl, trans('recentGames'), data.recentGames || []),
|
recentTable = showGameTable(ctrl, trans('recentGames'), data.recentGames || []),
|
||||||
topTable = showGameTable(ctrl, trans('topGames'), data.topGames || []);
|
topTable = showGameTable(ctrl, trans('topGames'), data.topGames || []);
|
||||||
if (moveTable || recentTable || topTable) lastShow = h('div.data', [moveTable, topTable, recentTable]);
|
if (moveTable || recentTable || topTable) lastShow = h('div.data', [moveTable, topTable, recentTable]);
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import { OpeningData, TablebaseData } from './interfaces';
|
import { OpeningData, TablebaseData } from './interfaces';
|
||||||
|
|
||||||
export function opening(endpoint: string, variant: VariantKey, fen: Fen, config, withGames: boolean): JQueryPromise<OpeningData> {
|
export function opening(endpoint: string, variant: VariantKey, fen: Fen, play: string[], config, withGames: boolean): JQueryPromise<OpeningData> {
|
||||||
let url: string;
|
let url: string;
|
||||||
const params: any = {
|
const params: any = {
|
||||||
fen,
|
fen,
|
||||||
moves: 12
|
play: play.join(',')
|
||||||
};
|
};
|
||||||
if (!withGames) params.topGames = params.recentGames = 0;
|
if (!withGames) params.topGames = params.recentGames = 0;
|
||||||
if (config.db.selected() === 'masters') url = '/master';
|
if (config.db.selected() === 'masters') url = '/master';
|
||||||
|
@ -19,7 +19,7 @@ export function opening(endpoint: string, variant: VariantKey, fen: Fen, config,
|
||||||
data: params,
|
data: params,
|
||||||
cache: true
|
cache: true
|
||||||
}).then((data: Partial<OpeningData>) => {
|
}).then((data: Partial<OpeningData>) => {
|
||||||
data.opening = true;
|
data.isOpening = true;
|
||||||
data.fen = fen;
|
data.fen = fen;
|
||||||
return data as OpeningData;
|
return data as OpeningData;
|
||||||
});
|
});
|
||||||
|
|
|
@ -40,7 +40,7 @@ export interface ExplorerConfigCtrl {
|
||||||
export interface ExplorerData {
|
export interface ExplorerData {
|
||||||
fen: Fen;
|
fen: Fen;
|
||||||
moves: MoveStats[];
|
moves: MoveStats[];
|
||||||
opening?: true;
|
isOpening?: true;
|
||||||
tablebase?: true;
|
tablebase?: true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,6 +48,12 @@ export interface OpeningData extends ExplorerData {
|
||||||
moves: OpeningMoveStats[];
|
moves: OpeningMoveStats[];
|
||||||
topGames?: OpeningGame[];
|
topGames?: OpeningGame[];
|
||||||
recentGames?: OpeningGame[];
|
recentGames?: OpeningGame[];
|
||||||
|
opening?: Opening;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Opening {
|
||||||
|
eco: string;
|
||||||
|
name: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface OpeningGame {
|
export interface OpeningGame {
|
||||||
|
@ -99,7 +105,7 @@ export interface TablebaseMoveStats extends MoveStats {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isOpening(m: ExplorerData): m is OpeningData {
|
export function isOpening(m: ExplorerData): m is OpeningData {
|
||||||
return !!m.opening;
|
return !!m.isOpening;
|
||||||
}
|
}
|
||||||
export function isTablebase(m: ExplorerData): m is TablebaseData {
|
export function isTablebase(m: ExplorerData): m is TablebaseData {
|
||||||
return !!m.tablebase;
|
return !!m.tablebase;
|
||||||
|
|
|
@ -87,7 +87,7 @@ export function make(send: SocketSend, ctrl: AnalyseCtrl): Socket {
|
||||||
clearTimeout(anaDestsTimeout);
|
clearTimeout(anaDestsTimeout);
|
||||||
if (!data.ch || data.ch === currentChapterId()) {
|
if (!data.ch || data.ch === currentChapterId()) {
|
||||||
anaDestsCache[data.path] = data;
|
anaDestsCache[data.path] = data;
|
||||||
ctrl.addDests(data.dests, data.path, data.opening);
|
ctrl.addDests(data.dests, data.path);
|
||||||
} else
|
} else
|
||||||
console.log('socket handler node got wrong chapter id', data);
|
console.log('socket handler node got wrong chapter id', data);
|
||||||
},
|
},
|
||||||
|
|
|
@ -321,7 +321,7 @@ export default function(data: StudyData, ctrl: AnalyseCtrl, tagTypes: TagTypes,
|
||||||
if (relay) relay.applyChapterRelay(data.chapter, d.relay);
|
if (relay) relay.applyChapterRelay(data.chapter, d.relay);
|
||||||
const newPath = ctrl.tree.addNode(node, position.path);
|
const newPath = ctrl.tree.addNode(node, position.path);
|
||||||
if (!newPath) return xhrReload();
|
if (!newPath) return xhrReload();
|
||||||
ctrl.tree.addDests(d.d, newPath, d.o);
|
ctrl.tree.addDests(d.d, newPath);
|
||||||
if (sticky) data.position.path = newPath;
|
if (sticky) data.position.path = newPath;
|
||||||
if ((sticky && vm.mode.sticky) || (
|
if ((sticky && vm.mode.sticky) || (
|
||||||
position.path === ctrl.path &&
|
position.path === ctrl.path &&
|
||||||
|
|
|
@ -77,7 +77,6 @@ function makeConcealOf(ctrl: AnalyseCtrl): ConcealOf | undefined {
|
||||||
function renderAnalyse(ctrl: AnalyseCtrl, concealOf?: ConcealOf) {
|
function renderAnalyse(ctrl: AnalyseCtrl, concealOf?: ConcealOf) {
|
||||||
return h('div.analyse__moves.areplay', [
|
return h('div.analyse__moves.areplay', [
|
||||||
(ctrl.embed && ctrl.study) ? h('div.chapter-name', ctrl.study.currentChapter().name) : null,
|
(ctrl.embed && ctrl.study) ? h('div.chapter-name', ctrl.study.currentChapter().name) : null,
|
||||||
renderOpeningBox(ctrl),
|
|
||||||
renderTreeView(ctrl, concealOf),
|
renderTreeView(ctrl, concealOf),
|
||||||
].concat(renderResult(ctrl)));
|
].concat(renderResult(ctrl)));
|
||||||
}
|
}
|
||||||
|
@ -228,17 +227,6 @@ function controls(ctrl: AnalyseCtrl) {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderOpeningBox(ctrl: AnalyseCtrl) {
|
|
||||||
let opening = ctrl.tree.getOpening(ctrl.nodeList);
|
|
||||||
if (!opening && !ctrl.path) opening = ctrl.data.game.opening;
|
|
||||||
if (opening) return h('div.opening_box', {
|
|
||||||
attrs: { title: opening.eco + ' ' + opening.name }
|
|
||||||
}, [
|
|
||||||
h('strong', opening.eco),
|
|
||||||
' ' + opening.name
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function forceInnerCoords(ctrl: AnalyseCtrl, v: boolean) {
|
function forceInnerCoords(ctrl: AnalyseCtrl, v: boolean) {
|
||||||
if (ctrl.data.pref.coords == 2)
|
if (ctrl.data.pref.coords == 2)
|
||||||
$('body').toggleClass('coords-in', v).toggleClass('coords-out', !v);
|
$('body').toggleClass('coords-in', v).toggleClass('coords-out', !v);
|
||||||
|
|
|
@ -1,6 +0,0 @@
|
||||||
.opening_box {
|
|
||||||
@extend %roboto, %nowrap-ellipsis;
|
|
||||||
padding: 5px;
|
|
||||||
border-bottom: $border;
|
|
||||||
background: $c-bg-zebra;
|
|
||||||
}
|
|
|
@ -10,11 +10,10 @@ export interface TreeWrapper {
|
||||||
nodeAtPath(path: Tree.Path): Tree.Node;
|
nodeAtPath(path: Tree.Path): Tree.Node;
|
||||||
getNodeList(path: Tree.Path): Tree.Node[];
|
getNodeList(path: Tree.Path): Tree.Node[];
|
||||||
longestValidPath(path: string): Tree.Path;
|
longestValidPath(path: string): Tree.Path;
|
||||||
getOpening(nodeList: Tree.Node[]): Tree.Opening | undefined;
|
|
||||||
updateAt(path: Tree.Path, update: (node: Tree.Node) => void): MaybeNode;
|
updateAt(path: Tree.Path, update: (node: Tree.Node) => void): MaybeNode;
|
||||||
addNode(node: Tree.Node, path: Tree.Path): Tree.Path | undefined;
|
addNode(node: Tree.Node, path: Tree.Path): Tree.Path | undefined;
|
||||||
addNodes(nodes: Tree.Node[], path: Tree.Path): Tree.Path | undefined;
|
addNodes(nodes: Tree.Node[], path: Tree.Path): Tree.Path | undefined;
|
||||||
addDests(dests: string, path: Tree.Path, opening?: Tree.Opening): MaybeNode;
|
addDests(dests: string, path: Tree.Path): MaybeNode;
|
||||||
setShapes(shapes: Tree.Shape[], path: Tree.Path): MaybeNode;
|
setShapes(shapes: Tree.Shape[], path: Tree.Path): MaybeNode;
|
||||||
setCommentAt(comment: Tree.Comment, path: Tree.Path): MaybeNode;
|
setCommentAt(comment: Tree.Comment, path: Tree.Path): MaybeNode;
|
||||||
deleteCommentAt(id: string, path: Tree.Path): MaybeNode;
|
deleteCommentAt(id: string, path: Tree.Path): MaybeNode;
|
||||||
|
@ -116,14 +115,6 @@ export function build(root: Tree.Node): TreeWrapper {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function getOpening(nodeList: Tree.Node[]): Tree.Opening | undefined {
|
|
||||||
var opening: Tree.Opening | undefined;
|
|
||||||
nodeList.forEach(function(node: Tree.Node) {
|
|
||||||
opening = node.opening || opening;
|
|
||||||
});
|
|
||||||
return opening;
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateAt(path: Tree.Path, update: (node: Tree.Node) => void): Tree.Node | undefined {
|
function updateAt(path: Tree.Path, update: (node: Tree.Node) => void): Tree.Node | undefined {
|
||||||
const node = nodeAtPathOrNull(path);
|
const node = nodeAtPathOrNull(path);
|
||||||
if (node) {
|
if (node) {
|
||||||
|
@ -223,14 +214,12 @@ export function build(root: Tree.Node): TreeWrapper {
|
||||||
nodeAtPath,
|
nodeAtPath,
|
||||||
getNodeList,
|
getNodeList,
|
||||||
longestValidPath: (path: string) => longestValidPathFrom(root, path),
|
longestValidPath: (path: string) => longestValidPathFrom(root, path),
|
||||||
getOpening,
|
|
||||||
updateAt,
|
updateAt,
|
||||||
addNode,
|
addNode,
|
||||||
addNodes,
|
addNodes,
|
||||||
addDests(dests: string, path: Tree.Path, opening?: Tree.Opening) {
|
addDests(dests: string, path: Tree.Path) {
|
||||||
return updateAt(path, function(node: Tree.Node) {
|
return updateAt(path, function(node: Tree.Node) {
|
||||||
node.dests = dests;
|
node.dests = dests;
|
||||||
if (opening) node.opening = opening;
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
setShapes(shapes: Tree.Shape[], path: Tree.Path) {
|
setShapes(shapes: Tree.Shape[], path: Tree.Path) {
|
||||||
|
|
Loading…
Reference in New Issue