Skip to content

Commit

Permalink
Lily/MoreTimers: Don't rely on system clock (#1898)
Browse files Browse the repository at this point in the history
This prevents the More Timers extension from being thrown off by system
clock changes.

Tested, no breaking changes.

---------

Co-authored-by: DangoCat[bot] <[email protected]>
  • Loading branch information
DNin01 and DangoCat authored Feb 1, 2025
1 parent e2016e9 commit 725eac3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions extensions/Lily/MoreTimers.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
*/
const timerValue = (timer) => {
return (
((timer.paused ? 0 : Date.now() - timer.startTime) + timer.pauseTime) /
((timer.paused ? 0 : Math.floor(performance.now()) - timer.startTime) +
timer.pauseTime) /
1000
);
};
Expand Down Expand Up @@ -215,7 +216,7 @@

startResetTimer(args) {
timers[args.TIMER] = {
startTime: Date.now(),
startTime: Math.floor(performance.now()),
pauseTime: 0,
paused: false,
};
Expand All @@ -233,7 +234,7 @@
if (!timer) return;
if (timer.paused === false) return;
timer.paused = false;
timer.startTime = Date.now();
timer.startTime = Math.floor(performance.now());
}

valueOfTimer(args) {
Expand All @@ -244,7 +245,7 @@
setTimer(args) {
timers[args.TIMER] = {
paused: false,
startTime: Date.now(),
startTime: Math.floor(performance.now()),
pauseTime: Scratch.Cast.toNumber(args.NUM) * 1000,
};
}
Expand Down

0 comments on commit 725eac3

Please sign in to comment.