mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-07-27 06:29:25 -04:00
Adding support for blocks to be plugged into the input of broadcast blocks. SB2 Import to come.
This commit is contained in:
parent
2817975e18
commit
413d113dda
3 changed files with 67 additions and 6 deletions
src/engine
|
@ -2,6 +2,7 @@ const BlockUtility = require('./block-utility');
|
|||
const log = require('../util/log');
|
||||
const Thread = require('./thread');
|
||||
const {Map} = require('immutable');
|
||||
const cast = require('../util/cast');
|
||||
|
||||
/**
|
||||
* Single BlockUtility instance reused by execute for every pritimive ran.
|
||||
|
@ -211,7 +212,33 @@ const execute = function (sequencer, thread) {
|
|||
currentStackFrame.waitingReporter = null;
|
||||
thread.popStack();
|
||||
}
|
||||
argValues[inputName] = currentStackFrame.reported[inputName];
|
||||
const inputValue = currentStackFrame.reported[inputName];
|
||||
if (inputName === 'BROADCAST_INPUT') {
|
||||
const broadcastInput = inputs[inputName];
|
||||
// Check if something is plugged into the broadcast block, or
|
||||
// if the shadow dropdown menu is being used.
|
||||
// Differentiate between these two cases by giving argValues
|
||||
// a 'BROADCAST_INPUT' field or a 'BROADCAST_OPTION' field
|
||||
// respectively.
|
||||
if (broadcastInput.block === broadcastInput.shadow) {
|
||||
// Shadow dropdown menu is being used.
|
||||
// Get the appropriate information out of it.
|
||||
const shadow = blockContainer.getBlock(broadcastInput.shadow);
|
||||
const broadcastField = shadow.fields.BROADCAST_OPTION;
|
||||
argValues.BROADCAST_OPTION = {
|
||||
id: broadcastField.id,
|
||||
name: broadcastField.value
|
||||
};
|
||||
} else {
|
||||
// Something is plugged into the broadcast input.
|
||||
// Cast it to a string. We don't need an id here.
|
||||
argValues.BROADCAST_INPUT = {
|
||||
name: cast.toString(inputValue)
|
||||
};
|
||||
}
|
||||
} else {
|
||||
argValues[inputName] = inputValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Add any mutation to args (e.g., for procedures).
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue