Skip to content

Commit e515506

Browse files
authored
refactor: clean up test-ui and test-logic (@Miodec) (monkeytypegame#7229)
Move ui code to test ui, remove unused code, remove duplicated code, merge the two config event listeners, merge a lot of the ui code to make it easier to grasp.
1 parent 9654ac5 commit e515506

File tree

8 files changed

+251
-243
lines changed

8 files changed

+251
-243
lines changed

frontend/src/ts/test/funbox/layoutfluid-funbox-timer.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ export function hide(): void {
2020
});
2121
}
2222

23+
export function instantHide(): void {
24+
timerEl.style.opacity = "0";
25+
}
26+
2327
export function updateTime(sec: number, layout: string): void {
2428
timerEl.textContent = `${capitalizeFirstLetter(layout)} in: ${sec}s`;
2529
}

frontend/src/ts/test/live-acc.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import { requestDebouncedAnimationFrame } from "../utils/debounced-animation-fra
77

88
const textEl = document.querySelector(
99
"#liveStatsTextBottom .liveAcc",
10-
) as Element;
11-
const miniEl = document.querySelector("#liveStatsMini .acc") as Element;
10+
) as HTMLElement;
11+
const miniEl = document.querySelector("#liveStatsMini .acc") as HTMLElement;
1212

1313
export function update(acc: number): void {
1414
requestDebouncedAnimationFrame("live-acc.update", () => {
@@ -73,6 +73,17 @@ export function hide(): void {
7373
});
7474
}
7575

76+
export function instantHide(): void {
77+
if (!state) return;
78+
79+
textEl.classList.add("hidden");
80+
textEl.style.opacity = "0";
81+
miniEl.classList.add("hidden");
82+
miniEl.style.opacity = "0";
83+
84+
state = false;
85+
}
86+
7687
ConfigEvent.subscribe(({ key, newValue }) => {
7788
if (key === "liveAccStyle") newValue === "off" ? hide() : show();
7889
});

frontend/src/ts/test/live-burst.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { requestDebouncedAnimationFrame } from "../utils/debounced-animation-fra
88

99
const textEl = document.querySelector(
1010
"#liveStatsTextBottom .liveBurst",
11-
) as Element;
12-
const miniEl = document.querySelector("#liveStatsMini .burst") as Element;
11+
) as HTMLElement;
12+
const miniEl = document.querySelector("#liveStatsMini .burst") as HTMLElement;
1313

1414
export function reset(): void {
1515
requestDebouncedAnimationFrame("live-burst.reset", () => {
@@ -71,6 +71,17 @@ export function hide(): void {
7171
});
7272
}
7373

74+
export function instantHide(): void {
75+
if (!state) return;
76+
77+
textEl.classList.add("hidden");
78+
textEl.style.opacity = "0";
79+
miniEl.classList.add("hidden");
80+
miniEl.style.opacity = "0";
81+
82+
state = false;
83+
}
84+
7485
ConfigEvent.subscribe(({ key, newValue }) => {
7586
if (key === "liveBurstStyle") newValue === "off" ? hide() : show();
7687
});

frontend/src/ts/test/live-speed.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ import { animate } from "animejs";
88

99
const textElement = document.querySelector(
1010
"#liveStatsTextBottom .liveSpeed",
11-
) as Element;
12-
const miniElement = document.querySelector("#liveStatsMini .speed") as Element;
11+
) as HTMLElement;
12+
const miniElement = document.querySelector(
13+
"#liveStatsMini .speed",
14+
) as HTMLElement;
1315

1416
export function reset(): void {
1517
requestDebouncedAnimationFrame("live-speed.reset", () => {
@@ -75,6 +77,15 @@ export function hide(): void {
7577
});
7678
}
7779

80+
export function instantHide(): void {
81+
if (!state) return;
82+
miniElement.classList.add("hidden");
83+
miniElement.style.opacity = "0";
84+
textElement.classList.add("hidden");
85+
textElement.style.opacity = "0";
86+
state = false;
87+
}
88+
7889
ConfigEvent.subscribe(({ key, newValue }) => {
7990
if (key === "liveSpeedStyle") newValue === "off" ? hide() : show();
8091
});

frontend/src/ts/test/monkey.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,10 @@ export function hide(): void {
162162
},
163163
});
164164
}
165+
166+
export function instantHide(): void {
167+
monkeyEl.classList.add("hidden");
168+
monkeyEl.style.opacity = "0";
169+
monkeyEl.style.animationDuration = "0s";
170+
monkeyFastEl.style.opacity = "0";
171+
}

0 commit comments

Comments
 (0)