mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-07-27 22:50:22 -04:00
Don't set motor power if it's already equal to the input power.
This commit is contained in:
parent
71c3b72892
commit
c1292f6a59
1 changed files with 17 additions and 13 deletions
|
@ -1788,19 +1788,23 @@ class Scratch3BoostBlocks {
|
||||||
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.power = MathUtil.clamp(Cast.toNumber(args.POWER), 0, 100);
|
const power = MathUtil.clamp(Cast.toNumber(args.POWER), 0, 100);
|
||||||
switch (motor.status) {
|
// if motor power is already equal to the scaled input power, don't do anything
|
||||||
case BoostMotorState.ON_FOREVER:
|
if (motor.power !== MathUtil.scale(power, 1, 100, 10, 100)) {
|
||||||
motor.turnOnForever(false);
|
motor.power = power;
|
||||||
break;
|
switch (motor.status) {
|
||||||
case BoostMotorState.ON_FOR_TIME:
|
case BoostMotorState.ON_FOREVER:
|
||||||
motor.turnOnFor(motor.pendingTimeoutStartTime + motor.pendingTimeoutDelay - Date.now(), false);
|
motor.turnOnForever(false);
|
||||||
break;
|
break;
|
||||||
case BoostMotorState.ON_FOR_ROTATION: {
|
case BoostMotorState.ON_FOR_TIME:
|
||||||
const p = Math.abs(motor.pendingPositionDestination - motor.position);
|
motor.turnOnFor(motor.pendingTimeoutStartTime + motor.pendingTimeoutDelay - Date.now(), false);
|
||||||
motor.turnOnForDegrees(p, Math.sign(p), false);
|
break;
|
||||||
break;
|
case BoostMotorState.ON_FOR_ROTATION: {
|
||||||
}
|
const p = Math.abs(motor.pendingPositionDestination - motor.position);
|
||||||
|
motor.turnOnForDegrees(p, Math.sign(p), false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue