pass spacing to parsePresetWidths

This commit is contained in:
Peter Fajdiga
2024-10-03 00:03:18 +02:00
parent 3ff7688e42
commit 1c61f22353
3 changed files with 6 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
type PresetWidth = ((screenWidth: number, spacing: number) => number);
type PresetWidth = (maxWidth: number) => number;
function parsePresetWidths(presetWidths: string): PresetWidth[] {
function parsePresetWidths(presetWidths: string, spacing: number): PresetWidth[] {
function parseNumberSafe(str: string) {
const num = Number(str);
if (isNaN(num) || num <= 0) {
@@ -17,7 +17,7 @@ function parsePresetWidths(presetWidths: string): PresetWidth[] {
}
function getRatioFunction(ratio: number) {
return (screenWidth: number, spacing: number) => Math.floor((screenWidth + spacing) * ratio - spacing);
return (maxWidth: number) => Math.floor((maxWidth + spacing) * ratio - spacing);
}
return presetWidths.split(",").map((widthStr: string) => {

View File

@@ -11,7 +11,7 @@ class World {
let presetWidths: PresetWidth[] = [];
try {
presetWidths = parsePresetWidths(config.presetWidths);
presetWidths = parsePresetWidths(config.presetWidths, config.gapsInnerHorizontal);
} catch (error: any) {
notificationInvalidPresetWidths.sendEvent();
log("failed to parse presetWidths:", error);

View File

@@ -17,12 +17,12 @@ tests.register("parsePresetWidths", 1, () => {
];
function applyPresetWidths(presetWidths: PresetWidth[]) {
return presetWidths.map(f => f(screenWidth, spacing));
return presetWidths.map(f => f(screenWidth));
}
for (const testCase of testCases) {
try {
const result = parsePresetWidths(testCase.str);
const result = parsePresetWidths(testCase.str, spacing);
assert(!testCase.error);
assertArrayEqual(applyPresetWidths(result), testCase.result!);
} catch (error) {