Skip to content

Commit 4ec8aea

Browse files
authored
fix(config): auto-resolve monkey live stats conflicts (@d1rshan) (#7715)
Adds handling for the invalid monkey + live text stats combination by auto-resolving conflicting settings instead of blocking them. Behavior: - enabling monkey while live speed style or live accuracy style is text will automatically set those conflicting live stat styles to off - setting live speed style to text while monkey is enabled will automatically disable monkey - setting live accuracy style to text while monkey is enabled will automatically disable monkey This follows the existing overrideConfig pattern used for other conflicting settings, where the latest selection takes priority. Also adds tests to cover these auto-resolved config combinations. Closes #7714
1 parent b6a0d10 commit 4ec8aea

File tree

3 files changed

+123
-0
lines changed

3 files changed

+123
-0
lines changed

frontend/__tests__/root/config-metadata.spec.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,15 @@ describe("ConfigMeta", () => {
163163
{ value: false, given: { tapeMode: "word" } },
164164
{ value: true, given: { tapeMode: "word" }, fail: true },
165165
],
166+
monkey: [{ value: false, given: { liveSpeedStyle: "text" } }],
167+
liveSpeedStyle: [
168+
{ value: "mini", given: { monkey: true } },
169+
{ value: "text", given: { monkey: true } },
170+
],
171+
liveAccStyle: [
172+
{ value: "mini", given: { monkey: true } },
173+
{ value: "text", given: { monkey: true } },
174+
],
166175
};
167176

168177
it.for(
@@ -244,6 +253,45 @@ describe("ConfigMeta", () => {
244253
expected: { freedomMode: false, stopOnError: "off" },
245254
},
246255
],
256+
monkey: [
257+
{
258+
value: false,
259+
given: { liveSpeedStyle: "text", liveAccStyle: "text" },
260+
expected: {
261+
liveSpeedStyle: "text",
262+
liveAccStyle: "text",
263+
},
264+
},
265+
{
266+
value: true,
267+
given: { liveSpeedStyle: "text", liveAccStyle: "text" },
268+
expected: { liveSpeedStyle: "mini", liveAccStyle: "mini" },
269+
},
270+
],
271+
liveSpeedStyle: [
272+
{
273+
value: "mini",
274+
given: { monkey: true },
275+
expected: { monkey: true },
276+
},
277+
{
278+
value: "text",
279+
given: { monkey: true },
280+
expected: { monkey: false },
281+
},
282+
],
283+
liveAccStyle: [
284+
{
285+
value: "mini",
286+
given: { monkey: true },
287+
expected: { monkey: true },
288+
},
289+
{
290+
value: "text",
291+
given: { monkey: true },
292+
expected: { monkey: false },
293+
},
294+
],
247295
tapeMode: [
248296
{
249297
value: "off",

frontend/__tests__/root/config.spec.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,50 @@ describe("Config", () => {
109109
expect(Config.setConfig("showAllLines", true)).toBe(false);
110110
});
111111

112+
it("disables live text stats when enabling monkey", () => {
113+
//GIVEN
114+
replaceConfig({
115+
liveSpeedStyle: "text",
116+
liveAccStyle: "text",
117+
monkey: false,
118+
});
119+
120+
//WHEN / THEN
121+
expect(Config.setConfig("monkey", true)).toBe(true);
122+
expect(getConfig()).toMatchObject({
123+
monkey: true,
124+
liveSpeedStyle: "mini",
125+
liveAccStyle: "mini",
126+
});
127+
expect(notificationAddMock).not.toHaveBeenCalled();
128+
});
129+
130+
it("disables monkey when enabling live speed text", () => {
131+
//GIVEN
132+
replaceConfig({ monkey: true, liveSpeedStyle: "off" });
133+
134+
//WHEN / THEN
135+
expect(Config.setConfig("liveSpeedStyle", "text")).toBe(true);
136+
expect(getConfig()).toMatchObject({
137+
monkey: false,
138+
liveSpeedStyle: "text",
139+
});
140+
expect(notificationAddMock).not.toHaveBeenCalled();
141+
});
142+
143+
it("disables monkey when enabling live accuracy text", () => {
144+
//GIVEN
145+
replaceConfig({ monkey: true, liveAccStyle: "off" });
146+
147+
//WHEN / THEN
148+
expect(Config.setConfig("liveAccStyle", "text")).toBe(true);
149+
expect(getConfig()).toMatchObject({
150+
monkey: false,
151+
liveAccStyle: "text",
152+
});
153+
expect(notificationAddMock).not.toHaveBeenCalled();
154+
});
155+
112156
it("should use overrideValue", () => {
113157
//WHEN
114158
Config.setConfig("customLayoutfluid", ["3l", "ABNT2", "3l"]);

frontend/src/ts/config/metadata.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,13 +620,29 @@ export const configMetadata: ConfigMetadataObject = {
620620
displayString: "live speed style",
621621
changeRequiresRestart: false,
622622
group: "appearance",
623+
overrideConfig: ({ value }) => {
624+
if (value === "text") {
625+
return {
626+
monkey: false,
627+
};
628+
}
629+
return {};
630+
},
623631
},
624632
liveAccStyle: {
625633
key: "liveAccStyle",
626634
fa: { icon: "fa-tachometer-alt" },
627635
displayString: "live accuracy style",
628636
changeRequiresRestart: false,
629637
group: "appearance",
638+
overrideConfig: ({ value }) => {
639+
if (value === "text") {
640+
return {
641+
monkey: false,
642+
};
643+
}
644+
return {};
645+
},
630646
},
631647
liveBurstStyle: {
632648
key: "liveBurstStyle",
@@ -1005,6 +1021,21 @@ export const configMetadata: ConfigMetadataObject = {
10051021
displayString: "monkey",
10061022
changeRequiresRestart: false,
10071023
group: "hidden",
1024+
overrideConfig: ({ value, currentConfig }) => {
1025+
if (value) {
1026+
return {
1027+
liveSpeedStyle:
1028+
currentConfig.liveSpeedStyle === "text"
1029+
? "mini"
1030+
: currentConfig.liveSpeedStyle,
1031+
liveAccStyle:
1032+
currentConfig.liveAccStyle === "text"
1033+
? "mini"
1034+
: currentConfig.liveAccStyle,
1035+
};
1036+
}
1037+
return {};
1038+
},
10081039
},
10091040
monkeyPowerLevel: {
10101041
key: "monkeyPowerLevel",

0 commit comments

Comments
 (0)