mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-22 22:12:28 -05:00
Add listener for new blocks that doesn't add to stacks
This commit is contained in:
parent
ab5c79730c
commit
11c6537f42
2 changed files with 26 additions and 2 deletions
|
@ -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.
|
||||
if (!opt_isFlyoutBlock) {
|
||||
this.stacks.push(block.id);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
23
src/index.js
23
src/index.js
|
@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue