mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 06:23:37 -05:00
Merge pull request #9 from tmickel/feature/flyout-listening
Add listener for new blocks that doesn't add to stacks
This commit is contained in:
commit
69450031cd
2 changed files with 26 additions and 3 deletions
|
@ -50,7 +50,7 @@ Runtime.THREAD_STEP_INTERVAL = 1000 / 60;
|
||||||
* Block management: create blocks and stacks from a `create` event
|
* Block management: create blocks and stacks from a `create` event
|
||||||
* @param {!Object} block Blockly create event to be processed
|
* @param {!Object} block Blockly create event to be processed
|
||||||
*/
|
*/
|
||||||
Runtime.prototype.createBlock = function (block) {
|
Runtime.prototype.createBlock = function (block, opt_isFlyoutBlock) {
|
||||||
// Create new block
|
// Create new block
|
||||||
this.blocks[block.id] = block;
|
this.blocks[block.id] = block;
|
||||||
|
|
||||||
|
@ -67,7 +67,9 @@ Runtime.prototype.createBlock = function (block) {
|
||||||
// Push block id to stacks array. New blocks are always a stack even if only
|
// 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
|
// momentary. If the new block is added to an existing stack this stack will
|
||||||
// be removed by the `moveBlock` method below.
|
// be removed by the `moveBlock` method below.
|
||||||
this.stacks.push(block.id);
|
if (!opt_isFlyoutBlock) {
|
||||||
|
this.stacks.push(block.id);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
23
src/index.js
23
src/index.js
|
@ -31,7 +31,7 @@ function VirtualMachine () {
|
||||||
// Blocks
|
// Blocks
|
||||||
switch (e.type) {
|
switch (e.type) {
|
||||||
case 'create':
|
case 'create':
|
||||||
instance.runtime.createBlock(adapter(e));
|
instance.runtime.createBlock(adapter(e), false);
|
||||||
break;
|
break;
|
||||||
case 'change':
|
case 'change':
|
||||||
instance.runtime.changeBlock({
|
instance.runtime.changeBlock({
|
||||||
|
@ -57,6 +57,27 @@ function VirtualMachine () {
|
||||||
break;
|
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