Merge pull request #1970 from kchadha/dynamic-backdrop-list
Implement when backdrop switches to menu.
This commit is contained in:
1 file changed
+36
@@ -28,6 +28,25 @@ export default function (vm) {
|
||||
};
|
||||
};
|
||||
|
||||
const jsonForHatBlockMenu = function (hatName, name, menuOptionsFn, colors, start) {
|
||||
return {
|
||||
message0: hatName,
|
||||
args0: [
|
||||
{
|
||||
type: 'field_dropdown',
|
||||
name: name,
|
||||
options: function () {
|
||||
return start.concat(menuOptionsFn());
|
||||
}
|
||||
}
|
||||
],
|
||||
colour: colors.primary,
|
||||
colourSecondary: colors.secondary,
|
||||
colourTertiary: colors.tertiary,
|
||||
extensions: ['shape_hat']
|
||||
};
|
||||
};
|
||||
|
||||
const soundsMenu = function () {
|
||||
if (vm.editingTarget && vm.editingTarget.sprite.sounds.length > 0) {
|
||||
return vm.editingTarget.sprite.sounds.map(sound => [sound.name, sound.name]);
|
||||
@@ -50,6 +69,14 @@ export default function (vm) {
|
||||
return [['', '']];
|
||||
};
|
||||
|
||||
const backdropNamesMenu = function () {
|
||||
const stage = vm.runtime.getTargetForStage();
|
||||
if (stage && stage.getCostumes().length > 0) {
|
||||
return stage.getCostumes().map(costume => [costume.name, costume.name]);
|
||||
}
|
||||
return [['', '']];
|
||||
};
|
||||
|
||||
const spriteMenu = function () {
|
||||
const sprites = [];
|
||||
for (const targetId in vm.runtime.targets) {
|
||||
@@ -87,6 +114,8 @@ export default function (vm) {
|
||||
|
||||
const controlColors = ScratchBlocks.Colours.control;
|
||||
|
||||
const eventColors = ScratchBlocks.Colours.event;
|
||||
|
||||
ScratchBlocks.Blocks.sound_sounds_menu.init = function () {
|
||||
const json = jsonForMenuBlock('SOUND_MENU', soundsMenu, soundColors, []);
|
||||
this.jsonInit(json);
|
||||
@@ -102,6 +131,13 @@ export default function (vm) {
|
||||
this.jsonInit(json);
|
||||
};
|
||||
|
||||
ScratchBlocks.Blocks.event_whenbackdropswitchesto.init = function () {
|
||||
const json = jsonForHatBlockMenu(
|
||||
ScratchBlocks.Msg.EVENT_WHENBACKDROPSWITCHESTO,
|
||||
'BACKDROP', backdropNamesMenu, eventColors, []);
|
||||
this.jsonInit(json);
|
||||
};
|
||||
|
||||
ScratchBlocks.Blocks.motion_pointtowards_menu.init = function () {
|
||||
const json = jsonForMenuBlock('TOWARDS', spriteMenu, motionColors, [
|
||||
['mouse-pointer', '_mouse_']
|
||||
|
||||
Reference in new issue
Block a user