Skip to content

Commit

Permalink
chore: onerandom mode done
Browse files Browse the repository at this point in the history
  • Loading branch information
ThEditor committed Jul 28, 2024
1 parent 8f3d66a commit 9e32725
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 16 deletions.
2 changes: 1 addition & 1 deletion frontend/src/ts/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export function setMode(mode: ConfigTypes.Mode, nosave?: boolean): boolean {
setNumbers(false);
} else if (config.mode === "onerandom") {
setPunctuation(true);
setNumbers(true);
setNumbers(false);
}
saveToLocalStorage("mode", nosave);
ConfigEvent.dispatch("mode", config.mode, nosave, previous);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/test/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ function updateTestType(randomQuote: MonkeyTypes.Quote | null): void {

testType += Config.mode;

if (Config.mode === "time") {
if (Config.mode === "time" || Config.mode === "onerandom") {
testType += " " + Config.time;
} else if (Config.mode === "words" || Config.mode === "easy") {
testType += " " + Config.words;
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/ts/test/test-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ export async function instantUpdate(): Promise<void> {
$("#testConfig .time").removeClass("hidden");

updateExtras("time", Config.time);
} else if (Config.mode === "words" || Config.mode === "easy") {
} else if (Config.mode === "words") {
$("#testConfig .puncAndNum").removeClass("hidden");
$("#testConfig .leftSpacer").removeClass("scrolled");
$("#testConfig .rightSpacer").removeClass("scrolled");
$("#testConfig .wordCount").removeClass("hidden");

updateExtras("words", Config.words);
} else if (Config.mode === "quote" || Config.mode === "medium") {
} else if (Config.mode === "quote") {
$("#testConfig .rightSpacer").removeClass("scrolled");
$("#testConfig .quoteLength").removeClass("hidden");

Expand Down Expand Up @@ -267,7 +267,7 @@ ConfigEvent.subscribe((eventKey, eventValue, _nosave, eventPreviousValue) => {

let m2;

if (Config.mode === "time") {
if (Config.mode === "time" || Config.mode === "onerandom") {
m2 = Config.time;
} else if (Config.mode === "words" || Config.mode === "easy") {
m2 = Config.words;
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/ts/test/test-logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -950,8 +950,10 @@ export async function finish(difficultyFailed = false): Promise<void> {
Notifications.add("Test invalid - repeated", 0);
dontSave = true;
} else if (
(Config.mode === "time" && mode2Number < 15 && mode2Number > 0) ||
(Config.mode === "time" &&
((Config.mode === "time" || Config.mode === "onerandom") &&
mode2Number < 15 &&
mode2Number > 0) ||
((Config.mode === "time" || Config.mode === "onerandom") &&
mode2Number === 0 &&
completedEvent.testDuration < 15) ||
((Config.mode === "words" || Config.mode === "easy") &&
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/test/test-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export function setStart(s: number): void {
export function calculateAfkSeconds(testSeconds: number): number {
let extraAfk = 0;
if (testSeconds !== undefined) {
if (Config.mode === "time") {
if (Config.mode === "time" || Config.mode === "onerandom") {
extraAfk =
Math.round(testSeconds) - TestInput.keypressCountHistory.length;
} else {
Expand Down
10 changes: 7 additions & 3 deletions frontend/src/ts/test/test-timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function updateTimer(): void {
if (timerDebug) console.time("timer progress update");
if (
Config.mode === "time" ||
Config.mode === "onerandom" ||
(Config.mode === "custom" && CustomText.getLimitMode() === "time")
) {
TimerProgress.update();
Expand Down Expand Up @@ -86,7 +87,7 @@ function layoutfluid(): void {
if (timerDebug) console.time("layoutfluid");
if (
Config.funbox.split("#").includes("layoutfluid") &&
Config.mode === "time"
(Config.mode === "time" || Config.mode === "onerandom")
) {
const layouts = Config.customLayoutfluid
? Config.customLayoutfluid.split("#")
Expand Down Expand Up @@ -149,12 +150,13 @@ function checkIfTimeIsUp(): void {
if (timerDebug) console.time("times up check");
if (
Config.mode === "time" ||
Config.mode === "onerandom" ||
(Config.mode === "custom" && CustomText.getLimitMode() === "time")
) {
if (
(Time.get() >= Config.time &&
Config.time !== 0 &&
Config.mode === "time") ||
(Config.mode === "time" || Config.mode === "onerandom")) ||
(Time.get() >= CustomText.getLimitValue() &&
CustomText.getLimitValue() !== 0 &&
Config.mode === "custom")
Expand Down Expand Up @@ -209,7 +211,9 @@ export async function start(): Promise<void> {
nextDelay: delay,
});
if (
(Config.mode === "time" && Config.time < 130 && Config.time > 0) ||
((Config.mode === "time" || Config.mode === "onerandom") &&
Config.time < 130 &&
Config.time > 0) ||
((Config.mode === "words" || Config.mode === "easy") &&
Config.words < 250 &&
Config.words > 0)
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/ts/test/timer-progress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function reset(): void {
let width = "0vw";
if (
Config.mode === "time" ||
Config.mode === "onerandom" ||
(Config.mode === "custom" && CustomText.getLimitMode() === "time")
) {
width = "100vw";
Expand Down Expand Up @@ -103,6 +104,7 @@ export function update(): void {
const time = Time.get();
if (
Config.mode === "time" ||
Config.mode === "onerandom" ||
(Config.mode === "custom" && CustomText.getLimitMode() === "time")
) {
let maxtime = Config.time;
Expand Down
15 changes: 15 additions & 0 deletions frontend/src/ts/test/words-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,20 @@ export async function generateWords(
wordList = await getQuoteWordList(language, wordOrder);
} else if (Config.mode === "zen") {
wordList = [];
} else if (Config.mode === "onerandom") {
// generate list of words from special characters
const special_characters = "``!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/";
wordList = [];
for (let i = 0; i < 1000; i++) {
let word = "";
for (let i = 0; i < 10; i++) {
word +=
special_characters[
Math.floor(Math.random() * special_characters.length)
] ?? "@";
}
wordList.push(word);
}
}

const limit = getWordsLimit();
Expand Down Expand Up @@ -755,6 +769,7 @@ export async function getNextWord(

if (
Config.mode === "time" ||
Config.mode === "onerandom" ||
(Config.mode === "custom" && CustomText.getLimitMode() === "time") ||
(Config.mode === "custom" &&
CustomText.getLimitMode() === "word" &&
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/ts/utils/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ export function canQuickRestart(
customTextIsLong: boolean
): boolean {
const wordsLong = mode === "words" && (words >= 1000 || words === 0);
const timeLong = mode === "time" && (time >= 900 || time === 0);
const timeLong =
(mode === "time" || mode === "onerandom") && (time >= 900 || time === 0);
const customTextLong = mode === "custom" && customTextIsLong;

const customTextRandomWordsLong =
Expand Down Expand Up @@ -385,7 +386,7 @@ export function getMode2<M extends keyof PersonalBests>(
const mode = config.mode;
let retVal: string;

if (mode === "time") {
if (mode === "time" || mode === "onerandom") {
retVal = config.time.toString();
} else if (mode === "words") {
retVal = config.words.toString();
Expand All @@ -397,8 +398,6 @@ export function getMode2<M extends keyof PersonalBests>(
retVal = `${randomQuote?.id ?? -1}`;
} else if (mode === "easy") {
retVal = config.words.toString();
} else if (mode === "onerandom") {
retVal = config.words.toString();
} else {
throw new Error("Invalid mode");
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/ts/utils/url-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export function loadTestSettingsFromUrl(getOverride?: string): void {
}

if (de[1] !== null) {
if (Config.mode === "time") {
if (Config.mode === "time" || Config.mode === "onerandom") {
UpdateConfig.setTimeConfig(parseInt(de[1], 10), true);
} else if (Config.mode === "words" || Config.mode === "easy") {
UpdateConfig.setWordCount(parseInt(de[1], 10), true);
Expand Down

0 comments on commit 9e32725

Please sign in to comment.