Skip to content
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

Rupato/Fix Blockly mandatory block error #247

Merged
Merged
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
19 changes: 14 additions & 5 deletions src/external/bot-skeleton/scratch/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,20 @@ const getMissingBlocks = (workspace, required_block_types) => {
};

const getDisabledBlocks = required_blocks_check => {
return required_blocks_check.filter(block => {
const hasDisabledChild =
block.childBlocks_ && block.childBlocks_.some(childBlock => childBlock.disabled === true);
return block.disabled === true || hasDisabledChild;
});
const workspace = window.Blockly.derivWorkspace;
const required_block_types = [getSelectedTradeType(workspace), ...config().mandatoryMainBlocks];
const disabled_blocks = Object.fromEntries(
workspace
.getAllBlocks()
.filter(block => required_block_types.includes(block.type))
.map(block => [block.type, block.disabled])
);
const mandatory_blocks = ['before_purchase', 'purchase', 'trade_definition', 'trade_definition_tradeoptions'];
const has_disabled_blocks = mandatory_blocks.some(type => disabled_blocks[type]);

return has_disabled_blocks
? required_blocks_check.filter(block => block.disabled || block.childBlocks_?.some(child => child.disabled))
: [];
};

const throwNewErrorMessage = (error_blocks, key) => {
Expand Down
Loading