Merge pull request from cwillisf/extension-monitors

Extension monitors
This commit is contained in:
Chris Willis-Ford 2018-09-12 18:10:12 -04:00 committed by GitHub
commit 8977ce1e93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 74 additions and 3 deletions
src/engine

View file

@ -805,8 +805,12 @@ class Runtime extends EventEmitter {
}
}
// Add icon to the bottom right of a loop block
if (blockInfo.blockType === BlockType.LOOP) {
if (blockInfo.blockType === BlockType.REPORTER) {
if (!blockInfo.disableMonitor && context.inputList.length === 0) {
blockJSON.checkboxInFlyout = true;
}
} else if (blockInfo.blockType === BlockType.LOOP) {
// Add icon to the bottom right of a loop block
blockJSON[`lastDummyAlign${outLineNum}`] = 'RIGHT';
blockJSON[`message${outLineNum}`] = '%1';
blockJSON[`args${outLineNum}`] = [{
@ -1851,6 +1855,31 @@ class Runtime extends EventEmitter {
return varNames;
}
/**
* Get the label or label function for an opcode
* @param {string} extendedOpcode - the opcode you want a label for
* @return {object} - object with label and category
* @property {string} category - the category for this opcode
* @property {Function} [labelFn] - function to generate the label for this opcode
* @property {string} [label] - the label for this opcode if `labelFn` is absent
*/
getLabelForOpcode (extendedOpcode) {
const [category, opcode] = StringUtil.splitFirst(extendedOpcode, '_');
if (!(category && opcode)) return;
const categoryInfo = this._blockInfo.find(ci => ci.id === category);
if (!categoryInfo) return;
const block = categoryInfo.blocks.find(b => b.info.opcode === opcode);
if (!block) return;
// TODO: should this use some other category? Also, we may want to format the label in a locale-specific way.
return {
category: 'data',
label: `${categoryInfo.name}: ${block.info.text}`
};
}
/**
* Create a new global variable avoiding conflicts with other variable names.
* @param {string} variableName The desired variable name for the new global variable.