Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const json = jsonForMenuBlock('TO', spriteMenu, motionColors, [
[random, '_random_'],
[mouse, '_mouse_']
]);
this.jsonInit(json);
};
ScratchBlocks.Blocks.sensing_of_object_menu.init = function () {
const stage = ScratchBlocks.ScratchMsgs.translate('SENSING_OF_STAGE', 'Stage');
const json = jsonForMenuBlock('OBJECT', spriteMenu, sensingColors, [
[stage, '_stage_']
]);
this.jsonInit(json);
};
ScratchBlocks.Blocks.sensing_of.init = function () {
const blockId = this.id;
// Function that fills in menu for the first input in the sensing block.
// Called every time it opens since it depends on the values in the other block input.
const menuFn = function () {
const stageOptions = [
[ScratchBlocks.Msg.SENSING_OF_BACKDROPNUMBER, 'backdrop #'],
[ScratchBlocks.Msg.SENSING_OF_BACKDROPNAME, 'backdrop name'],
[ScratchBlocks.Msg.SENSING_OF_VOLUME, 'volume']
];
const spriteOptions = [
[ScratchBlocks.Msg.SENSING_OF_XPOSITION, 'x position'],
[ScratchBlocks.Msg.SENSING_OF_YPOSITION, 'y position'],
[ScratchBlocks.Msg.SENSING_OF_DIRECTION, 'direction'],
[ScratchBlocks.Msg.SENSING_OF_COSTUMENUMBER, 'costume #'],
[ScratchBlocks.Msg.SENSING_OF_COSTUMENAME, 'costume name'],
[ScratchBlocks.Msg.SENSING_OF_SIZE, 'size'],
[mouse, '_mouse_']
]);
this.jsonInit(json);
};
ScratchBlocks.Blocks.motion_glideto_menu.init = function () {
const random = ScratchBlocks.ScratchMsgs.translate('MOTION_GLIDETO_RANDOM', 'random position');
const mouse = ScratchBlocks.ScratchMsgs.translate('MOTION_GLIDETO_POINTER', 'mouse-pointer');
const json = jsonForMenuBlock('TO', spriteMenu, motionColors, [
[random, '_random_'],
[mouse, '_mouse_']
]);
this.jsonInit(json);
};
ScratchBlocks.Blocks.sensing_of_object_menu.init = function () {
const stage = ScratchBlocks.ScratchMsgs.translate('SENSING_OF_STAGE', 'Stage');
const json = jsonForMenuBlock('OBJECT', spriteMenu, sensingColors, [
[stage, '_stage_']
]);
this.jsonInit(json);
};
ScratchBlocks.Blocks.sensing_of.init = function () {
const blockId = this.id;
// Function that fills in menu for the first input in the sensing block.
// Called every time it opens since it depends on the values in the other block input.
const menuFn = function () {
const stageOptions = [
[ScratchBlocks.Msg.SENSING_OF_BACKDROPNUMBER, 'backdrop #'],
[ScratchBlocks.Msg.SENSING_OF_BACKDROPNAME, 'backdrop name'],
[ScratchBlocks.Msg.SENSING_OF_VOLUME, 'volume']
if (menu.length === 0) {
return [['', '']]; // Empty menu matches Scratch 2 behavior
}
return menu;
}
const myself = ScratchBlocks.ScratchMsgs.translate('CONTROL_CREATECLONEOF_MYSELF', 'myself');
return [[myself, '_myself_']].concat(spriteMenu());
};
const soundColors = ScratchBlocks.Colours.sounds;
const looksColors = ScratchBlocks.Colours.looks;
const motionColors = ScratchBlocks.Colours.motion;
const sensingColors = ScratchBlocks.Colours.sensing;
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);
};
ScratchBlocks.Blocks.looks_costume.init = function () {
const json = jsonForMenuBlock('COSTUME', costumesMenu, looksColors, []);
this.jsonInit(json);
};
ScratchBlocks.Blocks.looks_backdrops.init = function () {
}
return ScratchBlocks.StatusButtonState.NOT_READY;
};
ScratchBlocks.FieldNote.playNote_ = function (noteNum, extensionId) {
vm.runtime.emit('PLAY_NOTE', noteNum, extensionId);
};
// Use a collator's compare instead of localeCompare which internally
// creates a collator. Using this is a lot faster in browsers that create a
// collator for every localeCompare call.
const collator = new Intl.Collator([], {
sensitivity: 'base',
numeric: true
});
ScratchBlocks.scratchBlocksUtils.compareStrings = function (str1, str2) {
return collator.compare(str1, str2);
};
// Blocks wants to know if 3D CSS transforms are supported. The cross
// section of browsers Scratch supports and browsers that support 3D CSS
// transforms will make the return always true.
//
// Shortcutting to true lets us skip an expensive style recalculation when
// first loading the Scratch editor.
ScratchBlocks.utils.is3dSupported = function () {
return true;
};
return ScratchBlocks;
}
this.jsonInit(json);
};
ScratchBlocks.VerticalFlyout.getCheckboxState = function (blockId) {
const monitoredBlock = vm.runtime.monitorBlocks._blocks[blockId];
return monitoredBlock ? monitoredBlock.isMonitored : false;
};
ScratchBlocks.FlyoutExtensionCategoryHeader.getExtensionState = function (extensionId) {
if (vm.getPeripheralIsConnected(extensionId)) {
return ScratchBlocks.StatusButtonState.READY;
}
return ScratchBlocks.StatusButtonState.NOT_READY;
};
ScratchBlocks.FieldNote.playNote_ = function (noteNum, extensionId) {
vm.runtime.emit('PLAY_NOTE', noteNum, extensionId);
};
// Use a collator's compare instead of localeCompare which internally
// creates a collator. Using this is a lot faster in browsers that create a
// collator for every localeCompare call.
const collator = new Intl.Collator([], {
sensitivity: 'base',
numeric: true
});
ScratchBlocks.scratchBlocksUtils.compareStrings = function (str1, str2) {
return collator.compare(str1, str2);
};
// Blocks wants to know if 3D CSS transforms are supported. The cross
// section of browsers Scratch supports and browsers that support 3D CSS
[edge, '_edge_']
]);
this.jsonInit(json);
};
ScratchBlocks.Blocks.control_create_clone_of_menu.init = function () {
const json = jsonForMenuBlock('CLONE_OPTION', cloneMenu, controlColors, []);
this.jsonInit(json);
};
ScratchBlocks.VerticalFlyout.getCheckboxState = function (blockId) {
const monitoredBlock = vm.runtime.monitorBlocks._blocks[blockId];
return monitoredBlock ? monitoredBlock.isMonitored : false;
};
ScratchBlocks.FlyoutExtensionCategoryHeader.getExtensionState = function (extensionId) {
if (vm.getPeripheralIsConnected(extensionId)) {
return ScratchBlocks.StatusButtonState.READY;
}
return ScratchBlocks.StatusButtonState.NOT_READY;
};
ScratchBlocks.FieldNote.playNote_ = function (noteNum, extensionId) {
vm.runtime.emit('PLAY_NOTE', noteNum, extensionId);
};
// Use a collator's compare instead of localeCompare which internally
// creates a collator. Using this is a lot faster in browsers that create a
// collator for every localeCompare call.
const collator = new Intl.Collator([], {
sensitivity: 'base',
numeric: true
ScratchBlocks.Blocks.sensing_touchingobjectmenu.init = function () {
const mouse = ScratchBlocks.ScratchMsgs.translate('SENSING_TOUCHINGOBJECT_POINTER', 'mouse-pointer');
const edge = ScratchBlocks.ScratchMsgs.translate('SENSING_TOUCHINGOBJECT_EDGE', 'edge');
const json = jsonForMenuBlock('TOUCHINGOBJECTMENU', spriteMenu, sensingColors, [
[mouse, '_mouse_'],
[edge, '_edge_']
]);
this.jsonInit(json);
};
ScratchBlocks.Blocks.control_create_clone_of_menu.init = function () {
const json = jsonForMenuBlock('CLONE_OPTION', cloneMenu, controlColors, []);
this.jsonInit(json);
};
ScratchBlocks.VerticalFlyout.getCheckboxState = function (blockId) {
const monitoredBlock = vm.runtime.monitorBlocks._blocks[blockId];
return monitoredBlock ? monitoredBlock.isMonitored : false;
};
ScratchBlocks.FlyoutExtensionCategoryHeader.getExtensionState = function (extensionId) {
if (vm.getPeripheralIsConnected(extensionId)) {
return ScratchBlocks.StatusButtonState.READY;
}
return ScratchBlocks.StatusButtonState.NOT_READY;
};
ScratchBlocks.FieldNote.playNote_ = function (noteNum, extensionId) {
vm.runtime.emit('PLAY_NOTE', noteNum, extensionId);
};
// Use a collator's compare instead of localeCompare which internally
setBlocks (blocksRef) {
if (!blocksRef) return;
this.blocks = blocksRef;
const workspaceConfig = defaultsDeep({},
CustomProcedures.defaultOptions,
this.props.options
);
// @todo This is a hack to make there be no toolbox.
const oldDefaultToolbox = ScratchBlocks.Blocks.defaultToolbox;
ScratchBlocks.Blocks.defaultToolbox = null;
this.workspace = ScratchBlocks.inject(this.blocks, workspaceConfig);
ScratchBlocks.Blocks.defaultToolbox = oldDefaultToolbox;
// Create the procedure declaration block for editing the mutation.
this.mutationRoot = this.workspace.newBlock('procedures_declaration');
// Make the declaration immovable, undeletable and have no context menu
this.mutationRoot.setMovable(false);
this.mutationRoot.setDeletable(false);
this.mutationRoot.contextMenu = false;
this.workspace.addChangeListener(() => {
this.mutationRoot.onChangeFn();
// Keep the block centered on the workspace
const metrics = this.workspace.getMetrics();
const {x, y} = this.mutationRoot.getRelativeToSurfaceXY();
const menuFn = function () {
const stageOptions = [
[ScratchBlocks.Msg.SENSING_OF_BACKDROPNUMBER, 'backdrop #'],
[ScratchBlocks.Msg.SENSING_OF_BACKDROPNAME, 'backdrop name'],
[ScratchBlocks.Msg.SENSING_OF_VOLUME, 'volume']
];
const spriteOptions = [
[ScratchBlocks.Msg.SENSING_OF_XPOSITION, 'x position'],
[ScratchBlocks.Msg.SENSING_OF_YPOSITION, 'y position'],
[ScratchBlocks.Msg.SENSING_OF_DIRECTION, 'direction'],
[ScratchBlocks.Msg.SENSING_OF_COSTUMENUMBER, 'costume #'],
[ScratchBlocks.Msg.SENSING_OF_COSTUMENAME, 'costume name'],
[ScratchBlocks.Msg.SENSING_OF_SIZE, 'size'],
[ScratchBlocks.Msg.SENSING_OF_VOLUME, 'volume']
];
if (vm.editingTarget) {
let lookupBlocks = vm.editingTarget.blocks;
let sensingOfBlock = lookupBlocks.getBlock(blockId);
// The block doesn't exist, but should be in the flyout. Look there.
if (!sensingOfBlock) {
sensingOfBlock = vm.runtime.flyoutBlocks.getBlock(blockId);
// If we still don't have a block, just return an empty list . This happens during
// scratch blocks construction.
if (!sensingOfBlock) {
return [['', '']];
}
// The block was in the flyout so look up future block info there.
const sort = function (options) {
options.sort(ScratchBlocks.scratchBlocksUtils.compareStrings);
};
// Get all the stage variables (no lists) so we can add them to menu when the stage is selected.