Skip to content
Snippets Groups Projects
Commit 312fafab authored by Eric Rosenbaum's avatar Eric Rosenbaum
Browse files

Dynamic menus for costumes and backdrops

parent f2cad9c1
Branches
Tags
No related merge requests found
const ScratchBlocks = require('scratch-blocks');
module.exports = function (vm) {
const jsonForMenuBlock = function (name, menuOptionsFn, colors) {
return {
message0: '%1',
args0: [
{
type: 'field_dropdown',
name: name,
options: menuOptionsFn
}
],
inputsInline: true,
output: 'String',
colour: colors.secondary,
colourSecondary: colors.secondary,
colourTertiary: colors.tertiary,
outputShape: ScratchBlocks.OUTPUT_SHAPE_ROUND
};
};
const soundsMenu = function () {
return vm.editingTarget.sprite.sounds.map(sound => [sound.name, sound.name]);
};
const costumesMenu = function () {
return vm.editingTarget.sprite.costumes.map(costume => [costume.name, costume.name]);
};
const backdropsMenu = function () {
return vm.runtime.targets[0].sprite.costumes.map(costume => [costume.name, costume.name]);
};
const soundColors = ScratchBlocks.Colours.sounds;
const looksColors = ScratchBlocks.Colours.looks;
ScratchBlocks.Blocks.sound_sounds_menu.init = function () {
this.jsonInit(
{
message0: '%1',
args0: [
{
type: 'field_dropdown',
name: 'SOUND_MENU',
options: function () {
const menu = vm.editingTarget.sprite.sounds.map(sound => [sound.name, sound.name]);
return menu;
}
}
],
inputsInline: true,
output: 'String',
colour: ScratchBlocks.Colours.sounds.secondary,
colourSecondary: ScratchBlocks.Colours.sounds.secondary,
colourTertiary: ScratchBlocks.Colours.sounds.tertiary,
outputShape: ScratchBlocks.OUTPUT_SHAPE_ROUND
});
const json = jsonForMenuBlock('SOUND_MENU', soundsMenu, soundColors);
this.jsonInit(json);
};
ScratchBlocks.Blocks.looks_costume.init = function () {
const json = jsonForMenuBlock('COSTUME', costumesMenu, looksColors);
this.jsonInit(json);
};
ScratchBlocks.Blocks.looks_backdrops.init = function () {
const json = jsonForMenuBlock('BACKDROP', backdropsMenu, looksColors);
this.jsonInit(json);
};
return ScratchBlocks;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment