Hi all,
For a somewhat extreme Blockly project am trying to add a
connection checker for statements. The goal is to have the
container_block to check if the type of the
statement_block will satisfy some constraint and if so to allow the connection. The code works fine without the connection checker. Adding a connection checker works fine in the sense that the UI allows the container block to exclusively connect with a statement_block with a type that matches the container.
Great. Only problem is the generator. The container block generator returns null for getInputTargetBlock once the check field is added to the block description (see
red addition bellow)).
(Clarifying: the new connector checker is less restrictive than the default connector checker, maybe the connector checker is not called when generating code???)
Example #1. (code)
Generator works fine, but no type checking used.
container_block
{
"type": "container_block",
...
"args0": [
{
"type": "input_statement",
"name": "content"
}
],
...
statement_block
{
"type": "statement_block",
...
"previousStatement": 'statement_block_connector',
"nextStatement": 'statement_block_connector',
...
}
statement_block generator
....
let currentBlock = this.getInputTargetBlock('content');
console.log("Generator message BLOCK: ", currentBlock);
...
Checker
export class NewBlockChecker extends Blockly.ConnectionChecker {
....
/**
* @override
*/
doTypeChecks(a: any, b: any) {
const checkArray0 = a.getCheck();
const checkArray1 = b.getCheck();
if ((checkArray0[0] === 'STATEMENT_CONNECTOR") &&
(checkArray1[0] !== "statement_block_connector"))
return false;
if ((checkArray1[0] === 'STATEMENT_CONNECTOR") &&
(checkArray0[0] !== "statement_block_connector"))
return false;
return true;
}
Example #1 (result)
Generator message BLOCK: Blockly.Block {id: 'm%%]x5.Nv|^|X10R9GRa',...
Example #2. (code)
Type checking works fine, but the generator does not.
Only difference is the lines added in red, rest code is kept the same
revised container_block
{
"type": "container_block",
...
"args0": [
{
"type": "input_statement",
"name": "content",
"check": [
"STATEMENT_CONNECTOR"
]
}
],
...
The checker works correctly yet:
Generator message BLOCK: null
Cheers,
Oded