Fix importing WeDo 2.0 blocks from SB2 (#1487)

* Fix wedo2 import from sb2

* Hide wedo play note block
This commit is contained in:
Eric Rosenbaum 2018-08-16 14:24:19 -04:00 committed by GitHub
parent 0df334fd38
commit 825035f503
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 59 additions and 58 deletions

View file

@ -746,7 +746,7 @@ class Scratch3WeDo2Blocks {
arguments: { arguments: {
MOTOR_ID: { MOTOR_ID: {
type: ArgumentType.STRING, type: ArgumentType.STRING,
menu: 'motorID', menu: 'MOTOR_ID',
defaultValue: MotorID.DEFAULT defaultValue: MotorID.DEFAULT
}, },
DURATION: { DURATION: {
@ -766,7 +766,7 @@ class Scratch3WeDo2Blocks {
arguments: { arguments: {
MOTOR_ID: { MOTOR_ID: {
type: ArgumentType.STRING, type: ArgumentType.STRING,
menu: 'motorID', menu: 'MOTOR_ID',
defaultValue: MotorID.DEFAULT defaultValue: MotorID.DEFAULT
} }
} }
@ -782,7 +782,7 @@ class Scratch3WeDo2Blocks {
arguments: { arguments: {
MOTOR_ID: { MOTOR_ID: {
type: ArgumentType.STRING, type: ArgumentType.STRING,
menu: 'motorID', menu: 'MOTOR_ID',
defaultValue: MotorID.DEFAULT defaultValue: MotorID.DEFAULT
} }
} }
@ -798,7 +798,7 @@ class Scratch3WeDo2Blocks {
arguments: { arguments: {
MOTOR_ID: { MOTOR_ID: {
type: ArgumentType.STRING, type: ArgumentType.STRING,
menu: 'motorID', menu: 'MOTOR_ID',
defaultValue: MotorID.DEFAULT defaultValue: MotorID.DEFAULT
}, },
POWER: { POWER: {
@ -811,19 +811,19 @@ class Scratch3WeDo2Blocks {
opcode: 'setMotorDirection', opcode: 'setMotorDirection',
text: formatMessage({ text: formatMessage({
id: 'wedo2.setMotorDirection', id: 'wedo2.setMotorDirection',
default: 'set [MOTOR_ID] direction to [DIRECTION]', default: 'set [MOTOR_ID] direction to [MOTOR_DIRECTION]',
description: 'set the motor\'s turn direction' description: 'set the motor\'s turn direction'
}), }),
blockType: BlockType.COMMAND, blockType: BlockType.COMMAND,
arguments: { arguments: {
MOTOR_ID: { MOTOR_ID: {
type: ArgumentType.STRING, type: ArgumentType.STRING,
menu: 'motorID', menu: 'MOTOR_ID',
defaultValue: MotorID.DEFAULT defaultValue: MotorID.DEFAULT
}, },
DIRECTION: { MOTOR_DIRECTION: {
type: ArgumentType.STRING, type: ArgumentType.STRING,
menu: 'motorDirection', menu: 'MOTOR_DIRECTION',
defaultValue: MotorDirection.FORWARD defaultValue: MotorDirection.FORWARD
} }
} }
@ -860,7 +860,8 @@ class Scratch3WeDo2Blocks {
type: ArgumentType.NUMBER, type: ArgumentType.NUMBER,
defaultValue: 0.5 defaultValue: 0.5
} }
} },
hideFromPalette: true
}, },
{ {
opcode: 'whenDistance', opcode: 'whenDistance',
@ -873,7 +874,7 @@ class Scratch3WeDo2Blocks {
arguments: { arguments: {
OP: { OP: {
type: ArgumentType.STRING, type: ArgumentType.STRING,
menu: 'lessMore', menu: 'OP',
defaultValue: '<' defaultValue: '<'
}, },
REFERENCE: { REFERENCE: {
@ -886,15 +887,15 @@ class Scratch3WeDo2Blocks {
opcode: 'whenTilted', opcode: 'whenTilted',
text: formatMessage({ text: formatMessage({
id: 'wedo2.whenTilted', id: 'wedo2.whenTilted',
default: 'when tilted [DIRECTION]', default: 'when tilted [TILT_DIRECTION_ANY]',
description: 'check when tilted in a certain direction' description: 'check when tilted in a certain direction'
}), }),
func: 'isTilted', func: 'isTilted',
blockType: BlockType.HAT, blockType: BlockType.HAT,
arguments: { arguments: {
DIRECTION: { TILT_DIRECTION_ANY: {
type: ArgumentType.STRING, type: ArgumentType.STRING,
menu: 'tiltDirectionAny', menu: 'TILT_DIRECTION_ANY',
defaultValue: TiltDirection.ANY defaultValue: TiltDirection.ANY
} }
} }
@ -912,14 +913,14 @@ class Scratch3WeDo2Blocks {
opcode: 'isTilted', opcode: 'isTilted',
text: formatMessage({ text: formatMessage({
id: 'wedo2.isTilted', id: 'wedo2.isTilted',
default: 'tilted [DIRECTION]?', default: 'tilted [TILT_DIRECTION_ANY]?',
description: 'whether the tilt sensor is tilted' description: 'whether the tilt sensor is tilted'
}), }),
blockType: BlockType.BOOLEAN, blockType: BlockType.BOOLEAN,
arguments: { arguments: {
DIRECTION: { TILT_DIRECTION_ANY: {
type: ArgumentType.STRING, type: ArgumentType.STRING,
menu: 'tiltDirectionAny', menu: 'TILT_DIRECTION_ANY',
defaultValue: TiltDirection.ANY defaultValue: TiltDirection.ANY
} }
} }
@ -928,26 +929,26 @@ class Scratch3WeDo2Blocks {
opcode: 'getTiltAngle', opcode: 'getTiltAngle',
text: formatMessage({ text: formatMessage({
id: 'wedo2.getTiltAngle', id: 'wedo2.getTiltAngle',
default: 'tilt angle [DIRECTION]', default: 'tilt angle [TILT_DIRECTION]',
description: 'the angle returned by the tilt sensor' description: 'the angle returned by the tilt sensor'
}), }),
blockType: BlockType.REPORTER, blockType: BlockType.REPORTER,
arguments: { arguments: {
DIRECTION: { TILT_DIRECTION: {
type: ArgumentType.STRING, type: ArgumentType.STRING,
menu: 'tiltDirection', menu: 'TILT_DIRECTION',
defaultValue: TiltDirection.UP defaultValue: TiltDirection.UP
} }
} }
} }
], ],
menus: { menus: {
motorID: [MotorID.DEFAULT, MotorID.A, MotorID.B, MotorID.ALL], MOTOR_ID: [MotorID.DEFAULT, MotorID.A, MotorID.B, MotorID.ALL],
motorDirection: [MotorDirection.FORWARD, MotorDirection.BACKWARD, MotorDirection.REVERSE], MOTOR_DIRECTION: [MotorDirection.FORWARD, MotorDirection.BACKWARD, MotorDirection.REVERSE],
tiltDirection: [TiltDirection.UP, TiltDirection.DOWN, TiltDirection.LEFT, TiltDirection.RIGHT], TILT_DIRECTION: [TiltDirection.UP, TiltDirection.DOWN, TiltDirection.LEFT, TiltDirection.RIGHT],
tiltDirectionAny: TILT_DIRECTION_ANY:
[TiltDirection.UP, TiltDirection.DOWN, TiltDirection.LEFT, TiltDirection.RIGHT, TiltDirection.ANY], [TiltDirection.UP, TiltDirection.DOWN, TiltDirection.LEFT, TiltDirection.RIGHT, TiltDirection.ANY],
lessMore: ['<', '>'] OP: ['<', '>']
} }
}; };
} }
@ -1024,13 +1025,13 @@ class Scratch3WeDo2Blocks {
* If the direction is 'reverse' the motor(s) will be reversed individually. * If the direction is 'reverse' the motor(s) will be reversed individually.
* @param {object} args - the block's arguments. * @param {object} args - the block's arguments.
* @property {MotorID} MOTOR_ID - the motor(s) to be affected. * @property {MotorID} MOTOR_ID - the motor(s) to be affected.
* @property {MotorDirection} DIRECTION - the new direction for the motor(s). * @property {MotorDirection} MOTOR_DIRECTION - the new direction for the motor(s).
*/ */
setMotorDirection (args) { setMotorDirection (args) {
this._forEachMotor(args.MOTOR_ID, motorIndex => { this._forEachMotor(args.MOTOR_ID, motorIndex => {
const motor = this._device.motor(motorIndex); const motor = this._device.motor(motorIndex);
if (motor) { if (motor) {
switch (args.DIRECTION) { switch (args.MOTOR_DIRECTION) {
case MotorDirection.FORWARD: case MotorDirection.FORWARD:
motor.direction = 1; motor.direction = 1;
break; break;
@ -1118,11 +1119,11 @@ class Scratch3WeDo2Blocks {
/** /**
* Test whether the tilt sensor is currently tilted. * Test whether the tilt sensor is currently tilted.
* @param {object} args - the block's arguments. * @param {object} args - the block's arguments.
* @property {TiltDirection} DIRECTION - the tilt direction to test (up, down, left, right, or any). * @property {TiltDirection} TILT_DIRECTION_ANY - the tilt direction to test (up, down, left, right, or any).
* @return {boolean} - true if the tilt sensor is tilted past a threshold in the specified direction. * @return {boolean} - true if the tilt sensor is tilted past a threshold in the specified direction.
*/ */
whenTilted (args) { whenTilted (args) {
return this._isTilted(args.DIRECTION); return this._isTilted(args.TILT_DIRECTION_ANY);
} }
/** /**
@ -1135,21 +1136,21 @@ class Scratch3WeDo2Blocks {
/** /**
* Test whether the tilt sensor is currently tilted. * Test whether the tilt sensor is currently tilted.
* @param {object} args - the block's arguments. * @param {object} args - the block's arguments.
* @property {TiltDirection} DIRECTION - the tilt direction to test (up, down, left, right, or any). * @property {TiltDirection} TILT_DIRECTION_ANY - the tilt direction to test (up, down, left, right, or any).
* @return {boolean} - true if the tilt sensor is tilted past a threshold in the specified direction. * @return {boolean} - true if the tilt sensor is tilted past a threshold in the specified direction.
*/ */
isTilted (args) { isTilted (args) {
return this._isTilted(args.DIRECTION); return this._isTilted(args.TILT_DIRECTION_ANY);
} }
/** /**
* @param {object} args - the block's arguments. * @param {object} args - the block's arguments.
* @property {TiltDirection} DIRECTION - the direction (up, down, left, right) to check. * @property {TiltDirection} TILT_DIRECTION - the direction (up, down, left, right) to check.
* @return {number} - the tilt sensor's angle in the specified direction. * @return {number} - the tilt sensor's angle in the specified direction.
* Note that getTiltAngle(up) = -getTiltAngle(down) and getTiltAngle(left) = -getTiltAngle(right). * Note that getTiltAngle(up) = -getTiltAngle(down) and getTiltAngle(left) = -getTiltAngle(right).
*/ */
getTiltAngle (args) { getTiltAngle (args) {
return this._getTiltAngle(args.DIRECTION); return this._getTiltAngle(args.TILT_DIRECTION);
} }
/** /**

View file

@ -1621,11 +1621,11 @@ const addExtensionOp = function (sb2Extension, sb2Opcode, blockInfo) {
const weDo2 = 'LEGO WeDo 2.0'; const weDo2 = 'LEGO WeDo 2.0';
addExtensionOp(weDo2, 'motorOnFor', { addExtensionOp(weDo2, 'motorOnFor', {
opcode: 'wedo2.motorOnFor', opcode: 'wedo2_motorOnFor',
argMap: [ argMap: [
{ {
type: 'input', type: 'input',
inputOp: 'wedo2.menu.motorID', inputOp: 'wedo2_menu_MOTOR_ID',
inputName: 'MOTOR_ID' inputName: 'MOTOR_ID'
}, },
{ {
@ -1637,33 +1637,33 @@ addExtensionOp(weDo2, 'motorOnFor', {
}); });
addExtensionOp(weDo2, 'motorOn', { addExtensionOp(weDo2, 'motorOn', {
opcode: 'wedo2.motorOn', opcode: 'wedo2_motorOn',
argMap: [ argMap: [
{ {
type: 'input', type: 'input',
inputOp: 'wedo2.menu.motorID', inputOp: 'wedo2_menu_MOTOR_ID',
inputName: 'MOTOR_ID' inputName: 'MOTOR_ID'
} }
] ]
}); });
addExtensionOp(weDo2, 'motorOff', { addExtensionOp(weDo2, 'motorOff', {
opcode: 'wedo2.motorOff', opcode: 'wedo2_motorOff',
argMap: [ argMap: [
{ {
type: 'input', type: 'input',
inputOp: 'wedo2.menu.motorID', inputOp: 'wedo2_menu_MOTOR_ID',
inputName: 'MOTOR_ID' inputName: 'MOTOR_ID'
} }
] ]
}); });
addExtensionOp(weDo2, 'startMotorPower', { addExtensionOp(weDo2, 'startMotorPower', {
opcode: 'wedo2.startMotorPower', opcode: 'wedo2_startMotorPower',
argMap: [ argMap: [
{ {
type: 'input', type: 'input',
inputOp: 'wedo2.menu.motorID', inputOp: 'wedo2_menu_MOTOR_ID',
inputName: 'MOTOR_ID' inputName: 'MOTOR_ID'
}, },
{ {
@ -1675,23 +1675,23 @@ addExtensionOp(weDo2, 'startMotorPower', {
}); });
addExtensionOp(weDo2, 'setMotorDirection', { addExtensionOp(weDo2, 'setMotorDirection', {
opcode: 'wedo2.setMotorDirection', opcode: 'wedo2_setMotorDirection',
argMap: [ argMap: [
{ {
type: 'input', type: 'input',
inputOp: 'wedo2.menu.motorID', inputOp: 'wedo2_menu_MOTOR_ID',
inputName: 'MOTOR_ID' inputName: 'MOTOR_ID'
}, },
{ {
type: 'input', type: 'input',
inputOp: 'wedo2.menu.motorDirection', inputOp: 'wedo2_menu_MOTOR_DIRECTION',
inputName: 'DIRECTION' inputName: 'MOTOR_DIRECTION'
} }
] ]
}); });
addExtensionOp(weDo2, 'setLED', { addExtensionOp(weDo2, 'setLED', {
opcode: 'wedo2.setLightHue', opcode: 'wedo2_setLightHue',
argMap: [ argMap: [
{ {
type: 'input', type: 'input',
@ -1702,7 +1702,7 @@ addExtensionOp(weDo2, 'setLED', {
}); });
addExtensionOp(weDo2, 'playNote', { addExtensionOp(weDo2, 'playNote', {
opcode: 'wedo2.playNoteFor', opcode: 'wedo2_playNoteFor',
argMap: [ argMap: [
{ {
type: 'input', type: 'input',
@ -1718,11 +1718,11 @@ addExtensionOp(weDo2, 'playNote', {
}); });
addExtensionOp(weDo2, 'whenDistance', { addExtensionOp(weDo2, 'whenDistance', {
opcode: 'wedo2.whenDistance', opcode: 'wedo2_whenDistance',
argMap: [ argMap: [
{ {
type: 'input', type: 'input',
inputOp: 'wedo2.menu.lessMore', inputOp: 'wedo2_menu_OP',
inputName: 'OP' inputName: 'OP'
}, },
{ {
@ -1734,39 +1734,39 @@ addExtensionOp(weDo2, 'whenDistance', {
}); });
addExtensionOp(weDo2, 'whenTilted', { addExtensionOp(weDo2, 'whenTilted', {
opcode: 'wedo2.whenTilted', opcode: 'wedo2_whenTilted',
argMap: [ argMap: [
{ {
type: 'input', type: 'input',
inputOp: 'wedo2.menu.tiltDirectionAny', inputOp: 'wedo2_menu_TILT_DIRECTION_ANY',
inputName: 'DIRECTION' inputName: 'TILT_DIRECTION_ANY'
} }
] ]
}); });
addExtensionOp(weDo2, 'getDistance', { addExtensionOp(weDo2, 'getDistance', {
opcode: 'wedo2.getDistance', opcode: 'wedo2_getDistance',
argMap: [] argMap: []
}); });
addExtensionOp(weDo2, 'isTilted', { addExtensionOp(weDo2, 'isTilted', {
opcode: 'wedo2.isTilted', opcode: 'wedo2_isTilted',
argMap: [ argMap: [
{ {
type: 'input', type: 'input',
inputOp: 'wedo2.menu.tiltDirectionAny', inputOp: 'wedo2_menu_TILT_DIRECTION_ANY',
inputName: 'DIRECTION' inputName: 'TILT_DIRECTION_ANY'
} }
] ]
}); });
addExtensionOp(weDo2, 'getTilt', { addExtensionOp(weDo2, 'getTilt', {
opcode: 'wedo2.getTiltAngle', opcode: 'wedo2_getTiltAngle',
argMap: [ argMap: [
{ {
type: 'input', type: 'input',
inputOp: 'wedo2.menu.tiltDirection', inputOp: 'wedo2_menu_TILT_DIRECTION',
inputName: 'DIRECTION' inputName: 'TILT_DIRECTION'
} }
] ]
}); });