diff --git a/frontend/src/js/controllers/input-controller.js b/frontend/src/js/controllers/input-controller.js index aaa914d81..86412aacd 100644 --- a/frontend/src/js/controllers/input-controller.js +++ b/frontend/src/js/controllers/input-controller.js @@ -18,7 +18,6 @@ import * as Settings from "../pages/settings"; import * as LayoutEmulator from "../test/layout-emulator"; import * as PaceCaret from "../test/pace-caret"; import * as TimerProgress from "../test/timer-progress"; -import * as TestTimer from "../test/test-timer"; import * as Focus from "../test/focus"; import * as ShiftTracker from "../test/shift-tracker"; import * as Replay from "../test/replay.js"; @@ -267,7 +266,7 @@ function handleSpace() { Config.mode === "quote" || Config.mode === "zen" ) { - TimerProgress.update(TestTimer.time); + TimerProgress.update(); } if ( Config.mode == "time" || diff --git a/frontend/src/js/states/time.js b/frontend/src/js/states/time.js new file mode 100644 index 000000000..fd7aafafb --- /dev/null +++ b/frontend/src/js/states/time.js @@ -0,0 +1,13 @@ +let time = 0; + +export function get() { + return time; +} + +export function set(active) { + time = active; +} + +export function increment() { + time++; +} diff --git a/frontend/src/js/test/test-logic.js b/frontend/src/js/test/test-logic.js index 7d7f69e2f..e66e948a4 100644 --- a/frontend/src/js/test/test-logic.js +++ b/frontend/src/js/test/test-logic.js @@ -272,7 +272,7 @@ export function startTest() { LiveWpm.show(); LiveAcc.show(); LiveBurst.show(); - TimerProgress.update(TestTimer.time); + TimerProgress.update(); TestTimer.clear(); if (Config.funbox === "memory") { diff --git a/frontend/src/js/test/test-timer.js b/frontend/src/js/test/test-timer.js index 9b4057147..45494ccb8 100644 --- a/frontend/src/js/test/test-timer.js +++ b/frontend/src/js/test/test-timer.js @@ -16,9 +16,9 @@ import * as TestLogic from "./test-logic"; import * as Caret from "./caret"; import * as SlowTimer from "../states/slow-timer"; import * as TestActive from "./../states/test-active"; +import * as Time from "./../states/time"; let slowTimerCount = 0; -export let time = 0; let timer = null; const interval = 1000; let expected = 0; @@ -29,13 +29,14 @@ export function enableTimerDebug() { } export function clear() { - time = 0; + Time.set(0); clearTimeout(timer); } function premid() { if (timerDebug) console.time("premid"); - document.querySelector("#premidSecondsLeft").innerHTML = Config.time - time; + document.querySelector("#premidSecondsLeft").innerHTML = + Config.time - Time.get(); if (timerDebug) console.timeEnd("premid"); } @@ -45,7 +46,7 @@ function updateTimer() { Config.mode === "time" || (Config.mode === "custom" && CustomText.isTimeRandom) ) { - TimerProgress.update(time); + TimerProgress.update(); } if (timerDebug) console.timeEnd("timer progress update"); } @@ -87,23 +88,23 @@ function layoutfluid() { // console.log(layouts); const numLayouts = layouts.length; let index = 0; - index = Math.floor(time / (Config.time / numLayouts)); + index = Math.floor(Time.get() / (Config.time / numLayouts)); if ( - time == Math.floor(Config.time / numLayouts) - 3 || - time == (Config.time / numLayouts) * 2 - 3 + Time.get() == Math.floor(Config.time / numLayouts) - 3 || + Time.get() == (Config.time / numLayouts) * 2 - 3 ) { Notifications.add("3", 0, 1); } if ( - time == Math.floor(Config.time / numLayouts) - 2 || - time == Math.floor(Config.time / numLayouts) * 2 - 2 + Time.get() == Math.floor(Config.time / numLayouts) - 2 || + Time.get() == Math.floor(Config.time / numLayouts) * 2 - 2 ) { Notifications.add("2", 0, 1); } if ( - time == Math.floor(Config.time / numLayouts) - 1 || - time == Math.floor(Config.time / numLayouts) * 2 - 1 + Time.get() == Math.floor(Config.time / numLayouts) - 1 || + Time.get() == Math.floor(Config.time / numLayouts) * 2 - 1 ) { Notifications.add("1", 0, 1); } @@ -152,8 +153,10 @@ function checkIfTimeIsUp() { (Config.mode === "custom" && CustomText.isTimeRandom) ) { if ( - (time >= Config.time && Config.time !== 0 && Config.mode === "time") || - (time >= CustomText.time && + (Time.get() >= Config.time && + Config.time !== 0 && + Config.mode === "time") || + (Time.get() >= CustomText.time && CustomText.time !== 0 && Config.mode === "custom") ) { @@ -181,7 +184,7 @@ export function getTimerStats() { async function timerStep() { if (timerDebug) console.time("timer step -----------------------------"); - time++; + Time.increment(); premid(); updateTimer(); let wpmAndRaw = calculateWpmRaw(); diff --git a/frontend/src/js/test/timer-progress.js b/frontend/src/js/test/timer-progress.js index 19587d394..fa7259c1b 100644 --- a/frontend/src/js/test/timer-progress.js +++ b/frontend/src/js/test/timer-progress.js @@ -3,7 +3,7 @@ import * as CustomText from "./custom-text"; import * as Misc from "../misc"; import * as TestWords from "./test-words"; import * as TestInput from "./test-input"; -import * as TestTimer from "./test-timer"; +import * as Time from "./../states/time"; import * as SlowTimer from "../states/slow-timer"; import * as TestActive from "./../states/test-active"; @@ -94,7 +94,7 @@ let miniTimerNumberElement = document.querySelector( ); export function update() { - let time = TestTimer.time; + let time = Time.get(); if ( Config.mode === "time" || (Config.mode === "custom" && CustomText.isTimeRandom)