Skip to content

Commit

Permalink
broadcast: always show move clock, add pause icon
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Dec 28, 2024
1 parent e1b699a commit 10b9967
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 20 deletions.
6 changes: 6 additions & 0 deletions ui/analyse/css/_player-clock.scss
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ $clock-height: 20px;
tenths {
font-size: 80%;
}

i {
font-size: 0.7em;
margin-inline-end: 0.4em;
color: $c-accent;
}
}

.material {
Expand Down
2 changes: 1 addition & 1 deletion ui/analyse/css/study/_player.scss
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ $player-height: 1.6rem;

height: 100%;
font-size: 1.2em;
@include padding-direction(0, 0.8em, 0, 0.4em);
@include padding-direction(0, 0.8em, 0, 0.6em);

border-radius: 0 4px 0 0;
box-shadow: none;
Expand Down
2 changes: 1 addition & 1 deletion ui/analyse/css/study/relay/_layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ main.analyse.is-relay:not(.has-relay-tour) {
}
&.relay-in-variation {
.main-board cg-board {
filter: saturate(0.65) brightness(0.9);
filter: saturate(0.7) brightness(0.9);
}
}
}
10 changes: 2 additions & 8 deletions ui/analyse/src/study/playerBars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import renderClocks from '../view/clocks';
import type AnalyseCtrl from '../ctrl';
import { renderMaterialDiffs } from '../view/components';
import type { StudyPlayers, Federation, TagArray } from './interfaces';
import { findTag, isFinished, looksLikeLichessGame, resultOf } from './studyChapters';
import { findTag, looksLikeLichessGame, resultOf } from './studyChapters';
import { userTitle } from 'common/userLink';
import RelayPlayers, { fidePageLinkAttrs } from './relay/relayPlayers';
import { StudyCtrl } from './studyDeps';
Expand Down Expand Up @@ -41,13 +41,7 @@ export default function (ctrl: AnalyseCtrl): VNode[] | undefined {
// Ongoing game: the last mainline node, no matter what
function selectClockPath(ctrl: AnalyseCtrl, study: StudyCtrl): Tree.Path {
const gamePath = ctrl.gamePath || study.data.chapter.relayPath;
return isFinished(study.data.chapter)
? ctrl.node.clock
? ctrl.path
: gamePath
? intersection(ctrl.path, gamePath)
: ctrl.path
: gamePath || ctrl.path;
return ctrl.node.clock ? ctrl.path : gamePath ? intersection(ctrl.path, gamePath) : ctrl.path;
}

function renderPlayer(
Expand Down
2 changes: 1 addition & 1 deletion ui/analyse/src/study/relay/relayView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const backToLiveView = (ctrl: AnalyseCtrl) =>
? h(
'button.fbt.relay-back-to-live.text',
{
attrs: dataIcon(licon.RadioTower),
attrs: dataIcon(licon.PlayTriangle),
hook: bind(
'click',
() => {
Expand Down
47 changes: 38 additions & 9 deletions ui/analyse/src/view/clocks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { h, type VNode } from 'snabbdom';
import type AnalyseCtrl from '../ctrl';
import { notNull } from 'common';
import * as licon from 'common/licon';
import { iconTag } from 'common/snabbdom';

interface ClockOpts {
centis: number | undefined;
active: boolean;
cls: string;
showTenths: boolean;
pause: boolean;
}

export default function renderClocks(ctrl: AnalyseCtrl, path: Tree.Path): [VNode, VNode] | undefined {
const node = ctrl.tree.nodeAtPath(path),
Expand All @@ -26,24 +36,43 @@ export default function renderClocks(ctrl: AnalyseCtrl, path: Tree.Path): [VNode
}

const showTenths = !study?.relay;
const pause = !!ctrl.study?.isRelayAwayFromLive();

return [
renderClock(centis[0], isWhiteTurn, whitePov ? 'bottom' : 'top', showTenths),
renderClock(centis[1], !isWhiteTurn, whitePov ? 'top' : 'bottom', showTenths),
renderClock({
centis: centis[0],
active: isWhiteTurn,
cls: whitePov ? 'bottom' : 'top',
showTenths,
pause,
}),
renderClock({
centis: centis[1],
active: !isWhiteTurn,
cls: whitePov ? 'top' : 'bottom',
showTenths,
pause,
}),
];
}

const renderClock = (centis: number | undefined, active: boolean, cls: string, showTenths: boolean): VNode =>
h('div.analyse__clock.' + cls, { class: { active } }, clockContent(centis, showTenths));
const renderClock = (opts: ClockOpts): VNode =>
h('div.analyse__clock.' + opts.cls, { class: { active: opts.active } }, clockContent(opts));

function clockContent(centis: number | undefined, showTenths: boolean): Array<string | VNode> {
if (!centis && centis !== 0) return ['-'];
const date = new Date(centis * 10),
function clockContent(opts: ClockOpts): Array<string | VNode> {
if (!opts.centis && opts.centis !== 0) return ['-'];
const date = new Date(opts.centis * 10),
millis = date.getUTCMilliseconds(),
sep = ':',
baseStr = pad2(date.getUTCMinutes()) + sep + pad2(date.getUTCSeconds());
if (!showTenths || centis >= 360000) return [Math.floor(centis / 360000) + sep + baseStr];
return centis >= 6000 ? [baseStr] : [baseStr, h('tenths', '.' + Math.floor(millis / 100).toString())];
const timeNodes =
!opts.showTenths || opts.centis >= 360000
? [Math.floor(opts.centis / 360000) + sep + baseStr]
: opts.centis >= 6000
? [baseStr]
: [baseStr, h('tenths', '.' + Math.floor(millis / 100).toString())];
const pauseNodes = opts.pause ? [iconTag(licon.Pause)] : [];
return [...pauseNodes, ...timeNodes];
}

const pad2 = (num: number): string => (num < 10 ? '0' : '') + num;

0 comments on commit 10b9967

Please sign in to comment.