Merge pull request #713 from cwillisf/fix-extension-hats

Fix extension hats
This commit is contained in:
Chris Willis-Ford 2017-10-13 16:03:51 -07:00 committed by GitHub
commit c4e79c9732
2 changed files with 9 additions and 3 deletions

View file

@ -245,7 +245,7 @@ class WeDo2 {
* @return {number} - the latest value received from the distance sensor.
*/
get distance () {
return this._sensors.distance;
return this._sensors.distance * 10;
}
/**
@ -732,8 +732,10 @@ class Scratch3WeDo2Blocks {
whenDistance (args) {
switch (args.OP) {
case '<':
case '&lt;':
return this._device.distance < args.REFERENCE;
case '>':
case '&gt;':
return this._device.distance > args.REFERENCE;
default:
log.warn(`Unknown comparison operator in whenDistance: ${args.OP}`);
@ -755,7 +757,7 @@ class Scratch3WeDo2Blocks {
* @return {number} - the distance sensor's value, scaled to the [0,100] range.
*/
getDistance () {
return this._device.distance * 10;
return this._device.distance;
}
/**

View file

@ -442,6 +442,9 @@ class Runtime extends EventEmitter {
const opcode = convertedBlock.json.type;
categoryInfo.blocks.push(convertedBlock);
this._primitives[opcode] = convertedBlock.info.func;
if (blockInfo.blockType === BlockType.HAT) {
this._hats[opcode] = {edgeActivated: true}; /** @TODO let extension specify this */
}
}
this.emit(Runtime.EXTENSION_ADDED, categoryInfo.blocks.concat(categoryInfo.menus));
@ -898,13 +901,14 @@ class Runtime extends EventEmitter {
// If no fields are present, check inputs (horizontal blocks)
if (Object.keys(hatFields).length === 0) {
hatFields = {}; // don't overwrite the block's actual fields list
const hatInputs = blocks.getInputs(block);
for (const input in hatInputs) {
if (!hatInputs.hasOwnProperty(input)) continue;
const id = hatInputs[input].block;
const inpBlock = blocks.getBlock(id);
const fields = blocks.getFields(inpBlock);
hatFields = Object.assign(fields, hatFields);
Object.assign(hatFields, fields);
}
}