Skip to content

Commit

Permalink
nvui study chapter select
Browse files Browse the repository at this point in the history
  • Loading branch information
allanjoseph98 committed Dec 31, 2024
1 parent 4c4e607 commit 6dd0ca8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
5 changes: 4 additions & 1 deletion ui/analyse/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ export default class AnalyseCtrl {
if (this.data.forecast) this.forecast = new ForecastCtrl(this.data.forecast, this.data, redraw);
if (this.opts.wiki) this.wiki = wikiTheory();
if (site.blindMode)
site.asset.loadEsm<NvuiPlugin>('analyse.nvui', { init: this }).then(nvui => (this.nvui = nvui));
site.asset.loadEsm<NvuiPlugin>('analyse.nvui', { init: this }).then(nvui => {
this.nvui = nvui;
this.redraw();
});

this.instanciateEvalCache();

Expand Down
33 changes: 32 additions & 1 deletion ui/analyse/src/plugins/analyse.nvui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ export function initModule(ctrl: AnalyseController) {
});
return h('main.analyse', [
h('div.nvui', [
studyDetails(ctrl),
h('h1', 'Textual representation'),
h('h2', 'Game info'),
...['white', 'black'].map((color: Color) =>
h('p', [color + ' player: ', renderPlayer(ctrl, playerByColor(d, color))]),
),
h('p', `${d.game.rated ? 'Rated' : 'Casual'} ${d.game.perf}`),
h('p', `${d.game.rated ? 'Rated' : 'Casual'} ${d.game.perf || d.game.variant.name}`),
d.clock ? h('p', `Clock: ${d.clock.initial / 60} + ${d.clock.increment}`) : null,
h('h2', 'Moves'),
h('p.moves', { attrs: { role: 'log', 'aria-live': 'off' } }, renderCurrentLine(ctrl, style)),
Expand Down Expand Up @@ -508,3 +509,33 @@ function jumpLine(ctrl: AnalyseController, delta: number) {
const newPath = prevPath + prevNode.children[newI].id;
ctrl.userJumpIfCan(newPath);
}

function studyDetails(ctrl: AnalyseController): MaybeVNode {
const study = ctrl.study;
return (
study &&
h('div.study-details', [
h('h2', 'Study details'),
h('span', `Title: ${study.data.name}. By: ${study.data.ownerId}`),
h('br'),
h('label.chapters', [
h('h2', 'Current chapter:'),
h(
'select',
study.chapters.list.all().map((ch, i) =>
h(
'option',
{
hook: bind('mousedown', () => study.setChapter(ch.id), ctrl.redraw),
attrs: {
selected: ch.id === study.currentChapter().id,
},
},
`${i + 1}. ${ch.name}`,
),
),
),
]),
])
);
}

0 comments on commit 6dd0ca8

Please sign in to comment.