Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
avoid hardcoding pools TCs
we already get them from the server on page load
  • Loading branch information
ornicar committed Dec 29, 2025
commit 4343a6fe4258f84e85f97756a2c76575522a8000
1 change: 1 addition & 0 deletions ui/botPlay/src/setup/setupCtrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default class SetupCtrl {
s.increment,
0,
this.redraw,
[],
);
}

Expand Down
5 changes: 5 additions & 0 deletions ui/lib/src/setup/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@
export type InputValue = number;
// Visible value computed from the input value
export type RealValue = number;

export interface ClockConfig {
lim: number;
inc: number;
}
5 changes: 4 additions & 1 deletion ui/lib/src/setup/timeControl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { propWithEffect, type Prop } from '@/index';
import type { InputValue, RealValue } from './interfaces';
import type { ClockConfig, InputValue, RealValue } from './interfaces';
import { clockToSpeed } from '@/game';

export type TimeMode = 'realTime' | 'correspondence' | 'unlimited';
Expand All @@ -14,6 +14,7 @@ export class TimeControl {
readonly timeV: Prop<InputValue>,
readonly incrementV: Prop<InputValue>,
readonly daysV: Prop<InputValue>,
readonly presets: ClockConfig[],
) {}

time: () => RealValue = () => timeVToTime(this.timeV());
Expand Down Expand Up @@ -50,13 +51,15 @@ export const timeControlFromStoredValues = (
inc: RealValue,
days: RealValue,
onChange: () => void,
presets: ClockConfig[],
): TimeControl =>
new TimeControl(
mode,
modes,
propWithEffect(sliderInitVal(time, timeVToTime, 100, 14), onChange),
propWithEffect(sliderInitVal(inc, incrementVToIncrement, 100, 5), onChange),
propWithEffect(sliderInitVal(days, daysVToDays, 20, 7), onChange),
presets,
);

export const timeModes: { id: number; key: TimeMode; name: string }[] = [
Expand Down
17 changes: 1 addition & 16 deletions ui/lib/src/setup/view/timeControl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,6 @@ const showTime = (v: number) => {
return v.toString();
};

const PRESETS = [
// mirrors modules/pool/src/main/PoolList.scala
{ lim: 1, inc: 0 },
{ lim: 2, inc: 1 },
{ lim: 3, inc: 0 },
{ lim: 3, inc: 2 },
{ lim: 5, inc: 0 },
{ lim: 5, inc: 3 },
{ lim: 10, inc: 0 },
{ lim: 10, inc: 5 },
{ lim: 15, inc: 10 },
{ lim: 30, inc: 0 },
{ lim: 30, inc: 20 },
];

const blindModeTimePickers = (tc: TimeControl) => {
return [
renderTimeModePicker(tc),
Expand Down Expand Up @@ -166,7 +151,7 @@ export const timePickerAndSliders = (tc: TimeControl, minimumTimeRequiredIfReal:
]),
hl(
'div.presets',
PRESETS.map(p =>
tc.presets.map(p =>
hl(
'button.preset-btn',
{
Expand Down
5 changes: 2 additions & 3 deletions ui/lobby/src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ClockConfig } from 'lib/setup/interfaces';
import type { TimeMode } from 'lib/setup/timeControl';

export type Sort = 'rating' | 'time';
Expand Down Expand Up @@ -45,10 +46,8 @@ export interface Seek {
action: 'joinSeek' | 'cancelSeek';
}

export interface Pool {
export interface Pool extends ClockConfig {
id: PoolId;
lim: number;
inc: number;
perf: string;
}

Expand Down
1 change: 1 addition & 0 deletions ui/lobby/src/setupCtrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export default class SetupController {
forceOptions?.increment ?? storeProps.increment,
storeProps.days,
this.onPropChange,
this.root.pools,
);
this.gameMode = this.propWithApply(storeProps.gameMode);
this.ratingMin = this.propWithApply(storeProps.ratingMin);
Expand Down
Loading