From 96fa7315d563c65a6c930ef9f1343fbbe939aa82 Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford Date: Fri, 13 Oct 2017 01:46:35 -0700 Subject: [PATCH 1/2] Don't overwrite hat block's fields Due to a typo (I believe) we were overwriting a horizontal hat block's fields list when collecting hat block inputs. Now we collect inputs into a temporary object in this case. --- src/engine/runtime.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/engine/runtime.js b/src/engine/runtime.js index dc76452b7..280f11d83 100644 --- a/src/engine/runtime.js +++ b/src/engine/runtime.js @@ -409,6 +409,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); @@ -802,13 +805,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); } } From 1a9e28bfc9665ef6f87c4de480a59dd8314936a0 Mon Sep 17 00:00:00 2001 From: Christopher Willis-Ford Date: Fri, 13 Oct 2017 01:48:25 -0700 Subject: [PATCH 2/2] Small WeDo 2.0 fixups --- src/blocks/scratch3_wedo2.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/blocks/scratch3_wedo2.js b/src/blocks/scratch3_wedo2.js index 103694410..abc09e5db 100644 --- a/src/blocks/scratch3_wedo2.js +++ b/src/blocks/scratch3_wedo2.js @@ -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 '<': return this._device.distance < args.REFERENCE; case '>': + case '>': 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; } /**