Skip to content

Commit

Permalink
🐛 Add hasparent restriction
Browse files Browse the repository at this point in the history
  • Loading branch information
Androz2091 committed Apr 18, 2020
1 parent 808a971 commit 2e94959
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/blocks/discord/channels/send_wait_reply_value.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Blockly.JavaScript[blockName] = function(){

registerRestrictions(blockName, [
{
type: "parent",
type: "hasparent",
message: "RES_SEND_WAIT_REPLY_VALUE_PARENT",
types: [
"s4d_send_wait_reply"
Expand Down
16 changes: 15 additions & 1 deletion src/restrictions.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ function validateRestriction(block, blocks, restriction) {
return (blocks.filter(b => restriction.types.includes(b.type) && !b.disabled).length > 0) !== reverse;
case "parent":
return (restriction.types.includes(block.getParent().type)) !== reverse;
case "hasparent":
return (hasParentOfType(block, restriction.types)) !== reverse;
case "notempty":
for (let type of restriction.types){
try {
Expand All @@ -93,14 +95,26 @@ function validateConfiguration(block, restriction) {
case "parent":
case "!parent":
return block.getParent() && !block.getParent().disabled;
case "hasparent":
case "custom":
case "notempty":
return true;
default:
return false;
}
}


function hasParentOfType(block, types){
let hasParent = false;
while(block.getParent()){
if(types.includes(block.getParent().type)){
hasParent = true;
}
block = block.getParent();
}
return hasParent;
}

function getTopLevelParent(block) {
if (!block) return null;
if (!block.getParent()) return block;
Expand Down

0 comments on commit 2e94959

Please sign in to comment.