Skip to content

Commit a2c6b8f

Browse files
committed
fix shadows being a bit goofy
1 parent 16abf67 commit a2c6b8f

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/util/new-block-ids.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,8 @@ module.exports = blocks => {
2929
if (blocks[i].next) {
3030
blocks[i].next = oldToNew[blocks[i].next];
3131
}
32+
if (blocks[i].obscuredHeadShadows) {
33+
blocks[i].obscuredHeadShadows = blocks[i].obscuredHeadShadows.map(id => (id ? oldToNew[id] : id));
34+
}
3235
}
3336
};

test/unit/util_new-block-ids.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,20 @@ test('next reference is maintained for previous block', t => {
6161
t.equal(newBlocks[0].next, newBlocks[3].id);
6262
t.end();
6363
});
64+
65+
// Collapsed variadic operators (extendable +, join, and/or) carry an obscuredHeadShadows array of
66+
// shadow block ids that expandOperators restores on save. It must be remapped like any other id
67+
// reference, or duplicating/sharing the sprite leaves it pointing at ids that no longer exist and
68+
// the typed values hidden under dropped reporters are lost on the next save.
69+
test('obscuredHeadShadows ids are remapped', t => {
70+
const blocks = [
71+
{id: 'op', opcode: 'operator_join', parent: null, next: null,
72+
inputs: {STRING1: {name: 'STRING1', block: 'shadow', shadow: 'shadow'}},
73+
obscuredHeadShadows: ['shadow', null]},
74+
{id: 'shadow', opcode: 'text', parent: 'op', next: null, inputs: {}}
75+
];
76+
newBlockIds(blocks);
77+
t.equal(blocks[0].obscuredHeadShadows[0], blocks[1].id, 'shadow id remapped to new id');
78+
t.equal(blocks[0].obscuredHeadShadows[1], null, 'null entries preserved');
79+
t.end();
80+
});

0 commit comments

Comments
 (0)