Adding support for blocks to be plugged into the input of broadcast blocks. SB2 Import to come.

This commit is contained in:
Karishma Chadha 2017-12-08 12:19:11 -05:00
parent 2817975e18
commit 413d113dda
3 changed files with 67 additions and 6 deletions
src/engine

View file

@ -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).