literate moves WIP
This commit is contained in:
parent
3c468659fc
commit
9cbe7e86df
|
@ -1226,7 +1226,6 @@ body.piece_letter .tview2 move {
|
|||
padding-right: 3px;
|
||||
white-space: nowrap;
|
||||
vertical-align: center;
|
||||
background: #aaa;
|
||||
}
|
||||
.tview2.literal move san {
|
||||
font-size: 1.185em;
|
||||
|
|
|
@ -82,7 +82,8 @@ export default class AnalyseCtrl {
|
|||
showComputer: StoredBooleanProp = storedProp('show-computer', true);
|
||||
keyboardHelp: boolean = location.hash === '#keyboard';
|
||||
threatMode: Prop<boolean> = prop(false);
|
||||
treeView: TreeView = 'literate';
|
||||
treeView: TreeView = li.storage.get('analyse.literate') ? 'literate' : 'column';
|
||||
// treeView: TreeView = 'column';
|
||||
cgVersion = {
|
||||
js: 1, // increment to recreate chessground
|
||||
dom: 1
|
||||
|
|
|
@ -31,8 +31,8 @@ function emptyMove(conceal?: Conceal): VNode {
|
|||
}
|
||||
|
||||
function renderChildrenOf(ctx: Ctx, node: Tree.Node, opts: Opts): MaybeVNodes | undefined {
|
||||
const cs = node.children;
|
||||
const main = cs[0];
|
||||
const cs = node.children,
|
||||
main = cs[0];
|
||||
if (!main) return;
|
||||
const conceal = opts.noConceal ? null : (opts.conceal || ctx.concealOf(true)(opts.parentPath + main.id, main));
|
||||
if (conceal === 'hide') return;
|
||||
|
@ -112,8 +112,7 @@ function renderMoveOf(ctx: Ctx, node: Tree.Node, opts: Opts): VNode {
|
|||
|
||||
function renderMainlineMoveOf(ctx: Ctx, node: Tree.Node, opts: Opts): VNode {
|
||||
const path = opts.parentPath + node.id,
|
||||
c = ctx.ctrl,
|
||||
classes = nodeClasses(c, path);
|
||||
classes = nodeClasses(ctx.ctrl, path);
|
||||
if (opts.conceal) classes[opts.conceal as string] = true;
|
||||
return h('move', {
|
||||
attrs: { p: path },
|
||||
|
@ -124,16 +123,11 @@ function renderMainlineMoveOf(ctx: Ctx, node: Tree.Node, opts: Opts): VNode {
|
|||
function renderVariationMoveOf(ctx: Ctx, node: Tree.Node, opts: Opts): VNode {
|
||||
const withIndex = opts.withIndex || node.ply % 2 === 1,
|
||||
path = opts.parentPath + node.id,
|
||||
active = path === ctx.ctrl.path,
|
||||
content: MaybeVNodes = [
|
||||
withIndex ? moveView.renderIndex(node.ply, true) : null,
|
||||
fixCrazySan(node.san!)
|
||||
],
|
||||
classes = {
|
||||
active,
|
||||
parent: !active && pathContains(ctx, path),
|
||||
context_menu: path === ctx.ctrl.contextMenuPath,
|
||||
};
|
||||
classes = nodeClasses(ctx.ctrl, path);
|
||||
if (opts.conceal) classes[opts.conceal as string] = true;
|
||||
if (node.glyphs) moveView.renderGlyphs(node.glyphs).forEach(g => content.push(g));
|
||||
return h('move', {
|
||||
|
@ -143,7 +137,7 @@ function renderVariationMoveOf(ctx: Ctx, node: Tree.Node, opts: Opts): VNode {
|
|||
}
|
||||
|
||||
function renderMoveAndChildrenOf(ctx: Ctx, node: Tree.Node, opts: Opts): MaybeVNodes {
|
||||
var path = opts.parentPath + node.id;
|
||||
const path = opts.parentPath + node.id;
|
||||
if (opts.truncate === 0) return [
|
||||
h('move', {
|
||||
attrs: { p: path }
|
||||
|
|
|
@ -3,8 +3,8 @@ import { VNode } from 'snabbdom/vnode'
|
|||
// import contextMenu from '../contextMenu';
|
||||
import { empty, defined } from 'common';
|
||||
// import { game } from 'game';
|
||||
// import { fixCrazySan } from 'chess';
|
||||
// import { path as treePath, ops as treeOps } from 'tree';
|
||||
import { fixCrazySan } from 'chess';
|
||||
import { path as treePath, ops as treeOps } from 'tree';
|
||||
import * as moveView from '../moveView';
|
||||
// import { authorText as commentAuthorText } from '../study/studyComments';
|
||||
import AnalyseCtrl from '../ctrl';
|
||||
|
@ -12,36 +12,109 @@ import { MaybeVNodes } from '../interfaces';
|
|||
import { autoScroll, renderMainlineCommentsOf, mainHook, nodeClasses } from './treeView';
|
||||
import { Ctx, Opts } from './treeView';
|
||||
|
||||
function renderNode(ctx: Ctx, node: Tree.Node, opts: Opts): MaybeVNodes {
|
||||
const path = opts.parentPath + node.id,
|
||||
c = ctx.ctrl;
|
||||
return [
|
||||
h('move', {
|
||||
attrs: { p: path },
|
||||
class: nodeClasses(c, path)
|
||||
}, [
|
||||
node.ply & 1 ? moveView.renderIndexText(node.ply, false) + ' ' : null,
|
||||
...moveView.renderMove(ctx, node)
|
||||
]),
|
||||
...(renderChildrenOf(ctx, node, {
|
||||
parentPath: path,
|
||||
isMainline: true
|
||||
}) || [])
|
||||
];
|
||||
}
|
||||
|
||||
function renderChildrenOf(ctx: Ctx, node: Tree.Node, opts: Opts): MaybeVNodes | undefined {
|
||||
const cs = node.children;
|
||||
const main = cs[0];
|
||||
const cs = node.children,
|
||||
main = cs[0];
|
||||
if (!main) return;
|
||||
return renderNode(ctx, main, {
|
||||
if (opts.isMainline) {
|
||||
const isWhite = main.ply % 2 === 1,
|
||||
commentTags: MaybeVNodes = []; //renderMainlineCommentsOf(ctx, main, conceal, true).filter(nonEmpty);
|
||||
if (!cs[1] && empty(commentTags)) return renderMoveAndChildrenOf(ctx, main, {
|
||||
parentPath: opts.parentPath,
|
||||
isMainline: true,
|
||||
});
|
||||
const mainChildren = renderChildrenOf(ctx, main, {
|
||||
parentPath: opts.parentPath + main.id,
|
||||
isMainline: true,
|
||||
});
|
||||
const passOpts = {
|
||||
parentPath: opts.parentPath,
|
||||
isMainline: true,
|
||||
};
|
||||
return (isWhite ? [moveView.renderIndex(main.ply, false)] : [] as MaybeVNodes).concat([
|
||||
renderMoveOf(ctx, main, passOpts),
|
||||
h('interrupt', commentTags.concat(
|
||||
renderLines(ctx, cs.slice(1), {
|
||||
parentPath: opts.parentPath,
|
||||
isMainline: true
|
||||
})
|
||||
))
|
||||
] as MaybeVNodes).concat(
|
||||
isWhite && mainChildren ? [
|
||||
moveView.renderIndex(main.ply, false),
|
||||
] : []).concat(mainChildren || []);
|
||||
}
|
||||
if (!cs[1]) return renderMoveAndChildrenOf(ctx, main, opts);
|
||||
return renderInlined(ctx, cs, opts) || [renderLines(ctx, cs, opts)];
|
||||
// return renderNode(ctx, main, {
|
||||
// parentPath: opts.parentPath,
|
||||
// isMainline: true
|
||||
// });
|
||||
}
|
||||
|
||||
function renderInlined(ctx: Ctx, nodes: Tree.Node[], opts: Opts): MaybeVNodes | undefined {
|
||||
// only 2 branches
|
||||
if (!nodes[1] || nodes[2]) return;
|
||||
// only if second branch has no sub-branches
|
||||
if (treeOps.hasBranching(nodes[1], 4)) return;
|
||||
return renderMoveAndChildrenOf(ctx, nodes[0], {
|
||||
parentPath: opts.parentPath,
|
||||
isMainline: true
|
||||
isMainline: opts.isMainline,
|
||||
inline: nodes[1]
|
||||
});
|
||||
}
|
||||
|
||||
function emptyMove(): VNode {
|
||||
return h('move.empty', '...');
|
||||
function renderLines(ctx: Ctx, nodes: Tree.Node[], opts: Opts): VNode {
|
||||
return h('lines', {
|
||||
class: { single: !nodes[1] }
|
||||
}, nodes.map(n => {
|
||||
if (n.comp && ctx.ctrl.retro && ctx.ctrl.retro.hideComputerLine(n, opts.parentPath))
|
||||
return h('line', 'Learn from this mistake');
|
||||
return h('line', renderMoveAndChildrenOf(ctx, n, {
|
||||
parentPath: opts.parentPath,
|
||||
isMainline: false,
|
||||
withIndex: true
|
||||
}));
|
||||
}));
|
||||
}
|
||||
|
||||
function renderMoveAndChildrenOf(ctx: Ctx, node: Tree.Node, opts: Opts): MaybeVNodes {
|
||||
const path = opts.parentPath + node.id;
|
||||
if (opts.truncate === 0) return [
|
||||
h('move', {
|
||||
attrs: { p: path }
|
||||
}, [h('index', '[...]')])
|
||||
];
|
||||
return ([renderMoveOf(ctx, node, opts)] as MaybeVNodes)
|
||||
// .concat(renderVariationCommentsOf(ctx, node))
|
||||
.concat(opts.inline ? renderInline(ctx, opts.inline, opts) : null)
|
||||
.concat(renderChildrenOf(ctx, node, {
|
||||
parentPath: path,
|
||||
isMainline: opts.isMainline,
|
||||
truncate: opts.truncate ? opts.truncate - 1 : undefined
|
||||
}) || []);
|
||||
}
|
||||
|
||||
function renderInline(ctx: Ctx, node: Tree.Node, opts: Opts): VNode {
|
||||
return h('inline', renderMoveAndChildrenOf(ctx, node, {
|
||||
withIndex: true,
|
||||
parentPath: opts.parentPath,
|
||||
isMainline: false
|
||||
}));
|
||||
}
|
||||
|
||||
function renderMoveOf(ctx: Ctx, node: Tree.Node, opts: Opts): VNode {
|
||||
const withIndex = opts.withIndex || node.ply % 2 === 1,
|
||||
path = opts.parentPath + node.id,
|
||||
content: MaybeVNodes = [
|
||||
withIndex ? moveView.renderIndex(node.ply, true) : null,
|
||||
fixCrazySan(node.san!)
|
||||
];
|
||||
if (node.glyphs) moveView.renderGlyphs(node.glyphs).forEach(g => content.push(g));
|
||||
return h('move', {
|
||||
attrs: { p: path },
|
||||
class: nodeClasses(ctx.ctrl, path)
|
||||
}, content);
|
||||
}
|
||||
|
||||
export default function(ctrl: AnalyseCtrl): VNode {
|
||||
|
|
Loading…
Reference in a new issue