From 144a0b349df8cc46bdab79de312d2bf2d5e819b5 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Mon, 22 May 2017 13:38:29 -0400 Subject: [PATCH 1/4] Change monitor reporting from category and label to opcode --- src/engine/blocks.js | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/engine/blocks.js b/src/engine/blocks.js index ebe113f8..6177e400 100644 --- a/src/engine/blocks.js +++ b/src/engine/blocks.js @@ -278,7 +278,7 @@ class Blocks { const block = this._blocks[args.id]; if (typeof block === 'undefined') return; - let wasMonitored = block.isMonitored; + const wasMonitored = block.isMonitored; switch (args.element) { case 'field': // Update block value @@ -293,22 +293,17 @@ class Blocks { if (optRuntime && wasMonitored && !block.isMonitored) { optRuntime.requestRemoveMonitor(block.id); } else if (optRuntime && !wasMonitored && block.isMonitored) { - optRuntime.requestAddMonitor( - // Ensure that value is not undefined, since React requires it - { - // @todo(vm#564) this will collide if multiple sprites use same block - id: block.id, - category: 'data', - // @todo(vm#565) how to handle translation here? - label: block.opcode, - // @todo(vm#565) for numerical values with decimals, some countries use comma - value: '', - x: 0, - // @todo(vm#566) Don't require sending x and y when instantiating a - // monitor. If it's not preset the GUI should decide. - y: 0 - } - ); + optRuntime.requestAddMonitor({ + // @todo(vm#564) this will collide if multiple sprites use same block + id: block.id, + opcode: block.opcode, + // @todo(vm#565) for numerical values with decimals, some countries use comma + value: '', + // @todo(vm#566) Don't require sending x and y when instantiating a + // monitor. If it's not preset the GUI should decide. + x: 0, + y: 0 + }); } break; } @@ -370,7 +365,7 @@ class Blocks { } } - + /** * Block management: run all blocks. * @param {!object} runtime Runtime to run all blocks in. From 817ea47e3261c87195a52ce4a1ffe8b60c600eb6 Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Mon, 22 May 2017 14:40:07 -0400 Subject: [PATCH 2/4] Remove XY from monitor reporting --- src/engine/blocks.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/engine/blocks.js b/src/engine/blocks.js index 6177e400..a65e4ac1 100644 --- a/src/engine/blocks.js +++ b/src/engine/blocks.js @@ -298,11 +298,7 @@ class Blocks { id: block.id, opcode: block.opcode, // @todo(vm#565) for numerical values with decimals, some countries use comma - value: '', - // @todo(vm#566) Don't require sending x and y when instantiating a - // monitor. If it's not preset the GUI should decide. - x: 0, - y: 0 + value: '' }); } break; From 5973e2d305bdf3762001bee94de4326c77572ede Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Mon, 22 May 2017 15:18:48 -0400 Subject: [PATCH 3/4] Add reporting for block params --- src/engine/blocks.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/engine/blocks.js b/src/engine/blocks.js index a65e4ac1..c0595171 100644 --- a/src/engine/blocks.js +++ b/src/engine/blocks.js @@ -267,6 +267,25 @@ class Blocks { } } + /** + * Serialize block fields and input fields for reporting new monitors + * @param {!object} block Block to be paramified. + * @return {!object} object of param key/values. + */ + getBlockParams (block) { + const params = {}; + for (const key in block.fields) { + params[key] = block.fields[key].value; + } + for (const inputKey in block.inputs) { + const inputBlock = this._blocks[block.inputs[inputKey].block]; + for (const key in inputBlock.fields) { + params[key] = inputBlock.fields[key].value; + } + } + return params; + } + /** * Block management: change block field values * @param {!object} args Blockly change event to be processed @@ -297,6 +316,7 @@ class Blocks { // @todo(vm#564) this will collide if multiple sprites use same block id: block.id, opcode: block.opcode, + params: this.getBlockParams(block), // @todo(vm#565) for numerical values with decimals, some countries use comma value: '' }); From df9230a0ff98317ea3303dd437d906b1ec907b8d Mon Sep 17 00:00:00 2001 From: Paul Kaplan Date: Tue, 23 May 2017 09:55:42 -0400 Subject: [PATCH 4/4] Make helper private --- src/engine/blocks.js | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/engine/blocks.js b/src/engine/blocks.js index c0595171..8a3436f5 100644 --- a/src/engine/blocks.js +++ b/src/engine/blocks.js @@ -267,25 +267,6 @@ class Blocks { } } - /** - * Serialize block fields and input fields for reporting new monitors - * @param {!object} block Block to be paramified. - * @return {!object} object of param key/values. - */ - getBlockParams (block) { - const params = {}; - for (const key in block.fields) { - params[key] = block.fields[key].value; - } - for (const inputKey in block.inputs) { - const inputBlock = this._blocks[block.inputs[inputKey].block]; - for (const key in inputBlock.fields) { - params[key] = inputBlock.fields[key].value; - } - } - return params; - } - /** * Block management: change block field values * @param {!object} args Blockly change event to be processed @@ -316,7 +297,7 @@ class Blocks { // @todo(vm#564) this will collide if multiple sprites use same block id: block.id, opcode: block.opcode, - params: this.getBlockParams(block), + params: this._getBlockParams(block), // @todo(vm#565) for numerical values with decimals, some countries use comma value: '' }); @@ -525,6 +506,24 @@ class Blocks { } // --------------------------------------------------------------------- + /** + * Helper to serialize block fields and input fields for reporting new monitors + * @param {!object} block Block to be paramified. + * @return {!object} object of param key/values. + */ + _getBlockParams (block) { + const params = {}; + for (const key in block.fields) { + params[key] = block.fields[key].value; + } + for (const inputKey in block.inputs) { + const inputBlock = this._blocks[block.inputs[inputKey].block]; + for (const key in inputBlock.fields) { + params[key] = inputBlock.fields[key].value; + } + } + return params; + } /** * Helper to add a stack to `this._scripts`.