Skip to content

Commit d184087

Browse files
gianpenaMiodec
andauthored
impr(timer/progress style): add flashing timer style (@gianpena) (monkeytypegame#7139)
### Description This copies the existing `text` timerstyle except on timed modes, where it will only show the remaining progress (seconds) on every 15th second (shows on 1:00, 45, 30, 15 and 0). The motivation for this addition was that I wanted a middle ground between the `text` timerstyle (in my opinion just a _little_ too distracting) and no live progress indicator at all (I lose track of how much time remains in the test), and I believe this achieves that middle ground. --------- Co-authored-by: Miodec <[email protected]>
1 parent f910c8a commit d184087

File tree

4 files changed

+74
-2
lines changed

4 files changed

+74
-2
lines changed

frontend/src/html/pages/settings.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,13 +856,16 @@
856856
</button>
857857
</div>
858858
<div class="text">
859-
Change the style of the timer/word count during a test.
859+
Change the style of the timer/word count during a test. "Flash" styles
860+
will briefly show the timer in timed modes every 15 seconds.
860861
</div>
861862
<div class="buttons">
862863
<button data-config-value="off">off</button>
863864
<button data-config-value="bar">bar</button>
864865
<button data-config-value="text">text</button>
865866
<button data-config-value="mini">mini</button>
867+
<button data-config-value="flash text">flash text</button>
868+
<button data-config-value="flash mini">flash mini</button>
866869
</div>
867870
</div>
868871
<div class="section" data-config-name="liveSpeedStyle">

frontend/src/styles/settings.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,12 @@
339339
}
340340
}
341341

342+
&[data-config-name="timerStyle"] {
343+
.buttons {
344+
grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
345+
}
346+
}
347+
342348
&.tags {
343349
.tagsListAndButton {
344350
grid-area: buttons;

frontend/src/ts/test/timer-progress.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,22 @@ export function show(): void {
3636
textEl.classList.remove("hidden");
3737
},
3838
});
39+
} else if (Config.timerStyle === "flash mini") {
40+
animate(miniEl, {
41+
opacity: [0, 1],
42+
duration: applyReducedMotion(125),
43+
onBegin: () => {
44+
miniEl.classList.remove("hidden");
45+
},
46+
});
47+
} else if (Config.timerStyle === "flash text") {
48+
animate(textEl, {
49+
opacity: [0, 1],
50+
duration: applyReducedMotion(125),
51+
onBegin: () => {
52+
textEl.classList.remove("hidden");
53+
},
54+
});
3955
} else if (Config.mode === "zen" || Config.timerStyle === "mini") {
4056
animate(miniEl, {
4157
opacity: [0, 1],
@@ -124,6 +140,30 @@ export function update(): void {
124140
if (textEl !== null) {
125141
textEl.innerHTML = "<div>" + displayTime + "</div>";
126142
}
143+
} else if (Config.timerStyle === "flash mini") {
144+
let displayTime = DateTime.secondsToString(maxtime - time);
145+
if (maxtime === 0) {
146+
displayTime = DateTime.secondsToString(time);
147+
}
148+
if (miniEl !== null) {
149+
if ((maxtime - time) % 15 !== 0) {
150+
miniEl.style.opacity = "0";
151+
} else {
152+
miniEl.style.opacity = "1";
153+
}
154+
miniEl.innerHTML = "<div>" + displayTime + "</div>";
155+
}
156+
} else if (Config.timerStyle === "flash text") {
157+
let displayTime = DateTime.secondsToString(maxtime - time);
158+
if (maxtime === 0) {
159+
displayTime = DateTime.secondsToString(time);
160+
}
161+
if (textEl !== null) {
162+
textEl.innerHTML =
163+
"<div>" +
164+
`${(maxtime - time) % 15 !== 0 ? "" : displayTime}` +
165+
"</div>";
166+
}
127167
} else if (Config.timerStyle === "mini") {
128168
let displayTime = DateTime.secondsToString(maxtime - time);
129169
if (maxtime === 0) {
@@ -163,6 +203,18 @@ export function update(): void {
163203
} else {
164204
textEl.innerHTML = `<div>${getCurrentCount()}/${outof}</div>`;
165205
}
206+
} else if (Config.timerStyle === "flash mini") {
207+
if (outof === 0) {
208+
miniEl.innerHTML = `${TestInput.input.getHistory().length}`;
209+
} else {
210+
miniEl.innerHTML = `${getCurrentCount()}/${outof}`;
211+
}
212+
} else if (Config.timerStyle === "flash text") {
213+
if (outof === 0) {
214+
textEl.innerHTML = `<div>${TestInput.input.getHistory().length}</div>`;
215+
} else {
216+
textEl.innerHTML = `<div>${getCurrentCount()}/${outof}</div>`;
217+
}
166218
} else if (Config.timerStyle === "mini") {
167219
if (outof === 0) {
168220
miniEl.innerHTML = `${TestInput.input.getHistory().length}`;
@@ -173,6 +225,10 @@ export function update(): void {
173225
} else if (Config.mode === "zen") {
174226
if (Config.timerStyle === "text") {
175227
textEl.innerHTML = `<div>${TestInput.input.getHistory().length}</div>`;
228+
} else if (Config.timerStyle === "flash mini") {
229+
miniEl.innerHTML = `${TestInput.input.getHistory().length}`;
230+
} else if (Config.timerStyle === "flash text") {
231+
textEl.innerHTML = `<div>${TestInput.input.getHistory().length}</div>`;
176232
} else {
177233
miniEl.innerHTML = `${TestInput.input.getHistory().length}`;
178234
}

packages/schemas/src/configs.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ export type ConfidenceMode = z.infer<typeof ConfidenceModeSchema>;
5454
export const IndicateTyposSchema = z.enum(["off", "below", "replace", "both"]);
5555
export type IndicateTypos = z.infer<typeof IndicateTyposSchema>;
5656

57-
export const TimerStyleSchema = z.enum(["off", "bar", "text", "mini"]);
57+
export const TimerStyleSchema = z.enum([
58+
"off",
59+
"bar",
60+
"text",
61+
"mini",
62+
"flash text",
63+
"flash mini",
64+
]);
5865
export type TimerStyle = z.infer<typeof TimerStyleSchema>;
5966

6067
export const LiveSpeedAccBurstStyleSchema = z.enum(["off", "text", "mini"]);

0 commit comments

Comments
 (0)