mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-07-09 12:33:58 -04:00
Create a new input if one doesn't exist (#148)
* Create a new input if one doesn't exist * Add regression tests for move-into-empty and obscuring shadows via move
This commit is contained in:
parent
f7e339f7c2
commit
14feb64005
2 changed files with 70 additions and 3 deletions
|
@ -249,9 +249,15 @@ Blocks.prototype.moveBlock = function (e) {
|
||||||
if (e.newInput !== undefined) {
|
if (e.newInput !== undefined) {
|
||||||
// Moved to the new parent's input.
|
// Moved to the new parent's input.
|
||||||
// Don't obscure the shadow block.
|
// Don't obscure the shadow block.
|
||||||
var newInput = this._blocks[e.newParent].inputs[e.newInput];
|
var oldShadow = null;
|
||||||
newInput.name = e.newInput;
|
if (this._blocks[e.newParent].inputs.hasOwnProperty(e.newInput)) {
|
||||||
newInput.block = e.id;
|
oldShadow = this._blocks[e.newParent].inputs[e.newInput].shadow;
|
||||||
|
}
|
||||||
|
this._blocks[e.newParent].inputs[e.newInput] = {
|
||||||
|
name: e.newInput,
|
||||||
|
block: e.id,
|
||||||
|
shadow: oldShadow
|
||||||
|
};
|
||||||
} else {
|
} else {
|
||||||
// Moved to the new parent's next connection.
|
// Moved to the new parent's next connection.
|
||||||
this._blocks[e.newParent].next = e.id;
|
this._blocks[e.newParent].next = e.id;
|
||||||
|
|
|
@ -291,6 +291,67 @@ test('move', function (t) {
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('move into empty', function (t) {
|
||||||
|
var b = new Blocks();
|
||||||
|
b.createBlock({
|
||||||
|
id: 'foo',
|
||||||
|
opcode: 'TEST_BLOCK',
|
||||||
|
next: null,
|
||||||
|
fields: {},
|
||||||
|
inputs: {},
|
||||||
|
topLevel: true
|
||||||
|
});
|
||||||
|
b.createBlock({
|
||||||
|
id: 'bar',
|
||||||
|
opcode: 'TEST_BLOCK',
|
||||||
|
next: null,
|
||||||
|
fields: {},
|
||||||
|
inputs: {},
|
||||||
|
topLevel: true
|
||||||
|
});
|
||||||
|
b.moveBlock({
|
||||||
|
id: 'bar',
|
||||||
|
newInput: 'fooInput',
|
||||||
|
newParent: 'foo'
|
||||||
|
});
|
||||||
|
t.equal(b._blocks['foo'].inputs['fooInput'].block, 'bar');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('move no obscure shadow', function (t) {
|
||||||
|
var b = new Blocks();
|
||||||
|
b.createBlock({
|
||||||
|
id: 'foo',
|
||||||
|
opcode: 'TEST_BLOCK',
|
||||||
|
next: null,
|
||||||
|
fields: {},
|
||||||
|
inputs: {
|
||||||
|
'fooInput': {
|
||||||
|
name: 'fooInput',
|
||||||
|
block: 'x',
|
||||||
|
shadow: 'y'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
topLevel: true
|
||||||
|
});
|
||||||
|
b.createBlock({
|
||||||
|
id: 'bar',
|
||||||
|
opcode: 'TEST_BLOCK',
|
||||||
|
next: null,
|
||||||
|
fields: {},
|
||||||
|
inputs: {},
|
||||||
|
topLevel: true
|
||||||
|
});
|
||||||
|
b.moveBlock({
|
||||||
|
id: 'bar',
|
||||||
|
newInput: 'fooInput',
|
||||||
|
newParent: 'foo'
|
||||||
|
});
|
||||||
|
t.equal(b._blocks['foo'].inputs['fooInput'].block, 'bar');
|
||||||
|
t.equal(b._blocks['foo'].inputs['fooInput'].shadow, 'y');
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
test('change', function (t) {
|
test('change', function (t) {
|
||||||
var b = new Blocks();
|
var b = new Blocks();
|
||||||
b.createBlock({
|
b.createBlock({
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue