Skip to content

Allow adding custom shadow argument reporters (SB part) #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions blocks_vertical/vertical_extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,10 @@ Blockly.ScratchBlocks.VerticalExtensions.SCRATCH_EXTENSION = function() {
this.isScratchExtension = true;
};

Blockly.ScratchBlocks.VerticalExtensions.SHADOW_ARGUMENT_REPORTER = function() {
this.shadow_argument_reporter = true;
};

/**
* Register all extensions for scratch-blocks.
* @package
Expand Down Expand Up @@ -284,6 +288,10 @@ Blockly.ScratchBlocks.VerticalExtensions.registerAll = function() {
// Misleading name. Given to blocks that have an extension icon.
Blockly.Extensions.register('scratch_extension',
Blockly.ScratchBlocks.VerticalExtensions.SCRATCH_EXTENSION);

// Blocks that are regenerative shadow reporters
Blockly.Extensions.register('shadow_argument_reporter',
Blockly.ScratchBlocks.VerticalExtensions.SHADOW_ARGUMENT_REPORTER);
};

Blockly.ScratchBlocks.VerticalExtensions.registerAll();
6 changes: 6 additions & 0 deletions core/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,12 @@ Blockly.Block = function(workspace, prototypeName, opt_id) {
}
};

/**
* Whether or not this block is a shadow argument reporter. (used by VM)
* @type {boolean}
*/
Blockly.Block.prototype.shadow_argument_reporter = false;

/**
* Optional text data that round-trips beween blocks and XML.
* Has no effect. May be used by 3rd parties for meta information.
Expand Down
17 changes: 15 additions & 2 deletions core/scratch_blocks_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ Blockly.scratchBlocksUtils.changeObscuredShadowIds = function(block) {
}
};

/**
* Set of blocks that have special behaviour in scratch-blocks where they're
* duplicated when dragged, and they are rendered slightly differently from
* normalshadow blocks.
* @type {string[]}
*/
Blockly.scratchBlocksUtils.shadowArgumentReporters = [
'argument_reporter_boolean',
'argument_reporter_string_number'
];

/**
* Whether a block is both a shadow block and an argument reporter. These
* blocks have special behaviour in scratch-blocks: they're duplicated when
Expand All @@ -83,8 +94,10 @@ Blockly.scratchBlocksUtils.changeObscuredShadowIds = function(block) {
* @package
*/
Blockly.scratchBlocksUtils.isShadowArgumentReporter = function(block) {
return (block.isShadow() && (block.type == 'argument_reporter_boolean' ||
block.type == 'argument_reporter_string_number'));
return (block.isShadow() && (
Blockly.scratchBlocksUtils.shadowArgumentReporters.includes(block.type) ||
block.shadow_argument_reporter
));
};

/**
Expand Down