mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 06:23:37 -05:00
Switch Blockly listener to normal function (not closure/generated)
This commit is contained in:
parent
aa70c1bc3b
commit
05a5369d7b
1 changed files with 43 additions and 49 deletions
|
@ -120,18 +120,12 @@ Blocks.prototype.getInputs = function (id) {
|
||||||
/**
|
/**
|
||||||
* Create event listener for blocks. Handles validation and serves as a generic
|
* Create event listener for blocks. Handles validation and serves as a generic
|
||||||
* adapter between the blocks and the runtime interface.
|
* adapter between the blocks and the runtime interface.
|
||||||
|
* @param {Object} e Blockly "block" event
|
||||||
* @param {boolean} isFlyout If true, create a listener for flyout events.
|
* @param {boolean} isFlyout If true, create a listener for flyout events.
|
||||||
* @param {?Runtime} opt_runtime Optional runtime to forward click events to.
|
* @param {?Runtime} opt_runtime Optional runtime to forward click events to.
|
||||||
* @return {Function} A generated listener to attach to Blockly instance.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Blocks.prototype.generateBlockListener = function (isFlyout, opt_runtime) {
|
Blocks.prototype.blocklyListen = function (e, isFlyout, opt_runtime) {
|
||||||
var instance = this;
|
|
||||||
/**
|
|
||||||
* The actual generated block listener.
|
|
||||||
* @param {Object} e Blockly "block" event
|
|
||||||
*/
|
|
||||||
return function (e) {
|
|
||||||
// Validate event
|
// Validate event
|
||||||
if (typeof e !== 'object') return;
|
if (typeof e !== 'object') return;
|
||||||
if (typeof e.blockId !== 'string') return;
|
if (typeof e.blockId !== 'string') return;
|
||||||
|
@ -150,11 +144,11 @@ Blocks.prototype.generateBlockListener = function (isFlyout, opt_runtime) {
|
||||||
var newBlocks = adapter(e);
|
var newBlocks = adapter(e);
|
||||||
// A create event can create many blocks. Add them all.
|
// A create event can create many blocks. Add them all.
|
||||||
for (var i = 0; i < newBlocks.length; i++) {
|
for (var i = 0; i < newBlocks.length; i++) {
|
||||||
instance.createBlock(newBlocks[i], isFlyout);
|
this.createBlock(newBlocks[i], isFlyout);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'change':
|
case 'change':
|
||||||
instance.changeBlock({
|
this.changeBlock({
|
||||||
id: e.blockId,
|
id: e.blockId,
|
||||||
element: e.element,
|
element: e.element,
|
||||||
name: e.name,
|
name: e.name,
|
||||||
|
@ -162,21 +156,21 @@ Blocks.prototype.generateBlockListener = function (isFlyout, opt_runtime) {
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 'move':
|
case 'move':
|
||||||
instance.moveBlock({
|
this.moveBlock({
|
||||||
id: e.blockId,
|
id: e.blockId,
|
||||||
oldParent: e.oldParentId,
|
oldParent: e.oldParentId,
|
||||||
oldInput: e.oldInputName,
|
oldInput: e.oldInputName,
|
||||||
newParent: e.newParentId,
|
newParent: e.newParentId,
|
||||||
newInput: e.newInputName
|
newInput: e.newInputName,
|
||||||
|
newCoordinate: e.newCoordinate
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case 'delete':
|
case 'delete':
|
||||||
instance.deleteBlock({
|
this.deleteBlock({
|
||||||
id: e.blockId
|
id: e.blockId
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in a new issue