Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/vm/src/serialization/sb2.js
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,7 @@ const parseBlock = function (sb2block, addBroadcastMsg, getVariableId, extension
inputs: {}, // Inputs to this block and the blocks they point to.
fields: {}, // Fields on this block and their values.
next: null, // Next block.
topLevel: false, // Nested blocks are not script roots.
shadow: false, // No shadow blocks in an SB2 by default.
children: [] // Store any generated children, flattened in `flatten`.
};
Expand Down
26 changes: 26 additions & 0 deletions packages/vm/test/fixtures/obscured-dropdown-shadow.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"projectVersion": 2,
"objName": "Stage",
"variables": [
{
"name": "costume name",
"value": "costume1"
}
],
"lists": [],
"scripts": [
[
80,
60,
[
[
"lookLike:",
["getVar:", "costume name"]
]
]
]
],
"costumes": [],
"sounds": [],
"children": []
}
44 changes: 44 additions & 0 deletions packages/vm/test/unit/engine_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,50 @@ test('create with obscured shadow', t => {
t.end();
});

test('create from state keeps an obscured shadow nested', t => {
const result = adapter({
json: [{
id: 'switch-costume',
type: 'looks_switchcostumeto',
inputs: {
COSTUME: {
block: {
id: 'variable-reporter',
type: 'data_variable',
fields: {
VARIABLE: {
id: 'costume-name',
name: 'costume name'
}
}
},
shadow: {
id: 'costume-shadow',
type: 'looks_costume',
fields: {
COSTUME: 'COSTUME1'
}
}
}
}
}]
});

t.equal(result.length, 3);
t.equal(result.filter(block => block.topLevel).length, 1);
const parent = result.find(block => block.id === 'switch-costume');
const variableReporter = result.find(block => block.id === 'variable-reporter');
const shadow = result.find(block => block.id === 'costume-shadow');
t.equal(parent.topLevel, true);
t.equal(parent.inputs.COSTUME.block, variableReporter.id);
t.equal(parent.inputs.COSTUME.shadow, shadow.id);
t.equal(variableReporter.shadow, false);
t.equal(variableReporter.topLevel, false);
t.equal(shadow.shadow, true);
t.equal(shadow.topLevel, false);
t.end();
});

test('create variable with entity in name', t => {
const result = adapter(events.createvariablewithentity);

Expand Down
28 changes: 28 additions & 0 deletions packages/vm/test/unit/serialization_sb2.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {extractProjectJson} from '../fixtures/readProjectFile.js';
import RenderedTarget from '../../src/sprites/rendered-target';
import Runtime from '../../src/engine/runtime';
import {deserialize} from '../../src/serialization/sb2.js';
import obscuredDropdownShadow from '../fixtures/obscured-dropdown-shadow.json';

test('spec', t => {
t.type(deserialize, 'function');
Expand Down Expand Up @@ -100,3 +101,30 @@ test('Ordering', t => {
t.end();
});
});

test('obscured dropdown shadow keeps the variable reporter as the input block', t => {
const runtime = new Runtime();

return deserialize(obscuredDropdownShadow, runtime).then(({targets}) => {
const blocks = targets[0].blocks;
const switchCostume = blocks.getBlock(blocks.getScripts()[0]);
const input = switchCostume.inputs.COSTUME;
const variableReporter = blocks.getBlock(input.block);
const shadow = blocks.getBlock(input.shadow);

t.equal(switchCostume.opcode, 'looks_switchcostumeto');
t.equal(variableReporter.opcode, 'data_variable');
t.equal(variableReporter.shadow, false);
t.equal(variableReporter.topLevel, false);
t.equal(shadow.opcode, 'looks_costume');
t.equal(shadow.shadow, true);
t.equal(shadow.topLevel, false);
t.ok(input.block !== input.shadow);

const state = blocks.toState();
const stateInput = state[0].inputs.COSTUME;
t.equal(stateInput.block.type, 'data_variable');
t.equal(stateInput.shadow.type, 'looks_costume');
t.end();
});
});
Loading