From d193002bf81d3fc65b6eaccedcd581422195fc1d Mon Sep 17 00:00:00 2001 From: Allan Joseph Date: Mon, 7 Oct 2024 19:23:44 +0530 Subject: [PATCH] use existing `clockToSpeed` function --- pnpm-lock.yaml | 3 +++ ui/lobby/package.json | 1 + ui/lobby/src/setupCtrl.ts | 22 +++++++--------------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f4404dd1009e..d99ac3f10f9e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -460,6 +460,9 @@ importers: debounce-promise: specifier: ^3.1.2 version: 3.1.2 + game: + specifier: workspace:* + version: link:../game snabbdom: specifier: 3.5.1 version: 3.5.1 diff --git a/ui/lobby/package.json b/ui/lobby/package.json index 2743aff68dac..84077b751fbd 100644 --- a/ui/lobby/package.json +++ b/ui/lobby/package.json @@ -16,6 +16,7 @@ "common": "workspace:*", "dasher": "workspace:*", "debounce-promise": "^3.1.2", + "game": "workspace:*", "snabbdom": "3.5.1" }, "lichess": { diff --git a/ui/lobby/src/setupCtrl.ts b/ui/lobby/src/setupCtrl.ts index a73b5cbb9371..2f646e19c3dd 100644 --- a/ui/lobby/src/setupCtrl.ts +++ b/ui/lobby/src/setupCtrl.ts @@ -2,6 +2,7 @@ import { Prop, propWithEffect } from 'common'; import { debounce } from 'common/timing'; import * as xhr from 'common/xhr'; import { storedJsonProp, StoredJsonProp } from 'common/storage'; +import { clockToSpeed } from 'game'; import LobbyController from './ctrl'; import { ForceSetupOptions, @@ -23,21 +24,12 @@ import { variants, } from './options'; -const getPerf = (variant: VariantKey, timeMode: TimeMode, time: RealValue, increment: RealValue): Perf => { - if (!['standard', 'fromPosition'].includes(variant)) return variant as Perf; - if (timeMode !== 'realTime') return 'correspondence'; - - const totalGameTime = time * 60 + increment * 40; - return totalGameTime < 30 - ? 'ultraBullet' - : totalGameTime < 180 - ? 'bullet' - : totalGameTime < 480 - ? 'blitz' - : totalGameTime < 1500 - ? 'rapid' - : 'classical'; -}; +const getPerf = (variant: VariantKey, timeMode: TimeMode, time: RealValue, increment: RealValue): Perf => + variant != 'standard' && variant != 'fromPosition' + ? variant + : timeMode !== 'realTime' + ? 'correspondence' + : clockToSpeed(time * 60, increment); export default class SetupController { root: LobbyController;