lila/ui/round/src/round.ts

23 lines
748 B
TypeScript

import { RoundData, Step } from './interfaces';
export const firstPly = (d: RoundData): number => d.steps[0].ply;
export const lastPly = (d: RoundData): number => lastStep(d).ply;
export const lastStep = (d: RoundData): Step => d.steps[d.steps.length - 1];
export const plyStep = (d: RoundData, ply: number): Step => d.steps[ply - firstPly(d)];
export const massage = (d: RoundData): void => {
if (d.clock) {
d.clock.showTenths = d.pref.clockTenths;
d.clock.showBar = d.pref.clockBar;
}
if (d.correspondence) d.correspondence.showBar = d.pref.clockBar;
if (['horde', 'crazyhouse'].includes(d.game.variant.key)) d.pref.showCaptured = false;
if (d.expiration) d.expiration.movedAt = Date.now() - d.expiration.idleMillis;
};