forked from gbtami/pychess-variants
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalysis.ts
207 lines (187 loc) · 8.45 KB
/
analysis.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
import { h, VNode } from "snabbdom";
import { _ } from './i18n';
import { AnalysisController } from './analysisCtrl';
import { gameInfo } from './gameInfo';
import { selectVariant, VARIANTS } from './variants';
import { renderTimeago } from './datetime';
import { spinner } from './view';
import { PyChessModel } from "./types";
function runGround(vnode: VNode, model: PyChessModel) {
const el = vnode.elm as HTMLElement;
const ctrl = new AnalysisController(el, model);
window['onFSFline'] = ctrl.onFSFline;
}
function leftSide(model: PyChessModel) {
if (model["gameId"] !== "") {
return [
gameInfo(model),
h('div#roundchat'),
];
} else {
const setVariant = (isInput: boolean) => {
let e;
e = document.getElementById('variant') as HTMLSelectElement;
const variant = e.options[e.selectedIndex].value;
if (isInput) window.location.assign('/analysis/' + variant);
}
const vVariant = model.variant || "chess";
return h('div.container', [
h('div', [
h('label', { attrs: { for: "variant" } }, _("Variant")),
selectVariant("variant", vVariant, () => setVariant(true), () => setVariant(false)),
]),
]);
}
}
export function embedView(model: PyChessModel): VNode[] {
const variant = VARIANTS[model.variant];
const chess960 = model.chess960 === 'True';
return [
h('div.embed-app', [
h(`selection#mainboard.${variant.boardFamily}.${variant.pieceFamily}.${variant.ui.boardMark}`, [
h('div.cg-wrap.' + variant.board.cg, { hook: { insert: (vnode) => runGround(vnode, model) } }),
]),
h('div.pocket-top', [
h('div.' + variant.pieceFamily + '.' + model["variant"], [
h('div.cg-wrap.pocket', [
h('div#pocket0'),
]),
]),
]),
h('div.analysis-tools', [
h('div.movelist-block', [
h('div#movelist'),
]),
h('div#misc-info', [
h('div#misc-infow'),
h('div#misc-info-center'),
h('div#misc-infob'),
]),
]),
h('div#move-controls'),
h('div.pocket-bot', [
h('div.' + variant.pieceFamily + '.' + model["variant"], [
h('div.cg-wrap.pocket', [
h('div#pocket1'),
]),
]),
]),
]),
h('div.footer', [
h('a.gamelink', { attrs: { rel: "noopener", target: "_blank", href: '/' + model["gameId"] } },
[variant.displayName(chess960), '•', model.wtitle, model.wplayer, 'vs', model.btitle, model.bplayer].join(' ')
),
]),
];
}
export function analysisView(model: PyChessModel): VNode[] {
const variant = VARIANTS[model.variant];
const isAnalysisBoard = model["gameId"] === "";
const tabindexCt = (isAnalysisBoard) ? '-1' : '0';
const tabindexPgn = (isAnalysisBoard) ? '0' : '-1';
renderTimeago();
const onClickFullfen = () => {
const el = document.getElementById('fullfen') as HTMLInputElement;
el.focus();
el.select();
}
return [
h('div.analysis-app', [
h('aside.sidebar-first', leftSide(model)),
h(`selection#mainboard.${variant.boardFamily}.${variant.pieceFamily}.${variant.ui.boardMark}`, [
h('div#anal-clock-top'),
h('div.cg-wrap.' + variant.board.cg, { hook: { insert: (vnode) => runGround(vnode, model) } }),
h('div#anal-clock-bottom'),
]),
h('div#gauge', [
h('div.black', { props: { style: "height: 50%;" } }),
h('div.tick', { props: { style: "height: 12.5%;" } }),
h('div.tick', { props: { style: "height: 25%;" } }),
h('div.tick', { props: { style: "height: 37.5%;" } }),
h('div.tick.zero', { props: { style: "height: 50%;" } }),
h('div.tick', { props: { style: "height: 62.5%;" } }),
h('div.tick', { props: { style: "height: 75%;" } }),
h('div.tick', { props: { style: "height: 87.5%;" } }),
]),
h('div.pocket-top', [
h('div.' + variant.pieceFamily + '.' + model["variant"], [
h('div.cg-wrap.pocket', [
h('div#pocket0'),
]),
]),
]),
h('div.analysis-tools', [
h('div#ceval', [
h('div.engine', [
h('score#score', ''),
h('div.info', [
'Fairy-Stockfish 14+ ',
h('span.nnue', { props: { title: _('Multi-threaded WebAssembly (classical evaluation)') } } , 'HCE'),
h('br'),
h('info#info', _('in local browser'))
]),
h('label.switch', [
h('input#input', {
props: {
name: "engine",
type: "checkbox",
},
}),
h('span#slider.sw-slider'),
]),
]),
]),
h('div.pvbox', [
h('div#pv1'),
h('div#pv2'),
h('div#pv3'),
h('div#pv4'),
h('div#pv5'),
]),
h('div.movelist-block', [
h('div#movelist'),
]),
h('div#vari'),
h('div#misc-info', [
h('div#misc-infow'),
h('div#misc-info-center'),
h('div#misc-infob'),
]),
]),
h('div#move-controls'),
h('div.pocket-bot', [
h('div.' + variant.pieceFamily + '.' + model["variant"], [
h('div.cg-wrap.pocket', [
h('div#pocket1'),
]),
]),
]),
h('under-left#spectators'),
h('under-board', [
h('div.chart-container', {attrs: {id: 'panel-1', role: 'tabpanel', tabindex: '-1', 'aria-labelledby': 'tab-1'}}, [
h('button#request-analysis'),
h('div#chart-analysis'),
h('div#loader-wrapper', [spinner()])
]),
h('div.chart-container', {attrs: {id: 'panel-2', role: 'tabpanel', tabindex: '-1', 'aria-labelledby': 'tab-2'}}, [
h('div#chart-movetime'),
]),
h('div.ctable-container', {attrs: {id: 'panel-3', role: 'tabpanel', tabindex: tabindexCt, 'aria-labelledby': 'tab-3'}}),
h('div', {attrs: {id: 'panel-4', role: 'tabpanel', tabindex: tabindexPgn, 'aria-labelledby': 'tab-4'}}, [
h('div#fentext', [
h('strong', 'FEN'),
h('input#fullfen', {attrs: {readonly: true, spellcheck: false}, on: { click: onClickFullfen } })
]),
h('div#copyfen'),
h('div#pgntext'),
]),
h('div', {attrs: {role: 'tablist', 'aria-label': 'Analysis Tabs'}}, [
h('span', {attrs: {role: 'tab', 'aria-selected': false, 'aria-controls': 'panel-1', id: 'tab-1', tabindex: '-1'}}, _('Computer analysis')),
h('span', {attrs: {role: 'tab', 'aria-selected': true, 'aria-controls': 'panel-2', id: 'tab-1', tabindex: '-1'}}, _('Move times')),
h('span', {attrs: {role: 'tab', 'aria-selected': false, 'aria-controls': 'panel-3', id: 'tab-3', tabindex: tabindexCt}}, _('Crosstable')),
h('span', {attrs: {role: 'tab', 'aria-selected': false, 'aria-controls': 'panel-4', id: 'tab-4', tabindex: tabindexPgn}}, _('FEN & PGN')),
]),
]),
]),
];
}