Add listener for new blocks that doesn't add to stacks

This commit is contained in:
Tim Mickel 2016-04-29 16:49:08 -04:00
parent ab5c79730c
commit 11c6537f42
2 changed files with 26 additions and 2 deletions

View file

@ -51,6 +51,7 @@ Runtime.THREAD_STEP_INTERVAL = 1000 / 60;
* @param {!Object} block Blockly create event to be processed
*/
Runtime.prototype.createBlock = function (block) {
Runtime.prototype.createBlock = function (block, opt_isFlyoutBlock) {
// Create new block
this.blocks[block.id] = block;
@ -67,7 +68,9 @@ Runtime.prototype.createBlock = function (block) {
// Push block id to stacks array. New blocks are always a stack even if only
// momentary. If the new block is added to an existing stack this stack will
// be removed by the `moveBlock` method below.
this.stacks.push(block.id);
if (!opt_isFlyoutBlock) {
this.stacks.push(block.id);
}
};
/**

View file

@ -31,7 +31,7 @@ function VirtualMachine () {
// Blocks
switch (e.type) {
case 'create':
instance.runtime.createBlock(adapter(e));
instance.runtime.createBlock(adapter(e), false);
break;
case 'change':
instance.runtime.changeBlock({
@ -57,6 +57,27 @@ function VirtualMachine () {
break;
}
};
instance.flyoutBlockListener = function (e) {
switch (e.type) {
case 'create':
instance.runtime.createBlock(adapter(e), true);
break;
case 'change':
instance.runtime.changeBlock({
id: e.blockId,
element: e.element,
name: e.name,
value: e.newValue
});
break;
case 'delete':
instance.runtime.deleteBlock({
id: e.blockId
});
break;
}
};
}
/**