Skip to content
Snippets Groups Projects
Commit 9c377e28 authored by picklesrus's avatar picklesrus
Browse files

Add variables to the sensing block menu based on the value in the garget menu.

parent 6ee270cd
No related branches found
No related tags found
No related merge requests found
...@@ -245,18 +245,25 @@ export default function (vm) { ...@@ -245,18 +245,25 @@ export default function (vm) {
// The block was in the flyout so look up future block info there. // The block was in the flyout so look up future block info there.
lookupBlocks = vm.runtime.flyoutBlocks; lookupBlocks = vm.runtime.flyoutBlocks;
} }
// Get all the stage variables (no lists) so we can add them to menu when the stage is selected.
const stageVariableOptions = vm.runtime.getTargetForStage().getAllVariableNamesInScopeByType('');
const stageVariableMenuItems = stageVariableOptions.map(variable => [variable, variable]);
if (sensingOfBlock.inputs.OBJECT.shadow !== sensingOfBlock.inputs.OBJECT.block) { if (sensingOfBlock.inputs.OBJECT.shadow !== sensingOfBlock.inputs.OBJECT.block) {
// There's a block dropped on top of the menu. It'd be nice to evaluate it and // There's a block dropped on top of the menu. It'd be nice to evaluate it and
// return the correct list, but that is tricky. Scratch2 just returns stage options // return the correct list, but that is tricky. Scratch2 just returns stage options
// so just do that here too. // so just do that here too.
return stageOptions; return stageOptions.concat(stageVariableMenuItems);
} }
const menuBlock = lookupBlocks.getBlock(sensingOfBlock.inputs.OBJECT.shadow); const menuBlock = lookupBlocks.getBlock(sensingOfBlock.inputs.OBJECT.shadow);
const selectedItem = menuBlock.fields.OBJECT.value; const selectedItem = menuBlock.fields.OBJECT.value;
if (selectedItem === '_stage_') { if (selectedItem === '_stage_') {
return stageOptions; return stageOptions.concat(stageVariableMenuItems);
} }
return spriteOptions; // Get all the local variables (no lists) and add them to the menu.
const spriteVariableOptions =
vm.runtime.getSpriteTargetByName(selectedItem).getAllVariableNamesInScopeByType('', true);
const spriteVariableMenuItems = spriteVariableOptions.map(variable => [variable, variable]);
return spriteOptions.concat(spriteVariableMenuItems);
} }
return [['', '']]; return [['', '']];
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment