Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion ui/analyse/src/view/clocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type AnalyseCtrl from '../ctrl';
import { defined, notNull } from 'lib';
import * as licon from 'lib/licon';
import { iconTag } from 'lib/snabbdom';
import { formatClockTimeVerbal } from 'lib/game/clock/clockView';

interface ClockOpts {
centis: number | undefined;
Expand Down Expand Up @@ -59,7 +60,11 @@ export default function renderClocks(ctrl: AnalyseCtrl, path: Tree.Path): [VNode
}

const renderClock = (opts: ClockOpts): VNode =>
h('div.analyse__clock.' + opts.cls, { class: { active: opts.active } }, clockContent(opts));
h(
'div.analyse__clock.' + opts.cls,
{ class: { active: opts.active } },
site.blindMode ? clockContentNvui(opts) : clockContent(opts),
);

function clockContent(opts: ClockOpts): Array<string | VNode> {
if (!opts.centis && opts.centis !== 0) return ['-'];
Expand All @@ -77,4 +82,9 @@ function clockContent(opts: ClockOpts): Array<string | VNode> {
return [...pauseNodes, ...timeNodes];
}

function clockContentNvui(opts: ClockOpts): Array<string | VNode> {
if (!opts.centis && opts.centis !== 0) return ['None'];
return [formatClockTimeVerbal(opts.centis * 10)];
}

const pad2 = (num: number): string => (num < 10 ? '0' : '') + num;
35 changes: 27 additions & 8 deletions ui/lib/src/game/clock/clockView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,35 @@ const pad2 = (num: number): string => (num < 10 ? '0' : '') + num;
const sepHigh = '<sep>:</sep>';
const sepLow = '<sep class="low">:</sep>';

export function formatClockTimeVerbal(time: Millis): string {
const totalSeconds = Math.floor(time / 1000);
const days = Math.floor(totalSeconds / (3600 * 24));
const hours = Math.floor((totalSeconds % (3600 * 24)) / 3600);
const minutes = Math.floor((totalSeconds % 3600) / 60);
const seconds = totalSeconds % 60;

const parts: string[] = [];
if (days > 0) {
parts.push(i18n.site.nbDays(days));
if (hours > 0) parts.push(i18n.site.nbHours(hours));
} else if (hours > 0) {
parts.push(i18n.site.nbHours(hours));
if (minutes > 0) parts.push(i18n.site.nbMinutes(minutes));
} else {
if (minutes > 0) parts.push(i18n.site.nbMinutes(minutes));
if (seconds > 0 || parts.length === 0) parts.push(i18n.site.nbSeconds(seconds));
}

if (parts.length === 1) {
return parts[0];
} else {
return parts.join(', ');
}
}

function formatClockTime(time: Millis, showTenths: boolean, isRunning: boolean, nvui: boolean) {
const date = new Date(time);
if (nvui)
return (
(time >= 3600000 ? Math.floor(time / 3600000) + 'H:' : '') +
date.getUTCMinutes() +
'M:' +
date.getUTCSeconds() +
'S'
);
if (nvui) return formatClockTimeVerbal(time);
const millis = date.getUTCMilliseconds(),
sep = isRunning && millis < 500 ? sepLow : sepHigh,
baseStr = pad2(date.getUTCMinutes()) + sep + pad2(date.getUTCSeconds());
Expand Down
2 changes: 1 addition & 1 deletion ui/lib/src/nvui/chess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ export function boardCommandsHandler() {
const $boardLive = $('.boardstatus');
if (ev.key === 'o' && key) $boardLive.text(key);
else if (ev.key === 'l') $boardLive.text($('p.lastMove').text());
else if (ev.key === 't') $boardLive.text(`${$('.nvui .botc').text()}, ${$('.nvui .topc').text()}`);
else if (ev.key === 't') $boardLive.text(`${$('.nvui .botc').text()} - ${$('.nvui .topc').text()}`);
};
}

Expand Down
3 changes: 2 additions & 1 deletion ui/round/src/corresClock/corresClockView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { looseH as h, type VNode } from 'lib/snabbdom';
import type { TopOrBottom } from 'lib/game/game';
import type { CorresClockController } from './corresClockCtrl';
import { moretime } from '../view/button';
import { formatClockTimeVerbal } from 'lib/game/clock/clockView';

const prefixInteger = (num: number, length: number): string =>
(num / Math.pow(10, length)).toFixed(length).slice(2);
Expand Down Expand Up @@ -39,7 +40,7 @@ export default function (
): VNode {
const millis = ctrl.millisOf(color),
update = (el: HTMLElement) => {
el.innerHTML = formatClockTime(millis);
el.innerHTML = site.blindMode ? formatClockTimeVerbal(millis) : formatClockTime(millis);
},
isPlayer = ctrl.root.data.player.color === color,
direction = document.dir === 'rtl' && millis < 86400 * 1000 ? 'ltr' : undefined;
Expand Down
2 changes: 1 addition & 1 deletion ui/round/src/plugins/round.nvui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ const inputCommands: InputCommand[] = [
{
cmd: 'clock',
help: i18n.keyboardMove.readOutClocks,
cb: notify => notify($('.nvui .botc').text() + ', ' + $('.nvui .topc').text()),
cb: notify => notify($('.nvui .botc').text() + ' - ' + $('.nvui .topc').text()),
alt: 'c',
},
{
Expand Down