Commit graph

3269 commits

Author SHA1 Message Date
Katie Broida
eedc0b16e0
Merge pull request #2041 from ktbee/use-empty-bitmap-size
Set height and width to zero for the canvas and costume size if bitmap's sourceHeight or sourceWidth are zero
2019-04-16 14:50:42 -04:00
Kevin Nørby Andersen
1c8dfea382
Merge pull request #2115 from knandersen/bugfix/2108
Fix #2108 by making setMotorPower() and setMotorDirection() yield for a tick
2019-04-15 18:41:28 -04:00
Kevin Nørby Andersen
8504d077c5
Merge pull request #2111 from knandersen/bugfix/2103
Fix #2103 and #2110 by clearly defining motor state and how it's modified
2019-04-15 18:41:03 -04:00
Kevin Andersen
6611abec9e Makes setMotorPower() and setMotorDirection() yield for a tick 2019-04-12 14:12:43 -04:00
Kevin Andersen
12e969119a Simplified the return value for when power is 0 in motorOnForRotation() 2019-04-12 14:07:26 -04:00
Kevin Andersen
a98f3af2e1 Added a special case in motorOnForRotation() to avoid hanging blocks if power is 0 2019-04-12 13:56:29 -04:00
Kevin Andersen
8ece9757aa changes BoostMotor.status(value) to reset all motor state 2019-04-12 12:27:54 -04:00
Kevin Andersen
3f0816bac8 This commit addresses point 1 from the discussion with @ericrosenbaum around moving the setting of motor-state into the BoostMotor-class rather than having it in the opcodes.
- turnOn() renamed to _turnOn() and marked as a private function, i.e. it should only be called by BoostMotor-functions, not opcodes.
- New function turnOnForever() to be called by opcodes.
- turnOff() now sets the motor state.
- _clearRotationState now does a check for null rather than a truthy value
- all motor state setting removed from Boost-class and opcodes: stopAllMotors(), motorOnFor(), motorOnForRotation(), motorOn(), motorOff()
- turnOnForever(), turnOnFor() and turnOnForDegrees() now have a resetState-parameter with the default value of true. This allows the setMotorPower() and setMotorDirection()-functions to not reset state, to avoid them resolving the promises of the original motor commands that they are affecting.
2019-04-12 11:33:10 -04:00
Kevin Andersen
cd7319d044 Added state-change for Boost.stopAllMotors() 2019-04-11 14:07:07 -04:00
Kevin Andersen
c3908b5f2c removed power wrongly being set in setMotorDirection() 2019-04-11 11:16:51 -04:00
Kevin Andersen
ba2aaf90dd Corrected documentation for BoostMotor._clearRotationState() 2019-04-11 11:12:52 -04:00
Kevin Andersen
63726044e4 Major change of motor state handling to increase reliability, clear responsibility of handling state, and readability of the code.
BoostMotor now has a status getter/setter that replaces isOn() and is responsible for clearing various motor state parameters.

A new BoostMotorState-enum contains the possible states a motor can be in.

Since time-based motor commands really just trigger a BoostMotor.turnOn(), it's the opcodes that are responsible for setting the motor state.
2019-04-11 10:39:56 -04:00
Eric Rosenbaum
66ff92433e
Merge pull request #2107 from ericrosenbaum/bugfix/boost-when-color
Fix BOOST whenColor hat
2019-04-10 10:30:20 -04:00
picklesrus
d182659a57
Merge pull request #2065 from picklesrus/duplicate-sprites
Fix #4573 by using an existing utitlity that re-ids blocks when we du…
2019-04-10 09:05:53 -04:00
Karishma Chadha
51ad4185d1 Update src/sprites/sprite.js
Don't use object.values because it doesn't work in old Safaris.

Co-Authored-By: picklesrus <picklesrus@users.noreply.github.com>
2019-04-10 08:55:54 -04:00
Eric Rosenbaum
c0ea5be1d3 Fix whenColor hat 2019-04-09 17:36:14 -04:00
Kevin Nørby Andersen
3d74bbd823
Merge pull request #2106 from knandersen/bugfix/2105
Fix #2105 by correctly accessing motor position from BoostMotor-class
2019-04-09 16:46:58 -04:00
Kevin Andersen
b8bbe80c4f get position from this._peripheral.motor() 2019-04-09 16:20:21 -04:00
Kevin Nørby Andersen
eb66855539
Merge pull request #2101 from knandersen/bugfix/2086
Fix #2086 by resolving pending promise even when power set to 0%
2019-04-09 15:43:09 -04:00
Kevin Andersen
b2c18e9dcd BoostMotor.power(value) now sets to 0 if value is 0 rather than scaling, to ensure that blocks skip immediately if speed set to 0 2019-04-09 15:34:08 -04:00
Kevin Andersen
75fc37aa30 Fixed conflicts 2019-04-09 14:57:27 -04:00
Kevin Andersen
41873bf7bf Use the power-getter rather than accessing the property directly 2019-04-09 14:52:41 -04:00
Kevin Nørby Andersen
6e976f854e
Merge pull request #2100 from knandersen/bugfix/2089,2088,2087
Fix 2087, 2088, and 2089 by properly setting parameters in rotation-commands and not using command feedback when relying on scratch-vm for motor timing
2019-04-09 14:25:44 -04:00
Kevin Andersen
3e55841011 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. 2019-04-09 11:45:42 -04:00
Kevin Andersen
7b917cabb4 Added isBusy-flag in onMessage to make sure promises aren't resolved if the motor is still busy. Added check in motorOnForRotation() that ensure that any previous pendingPromiseFunction() is resolved before creating a new one, to avoid hanging blocks 2019-04-09 09:30:26 -04:00
Kevin Andersen
19e6a1d4c9 Merge branch 'develop' of https://github.com/LLK/scratch-vm into bugfix/2089,2088,2087 2019-04-09 08:51:28 -04:00
Kevin Andersen
c664fca9d7 changed getMotorPosition() to use the Boost.motor()-function instead of accessing the _motors-property directly 2019-04-09 08:47:00 -04:00
Kevin Nørby Andersen
03b4d0e582
Merge pull request #2099 from knandersen/bugfix/2085
Fix #2085 by handling discarded hub commands
2019-04-08 19:27:32 -04:00
Kevin Andersen
ecbbacd4c0 It seems like there's a tradeoff between how we choose to set the max power of the motors. Previously, I had set the motors' max power (torque) to follow their target speed, meaning they accelerated smoothly, but also lost their torque. Then in the following commit I changed the max power to 100 which means maximum torque to achieve the target speed, which resulted in very abrupt accelerations and erratic motor movement when changing speeds:
873b56c985

In the following commit I changed the functionality so that we add a fixed amount (10) more power than the target speed, e.g. for speed 50 it would provide power 60. This is fine for high speeds, but for low speeds it provides poor torque:

e3cdbffa2a

I assume it would be possible to design some sort of calculation that enabled high torque for low speeds, and vice versa. I will discuss with the team.
2019-04-08 17:56:54 -04:00
Kevin Andersen
e24ace83a0 noticed several instances of getting especially power and direction properties from private variables instead of using the getter 2019-04-08 17:48:30 -04:00
Kevin Andersen
e986b0f4cb - changed max power setting in motor functions to be calculated with MathUtil.clamp() instead of MathUtil.wrapClamp() to avoid values rolling over!
- added an else-case to both setMotorDirection() and setMotorPower() so that dynamic speed/direction changes also affect the motorOn()-blocks just like the time- and rotation-based ones.
2019-04-08 13:48:10 -04:00
Kevin Andersen
d9e0267fa0 Resolves #2086. This issue was caused by turnOnForDegrees() not resolving a promise. Additionally, this promise can only be resolved if its assigned before turnOnDegrees() was called, so in motorOnForRotation() it is now switched around. 2019-04-05 14:18:33 -04:00
Kevin Andersen
2ee8042b6a Resolves #2085
This was caused because the case for BoostMessage.PORT_FEEDBACK didn't handle the BoostPortFeedback.DISCARDED type, which corresponds to a command failing on the Boost hub.
2019-04-05 13:35:28 -04:00
Kevin Andersen
2c6a9d85cf Resolves #2087 and #2088 for rotation-based commands.
There's quite a few interactions between degrees, their sign, and the currently set direction for the motor the degrees relate to. In this case, BoostMotor.turnOnDegrees() was being run with -degrees, and since that function does a Math.max between 0 and degrees, it resulted in 0 degrees.

Because of this, and for clarity, turnOnDegrees now only gets called with positive values. If running CCW, that should be specified in the direction-parameter.
2019-04-05 13:05:52 -04:00
Kevin Andersen
e3cdbffa2a Resolves #2089.
Partly resolves #2087, #2088.

This was happening because scratch-vm is responsible for timed motor commands rather than using the Boost hubs commands to run motors for a specific amount of time.
This meant that when we simply sent a motorOn-command, the hub would immediately return feedback for the motor that the command had completed.
The fix for this was, for timed motor commands, to not receive feedback from the motor, and instead have scratch-vm modify the BoostMotor._status.

TODO: Fix for rotation-based commands.

Agreed. Changed to 50%.

- BoostMotorMaxPower changed to BoostMotorMaxPowerAdd and now describes an extra boost (no pun intended) to the motor. Documentation added that describes the feature.
- _colorBucket renamed to _colorSamples for clarity.
- oldColor is renamed to previousColor, and is now initialized in this._sensors.
- Modified documentation.
2019-04-04 15:37:48 -04:00
Kevin Nørby Andersen
f02433510a
Merge pull request #2061 from knandersen/boostextension
Add LEGO BOOST Scratch 3.0 extension
2019-04-03 19:05:37 -04:00
Chris Willis-Ford
e6cc678cef
Merge pull request #2083 from cwillisf/extension-buttons
Allow extensions to make buttons
2019-04-03 12:28:09 -07:00
Christopher Willis-Ford
a1abcf3226 Add a comment clarifying the items in _blockInfo[0].blocks 2019-04-03 11:36:38 -07:00
Christopher Willis-Ford
0162bfc71e Test the info field in converted extension data
There are parts of the extension registration process which rely on the
`info` field being non-null, even for block separators. At one point
during development I broke that, so here's a test to hopefully prevent
someone else from getting bitten by the same thing.
2019-04-03 11:02:56 -07:00
Christopher Willis-Ford
4cdbb26f57 Explicitly check that every extension block has an opcode 2019-04-03 11:01:00 -07:00
Christopher Willis-Ford
87a88e2caf Add a button to the CoreEx extension 2019-04-02 23:13:01 -07:00
Christopher Willis-Ford
9eef05a7c5 Use new Scratch-specific callback keys for extension buttons 2019-04-02 22:47:26 -07:00
Kevin Andersen
d8f7b2c74f updated package-lock.json 2019-04-02 19:32:07 -04:00
Christopher Willis-Ford
d59c6a0b73 Fix missing arg for extension block separators 2019-04-02 15:23:48 -07:00
Christopher Willis-Ford
254edd48d5 Add unit test for extension button 2019-04-01 18:09:09 -07:00
Christopher Willis-Ford
bed54bae1f Allow extensions to make buttons 2019-04-01 18:09:09 -07:00
Kevin Andersen
330fcc5297 Merge branch 'boostextension' of https://github.com/knandersen/scratch-vm into boostextension 2019-04-01 06:40:18 -04:00
Kevin Andersen
7f0355169e Cleaned up documentation and removed extra line breaks in response to @evhan55 PR comments 2019-04-01 06:38:29 -04:00
Katie Broida
445ee46984
Merge pull request #1943 from ktbee/clock-timer-compat-fix
Start executing hats before other threads change values
2019-03-29 13:01:28 -04:00
Katie Broida
2a60391fb4 Make Scratch 3 project timer more compatible with Scratch 2 currentMSecs usage
These compatibility changes:
 - Use runtime.currentMSecs for the Clock timer "now" value
 - Start executing hats before other threads change values
 - Update test and fixtures to work with earlier hat execution
 - Add test for hat execution block order
2019-03-29 11:43:37 -04:00