Merge pull request from paulkaplan/feature/monitor-labels

Send monitor opcode and block params instead of fixed label/categories
This commit is contained in:
Paul Kaplan 2017-05-26 11:07:58 -04:00 committed by GitHub
commit 3e9dfde43f

View file

@ -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,14 @@ 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,
params: this._getBlockParams(block),
// @todo(vm#565) for numerical values with decimals, some countries use comma
value: ''
});
}
break;
}
@ -370,7 +362,7 @@ class Blocks {
}
}
/**
* Block management: run all blocks.
* @param {!object} runtime Runtime to run all blocks in.
@ -514,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`.