Clean up configs
This commit is contained in:
parent
79638d5fa4
commit
0fddad6b45
1 changed files with 375 additions and 652 deletions
|
|
@ -1,25 +1,48 @@
|
|||
import { appConfig } from '../config';
|
||||
import { settings } from '../settings';
|
||||
import {
|
||||
MAX_MIRROR_SEGMENT_COUNT,
|
||||
MIN_MIRROR_SEGMENT_COUNT,
|
||||
} from '../game-loop/stroke-mirroring';
|
||||
import { DEFAULT_MIRROR_SEGMENT_COUNT, settings } from '../settings';
|
||||
import { queryRequiredElement } from '../utils/dom';
|
||||
|
||||
const MIRROR_SEGMENT_STEP = 1;
|
||||
const MIRROR_SEGMENT_OFF_LABEL = 'Mirror off';
|
||||
const MIRROR_SEGMENT_FALLBACK_NAME = 'slices';
|
||||
const MIRROR_SEGMENT_NAMES = {
|
||||
2: 'halves',
|
||||
3: 'thirds',
|
||||
4: 'quarters',
|
||||
5: 'fifths',
|
||||
6: 'sixths',
|
||||
7: 'sevenths',
|
||||
8: 'eighths',
|
||||
9: 'ninths',
|
||||
10: 'tenths',
|
||||
11: 'elevenths',
|
||||
12: 'twelfths',
|
||||
} satisfies Record<number, string>;
|
||||
|
||||
const clampMirrorSegmentCount = (value: number): number => {
|
||||
const { default: defaultCount, max, min } = appConfig.toolbar.mirror;
|
||||
const safeValue = Number.isFinite(value) ? value : defaultCount;
|
||||
return Math.min(max, Math.max(min, Math.round(safeValue)));
|
||||
const safeValue = Number.isFinite(value) ? value : DEFAULT_MIRROR_SEGMENT_COUNT;
|
||||
return Math.min(
|
||||
MAX_MIRROR_SEGMENT_COUNT,
|
||||
Math.max(MIN_MIRROR_SEGMENT_COUNT, Math.round(safeValue))
|
||||
);
|
||||
};
|
||||
|
||||
const getMirrorSegmentRatio = (count: number): number => {
|
||||
const { max, min } = appConfig.toolbar.mirror;
|
||||
return (count - min) / (max - min);
|
||||
return (
|
||||
(count - MIN_MIRROR_SEGMENT_COUNT) /
|
||||
(MAX_MIRROR_SEGMENT_COUNT - MIN_MIRROR_SEGMENT_COUNT)
|
||||
);
|
||||
};
|
||||
|
||||
const formatMirrorSegmentCount = (count: number): string =>
|
||||
count <= 1
|
||||
? appConfig.toolbar.mirror.offLabel
|
||||
? MIRROR_SEGMENT_OFF_LABEL
|
||||
: `${count} ${
|
||||
appConfig.toolbar.mirror.names[
|
||||
count as keyof typeof appConfig.toolbar.mirror.names
|
||||
] ?? appConfig.toolbar.mirror.fallbackSegmentName
|
||||
MIRROR_SEGMENT_NAMES[count as keyof typeof MIRROR_SEGMENT_NAMES] ??
|
||||
MIRROR_SEGMENT_FALLBACK_NAME
|
||||
}`;
|
||||
|
||||
interface MirrorSegmentControlOptions {
|
||||
|
|
@ -50,9 +73,9 @@ export class MirrorSegmentControl {
|
|||
settings.mirrorSegmentCount = count;
|
||||
}
|
||||
|
||||
this.slider.min = appConfig.toolbar.mirror.min.toString();
|
||||
this.slider.max = appConfig.toolbar.mirror.max.toString();
|
||||
this.slider.step = appConfig.toolbar.mirror.step.toString();
|
||||
this.slider.min = MIN_MIRROR_SEGMENT_COUNT.toString();
|
||||
this.slider.max = MAX_MIRROR_SEGMENT_COUNT.toString();
|
||||
this.slider.step = MIRROR_SEGMENT_STEP.toString();
|
||||
this.slider.value = count.toString();
|
||||
|
||||
const label = formatMirrorSegmentCount(count);
|
||||
|
|
|
|||
Loading…
Reference in a new issue