From 11517e221b6111ace4354294b2c79db9c8b5f728 Mon Sep 17 00:00:00 2001 From: Karishma Chadha Date: Fri, 4 May 2018 10:45:58 -0400 Subject: [PATCH] Implement when backdrop switches to menu. --- src/lib/blocks.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/lib/blocks.js b/src/lib/blocks.js index fb54eae3b..1c3e8176c 100644 --- a/src/lib/blocks.js +++ b/src/lib/blocks.js @@ -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_']