mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Rewrite of moveBlock to better reflect Blockly
This commit is contained in:
parent
214daa8087
commit
aa152fd604
1 changed files with 25 additions and 24 deletions
|
@ -121,34 +121,35 @@ Runtime.prototype.changeBlock = function (args) {
|
||||||
Runtime.prototype.moveBlock = function (e) {
|
Runtime.prototype.moveBlock = function (e) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
// Block was removed from parent
|
// Remove from any old parent.
|
||||||
if (e.newParent === undefined && e.oldParent !== undefined) {
|
if (e.oldParent !== undefined) {
|
||||||
_this.addStack(e.id);
|
var oldParent = _this.blocks[e.oldParent];
|
||||||
|
if (e.oldInput !== undefined &&
|
||||||
// Update old parent
|
oldParent.inputs[e.oldInput].block === e.id) {
|
||||||
if (e.oldField === undefined) {
|
// This block was connected to the old parent's input.
|
||||||
_this.blocks[e.oldParent].next = null;
|
oldParent.inputs[e.oldInput].block = null;
|
||||||
} else {
|
} else if (oldParent.next === e.id) {
|
||||||
delete _this.blocks[e.oldParent].fields[e.oldField];
|
// This block was connected to the old parent's next connection.
|
||||||
|
oldParent.next = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (e.newParent !== undefined) {
|
|
||||||
// Block was moved to a new parent
|
|
||||||
// Either happens because it was previously parentless
|
|
||||||
// (e.oldParent === undefined)
|
|
||||||
// or because a block was moved in front of it.
|
|
||||||
|
|
||||||
// Remove stack
|
// Has the block become a top-level block?
|
||||||
_this._deleteStack(e.id);
|
if (e.newParent === undefined) {
|
||||||
|
_this._addStack(e.id);
|
||||||
// Update new parent
|
|
||||||
if (e.newField === undefined) {
|
|
||||||
_this.blocks[e.newParent].next = e.id;
|
|
||||||
} else {
|
} else {
|
||||||
_this.blocks[e.newParent].fields[e.newField] = {
|
// Remove stack, if one exists.
|
||||||
name: e.newField,
|
_this._deleteStack(e.id);
|
||||||
value: e.id,
|
// Otherwise, try to connect it in its new place.
|
||||||
blocks: {}
|
if (e.newInput !== undefined) {
|
||||||
|
// Moved to the new parent's input.
|
||||||
|
_this.blocks[e.newParent].inputs[e.newInput] = {
|
||||||
|
name: e.newInput,
|
||||||
|
block: e.id
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
|
// Moved to the new parent's next connection.
|
||||||
|
_this.blocks[e.newParent].next = e.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue