Skip to content

Commit

Permalink
fix: handle mandatory blocks to have single instance
Browse files Browse the repository at this point in the history
  • Loading branch information
farabi-deriv committed Nov 15, 2024
1 parent 950ba28 commit 612ce0c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/bot-skeleton/src/scratch/hooks/workspace_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ Blockly.WorkspaceSvg.prototype.addBlockNode = function (block_node) {
const block = Blockly.Xml.domToBlock(block_node, flyout.getFlyout().targetWorkspace);
const top_blocks = this.getTopBlocks(true);

if (config.single_instance_blocks.includes(block.type)) {
this.getAllBlocks().forEach(ws_block => {
if (ws_block.type === block.type && ws_block.id !== block.id) {
ws_block.dispose();
}
});
}

if (top_blocks.length) {
const last_block = top_blocks[top_blocks.length - 1];
const last_block_xy = last_block.getRelativeToSurfaceXY();
Expand Down

0 comments on commit 612ce0c

Please sign in to comment.