mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-06-04 01:24:58 -04:00
Handle unknown opcode in input
This commit is contained in:
parent
5cf10b1af1
commit
26c928d10b
1 changed files with 24 additions and 20 deletions
|
@ -843,6 +843,7 @@ const parseBlock = function (sb2block, addBroadcastMsg, getVariableId, extension
|
|||
for (let i = 0; i < blockMetadata.argMap.length; i++) {
|
||||
const expectedArg = blockMetadata.argMap[i];
|
||||
const providedArg = sb2block[i + 1]; // (i = 0 is opcode)
|
||||
|
||||
// Whether the input is obscuring a shadow.
|
||||
let shadowObscured = false;
|
||||
// Positional argument is an input.
|
||||
|
@ -866,32 +867,35 @@ const parseBlock = function (sb2block, addBroadcastMsg, getVariableId, extension
|
|||
// Single block occupies the input.
|
||||
const parsedBlockDesc = parseBlock(providedArg, addBroadcastMsg, getVariableId, extensions,
|
||||
parseState, comments, commentIndex);
|
||||
innerBlocks = [parsedBlockDesc[0]];
|
||||
innerBlocks = parsedBlockDesc[0] ? [parsedBlockDesc[0]] : [];
|
||||
// Update commentIndex
|
||||
commentIndex = parsedBlockDesc[1];
|
||||
}
|
||||
parseState.expectedArg = parentExpectedArg;
|
||||
// Check if innerBlocks is an empty list.
|
||||
// This indicates that all the inner blocks from the sb2 have
|
||||
// unknown opcodes and have been skipped.
|
||||
if (innerBlocks.length === 0) continue;
|
||||
let previousBlock = null;
|
||||
for (let j = 0; j < innerBlocks.length; j++) {
|
||||
if (j === 0) {
|
||||
innerBlocks[j].parent = activeBlock.id;
|
||||
} else {
|
||||
innerBlocks[j].parent = previousBlock;
|
||||
}
|
||||
previousBlock = innerBlocks[j].id;
|
||||
}
|
||||
|
||||
// Obscures any shadow.
|
||||
shadowObscured = true;
|
||||
activeBlock.inputs[expectedArg.inputName].block = (
|
||||
innerBlocks[0].id
|
||||
);
|
||||
activeBlock.children = (
|
||||
activeBlock.children.concat(innerBlocks)
|
||||
);
|
||||
|
||||
// Check if innerBlocks is not an empty list.
|
||||
// An empty list indicates that all the inner blocks from the sb2 have
|
||||
// unknown opcodes and have been skipped.
|
||||
if (innerBlocks.length > 0) {
|
||||
let previousBlock = null;
|
||||
for (let j = 0; j < innerBlocks.length; j++) {
|
||||
if (j === 0) {
|
||||
innerBlocks[j].parent = activeBlock.id;
|
||||
} else {
|
||||
innerBlocks[j].parent = previousBlock;
|
||||
}
|
||||
previousBlock = innerBlocks[j].id;
|
||||
}
|
||||
activeBlock.inputs[expectedArg.inputName].block = (
|
||||
innerBlocks[0].id
|
||||
);
|
||||
activeBlock.children = (
|
||||
activeBlock.children.concat(innerBlocks)
|
||||
);
|
||||
}
|
||||
}
|
||||
// Generate a shadow block to occupy the input.
|
||||
if (!expectedArg.inputOp) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue