mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-25 15:32:40 -05:00
Merge pull request #2101 from knandersen/bugfix/2086
Fix #2086 by resolving pending promise even when power set to 0%
This commit is contained in:
commit
eb66855539
1 changed files with 11 additions and 5 deletions
|
@ -372,9 +372,11 @@ class BoostMotor {
|
||||||
* Scale the motor power to a range between 10 and 100,
|
* Scale the motor power to a range between 10 and 100,
|
||||||
* to make sure the motors will run with something built onto them.
|
* to make sure the motors will run with something built onto them.
|
||||||
*/
|
*/
|
||||||
const p = MathUtil.scale(value, 0, 100, 10, 100);
|
if (value === 0) {
|
||||||
|
this._power = 0;
|
||||||
this._power = p;
|
} else {
|
||||||
|
this._power = MathUtil.scale(value, 1, 100, 10, 100);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -475,7 +477,11 @@ class BoostMotor {
|
||||||
* @param {number} direction - rotate in this direction
|
* @param {number} direction - rotate in this direction
|
||||||
*/
|
*/
|
||||||
turnOnForDegrees (degrees, direction) {
|
turnOnForDegrees (degrees, direction) {
|
||||||
if (this.power === 0) return;
|
if (this.power === 0) {
|
||||||
|
this.pendingPromiseFunction();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
degrees = Math.max(0, degrees);
|
degrees = Math.max(0, degrees);
|
||||||
|
|
||||||
const cmd = this._parent.generateOutputCommand(
|
const cmd = this._parent.generateOutputCommand(
|
||||||
|
@ -1654,8 +1660,8 @@ class Scratch3BoostBlocks {
|
||||||
motor.pendingPromiseFunction = null;
|
motor.pendingPromiseFunction = null;
|
||||||
}
|
}
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
motor.turnOnForDegrees(degrees, sign);
|
|
||||||
motor.pendingPromiseFunction = resolve;
|
motor.pendingPromiseFunction = resolve;
|
||||||
|
motor.turnOnForDegrees(degrees, sign);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in a new issue