Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JeremyGamer13/tween: Fix Pause button not suspending Tweening #1887

Merged
merged 4 commits into from
Feb 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions extensions/JeremyGamer13/tween.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,6 @@
bounce,
};

const now = () => Scratch.vm.runtime.currentMSecs;

class Tween {
getInfo() {
return {
Expand Down Expand Up @@ -478,12 +476,11 @@

getVariables() {
const variables =
// @ts-expect-error
typeof Blockly === "undefined"
? []
: // @ts-expect-error
Blockly.getMainWorkspace()
: Blockly.getMainWorkspace()
.getVariableMap()
// @ts-expect-error
.getVariablesOfType("")
.map((model) => ({
text: model.name,
Expand Down Expand Up @@ -523,7 +520,12 @@
// First run, need to start timer
util.yield();

const durationMS = Cast.toNumber(args.SEC) * 1000;
// If multiple values being tweened in same block, only start timer stack timer once.
if (util.stackTimerNeedsInit()) {
const durationMS = Math.max(0, 1000 * Cast.toNumber(args.SEC));
util.startStackTimer(durationMS);
}

const easeMethod = Cast.toString(args.MODE);
const easeDirection = Cast.toString(args.DIRECTION);
const start = currentValue;
Expand All @@ -537,23 +539,22 @@
}

util.stackFrame[id] = {
startTimeMS: now(),
durationMS,
easingFunction,
easeDirection,
start,
end,
};

return start;
} else if (now() - state.startTimeMS >= state.durationMS) {
} else if (util.stackTimerFinished()) {
// Done
return util.stackFrame[id].end;
} else {
// Still running
util.yield();

const progress = (now() - state.startTimeMS) / state.durationMS;
const progress =
util.stackFrame.timer.timeElapsed() / util.stackFrame.duration;
const tweened = state.easingFunction(progress, state.easeDirection);
return interpolate(tweened, state.start, state.end);
}
Expand Down