mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 23:12:24 -05:00
Resolves #2087 and #2088. Because we weren't clearing a motor's _pendingPromiseFunction after executing it, it kept lingering, which made setMotorPower() and setMotorDirection() trigger a rotation-based command even if was responding to a timed or forever motorcommand. By clearing the property every time we fire the function, and by using pendingPromiseFunction as the conditional in setMotorPower() and setMotorDirection(), this should be taken care of.
This commit is contained in:
parent
7b917cabb4
commit
3e55841011
1 changed files with 4 additions and 2 deletions
|
@ -953,6 +953,7 @@ class Boost {
|
||||||
const commandCompleted = feedback & (BoostPortFeedback.COMPLETED ^ BoostPortFeedback.DISCARDED);
|
const commandCompleted = feedback & (BoostPortFeedback.COMPLETED ^ BoostPortFeedback.DISCARDED);
|
||||||
if (!isBusy && commandCompleted && motor.pendingPromiseFunction) {
|
if (!isBusy && commandCompleted && motor.pendingPromiseFunction) {
|
||||||
motor.pendingPromiseFunction();
|
motor.pendingPromiseFunction();
|
||||||
|
motor.pendingPromiseFunction = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1650,6 +1651,7 @@ class Scratch3BoostBlocks {
|
||||||
if (motor.pendingPromiseFunction) {
|
if (motor.pendingPromiseFunction) {
|
||||||
// If there's already a promise for this motor it must be resolved to avoid hanging blocks.
|
// If there's already a promise for this motor it must be resolved to avoid hanging blocks.
|
||||||
motor.pendingPromiseFunction();
|
motor.pendingPromiseFunction();
|
||||||
|
motor.pendingPromiseFunction = null;
|
||||||
}
|
}
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
motor.turnOnForDegrees(degrees, sign);
|
motor.turnOnForDegrees(degrees, sign);
|
||||||
|
@ -1724,7 +1726,7 @@ class Scratch3BoostBlocks {
|
||||||
if (motor.isOn) {
|
if (motor.isOn) {
|
||||||
if (motor.pendingTimeoutDelay) {
|
if (motor.pendingTimeoutDelay) {
|
||||||
motor.turnOnFor(motor.pendingTimeoutStartTime + motor.pendingTimeoutDelay - Date.now());
|
motor.turnOnFor(motor.pendingTimeoutStartTime + motor.pendingTimeoutDelay - Date.now());
|
||||||
} else if (motor.pendingPositionDestination) {
|
} else if (motor.pendingPromiseFunction) {
|
||||||
const p = Math.abs(motor.pendingPositionDestination - motor.position);
|
const p = Math.abs(motor.pendingPositionDestination - motor.position);
|
||||||
motor.turnOnForDegrees(p, Math.sign(p));
|
motor.turnOnForDegrees(p, Math.sign(p));
|
||||||
} else {
|
} else {
|
||||||
|
@ -1765,7 +1767,7 @@ class Scratch3BoostBlocks {
|
||||||
if (motor.isOn) {
|
if (motor.isOn) {
|
||||||
if (motor.pendingTimeoutDelay) {
|
if (motor.pendingTimeoutDelay) {
|
||||||
motor.turnOnFor(motor.pendingTimeoutStartTime + motor.pendingTimeoutDelay - Date.now());
|
motor.turnOnFor(motor.pendingTimeoutStartTime + motor.pendingTimeoutDelay - Date.now());
|
||||||
} else if (motor.pendingPositionDestination) {
|
} else if (motor.pendingPromiseFunction) {
|
||||||
const p = Math.abs(motor.pendingPositionDestination - motor.position);
|
const p = Math.abs(motor.pendingPositionDestination - motor.position);
|
||||||
motor.turnOnForDegrees(p, Math.sign(p));
|
motor.turnOnForDegrees(p, Math.sign(p));
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue