Skip to content

Commit 9e7740a

Browse files
authored
refactor(config): remove special handling for font size 15 (@fehmer) (monkeytypegame#6693)
1 parent 2437222 commit 9e7740a

File tree

4 files changed

+30
-27
lines changed

4 files changed

+30
-27
lines changed

frontend/__tests__/root/config.spec.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,6 @@ describe("Config", () => {
443443

444444
//gets converted
445445
expect(Config.setFontSize(-1)).toBe(true);
446-
expect(Config.setFontSize("1" as any)).toBe(true);
447-
expect(Config.setFontSize("125" as any)).toBe(true);
448-
expect(Config.setFontSize("15" as any)).toBe(true);
449-
expect(Config.setFontSize("2" as any)).toBe(true);
450-
expect(Config.setFontSize("3" as any)).toBe(true);
451-
expect(Config.setFontSize("4" as any)).toBe(true);
452446

453447
expect(Config.setFontSize(0)).toBe(false);
454448
expect(Config.setFontSize("5" as any)).toBe(false);

frontend/__tests__/utils/config.spec.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,22 @@ describe("config.ts", () => {
193193
favThemes: ["80s_after_dark", "luna", "pulse"],
194194
},
195195
},
196+
{
197+
given: { fontSize: "2" },
198+
expected: { fontSize: 2 },
199+
},
200+
{
201+
given: { fontSize: "15" },
202+
expected: { fontSize: 1.5 },
203+
},
204+
{
205+
given: { fontSize: "125" },
206+
expected: { fontSize: 1.25 },
207+
},
208+
{
209+
given: { fontSize: 15 },
210+
expected: { fontSize: 15 },
211+
},
196212
])(`$given`, ({ given, expected }) => {
197213
const description = `given: ${JSON.stringify(
198214
given

frontend/src/ts/config.ts

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,34 +1770,13 @@ export function setFontSize(
17701770
if (fontSize < 0) {
17711771
fontSize = 1;
17721772
}
1773-
if (
1774-
typeof fontSize === "string" &&
1775-
["1", "125", "15", "2", "3", "4"].includes(fontSize)
1776-
) {
1777-
if (fontSize === "125") {
1778-
fontSize = 1.25;
1779-
} else if (fontSize === "15") {
1780-
fontSize = 1.5;
1781-
} else {
1782-
fontSize = parseInt(fontSize);
1783-
}
1784-
}
17851773

17861774
if (
17871775
!isConfigValueValid("font size", fontSize, ConfigSchemas.FontSizeSchema)
17881776
) {
17891777
return false;
17901778
}
17911779

1792-
// i dont know why the above check is not enough
1793-
// some people are getting font size 15 when it should be converted to 1.5
1794-
// after converting from the string to float system
1795-
1796-
// keeping this in for now, if you want a big font go 14.9 or something
1797-
if (fontSize === 15) {
1798-
fontSize = 1.5;
1799-
}
1800-
18011780
config.fontSize = fontSize;
18021781

18031782
$("#caret, #paceCaret, #liveStatsMini, #typingTest, #wordsInput").css(

frontend/src/ts/utils/config.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,19 @@ export function replaceLegacyValues(
142142
configObj.indicateTypos === false ? "off" : "replace";
143143
}
144144

145+
if (typeof configObj.fontSize === "string") {
146+
//legacy values use strings
147+
const oldValue = configObj.fontSize;
148+
let newValue = parseInt(oldValue);
149+
150+
if (oldValue === "125") {
151+
newValue = 1.25;
152+
} else if (oldValue === "15") {
153+
newValue = 1.5;
154+
}
155+
156+
configObj.fontSize = newValue;
157+
}
158+
145159
return configObj;
146160
}

0 commit comments

Comments
 (0)