mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-11 10:39:56 -05:00
changes BoostMotor.status(value) to reset all motor state
This commit is contained in:
parent
3f0816bac8
commit
8ece9757aa
1 changed files with 7 additions and 24 deletions
|
@ -415,20 +415,9 @@ class BoostMotor {
|
||||||
* @param {BoostMotorState} value - set this motor's state.
|
* @param {BoostMotorState} value - set this motor's state.
|
||||||
*/
|
*/
|
||||||
set status (value) {
|
set status (value) {
|
||||||
switch (value) {
|
// Clear any time- or rotation-related state from motor and set new status.
|
||||||
case BoostMotorState.OFF:
|
this._clearRotationState();
|
||||||
case BoostMotorState.ON_FOREVER:
|
this._clearTimeout();
|
||||||
this._clearRotationState();
|
|
||||||
this._clearTimeout();
|
|
||||||
break;
|
|
||||||
case BoostMotorState.ON_FOR_TIME:
|
|
||||||
this._clearRotationState();
|
|
||||||
break;
|
|
||||||
case BoostMotorState.ON_FOR_ROTATION:
|
|
||||||
this._clearRotationState();
|
|
||||||
this._clearTimeout();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
this._status = value;
|
this._status = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -472,7 +461,7 @@ class BoostMotor {
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_turnOn () {
|
_turnOn () {
|
||||||
if (this._power === 0) return;
|
if (this.power === 0) return;
|
||||||
const cmd = this._parent.generateOutputCommand(
|
const cmd = this._parent.generateOutputCommand(
|
||||||
this._index,
|
this._index,
|
||||||
BoostOutputExecution.EXECUTE_IMMEDIATELY,
|
BoostOutputExecution.EXECUTE_IMMEDIATELY,
|
||||||
|
@ -1672,9 +1661,7 @@ class Scratch3BoostBlocks {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
this._forEachMotor(args.MOTOR_ID, motorIndex => {
|
this._forEachMotor(args.MOTOR_ID, motorIndex => {
|
||||||
const motor = this._peripheral.motor(motorIndex);
|
const motor = this._peripheral.motor(motorIndex);
|
||||||
if (motor) {
|
if (motor) motor.turnOnFor(durationMS);
|
||||||
motor.turnOnFor(durationMS);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Run for some time even when no motor is connected
|
// Run for some time even when no motor is connected
|
||||||
|
@ -1732,9 +1719,7 @@ class Scratch3BoostBlocks {
|
||||||
// TODO: cast args.MOTOR_ID?
|
// TODO: cast args.MOTOR_ID?
|
||||||
this._forEachMotor(args.MOTOR_ID, motorIndex => {
|
this._forEachMotor(args.MOTOR_ID, motorIndex => {
|
||||||
const motor = this._peripheral.motor(motorIndex);
|
const motor = this._peripheral.motor(motorIndex);
|
||||||
if (motor) {
|
if (motor) motor.turnOnForever();
|
||||||
motor.turnOnForever();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
|
@ -1754,9 +1739,7 @@ class Scratch3BoostBlocks {
|
||||||
// TODO: cast args.MOTOR_ID?
|
// TODO: cast args.MOTOR_ID?
|
||||||
this._forEachMotor(args.MOTOR_ID, motorIndex => {
|
this._forEachMotor(args.MOTOR_ID, motorIndex => {
|
||||||
const motor = this._peripheral.motor(motorIndex);
|
const motor = this._peripheral.motor(motorIndex);
|
||||||
if (motor) {
|
if (motor) motor.turnOff();
|
||||||
motor.turnOff();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
|
|
Loading…
Reference in a new issue