Skip to content

Commit

Permalink
added output block, and now puts solution in block
Browse files Browse the repository at this point in the history
  • Loading branch information
N-J-Martin committed Mar 4, 2024
1 parent a047e3d commit dd74c4c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
14 changes: 14 additions & 0 deletions src/blocks/essence.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,20 @@ export const blocks = Blockly.common.createBlockDefinitionsFromJsonArray([
"tooltip": "",
"helpUrl": ""
},
{
"type": "output",
"message0": "%1",
"args0": [
{
"type": "field_label_serializable",
"name": "SOLUTION",
"text": "test"
}
],
"colour": 0,
"tooltip": "",
"helpUrl": ""
}

])

17 changes: 10 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ const outputDiv = document.getElementById('output');
const blocklyDiv = document.getElementById('blocklyDiv');
const ws = Blockly.inject(blocklyDiv, {toolbox});
const blockOut = Blockly.inject(document.getElementById('blocklyDiv2'), {toolbox});
blockOut.addChangeListener(function addBlock(addNewBlockEvent){
addNewBlockEvent.run(true);
});
new Blockly.Events.BlockCreate(blockOut.newBlock("letting_be_expr"));
//blockOut.addTopBlock(blocks["letting_be_expr"]);
//console.log(blockOut.getTopBlocks());
//blockOut.cleanUp();

//variable category using https://www.npmjs.com/package/@blockly/plugin-typed-variable-modal.
// much of the code below is from the usage instructions

Expand Down Expand Up @@ -185,6 +179,15 @@ async function getSolution() {
solution = await get(currentJobid);
}
solutionText.innerHTML = JSON.stringify(solution, undefined, 2);

if (solution.status == "ok"){
console.log(solution.solution);
let newBlock = blockOut.newBlock("output");
newBlock.setFieldValue(JSON.stringify(solution.solution), 'SOLUTION');
console.log(newBlock.getFieldValue('SOLUTION'));
let addNewBlockEvent = new Blockly.Events.BlockCreate(newBlock);
addNewBlockEvent.run(true)
}
}

// generate essence file from generated code
Expand Down

0 comments on commit dd74c4c

Please sign in to comment.