From a047e3da941620f913992a230596183ae6b3ba5c Mon Sep 17 00:00:00 2001 From: Nadine Martin Date: Mon, 4 Mar 2024 14:56:44 +0000 Subject: [PATCH 1/7] got output block stage set up. event creates block dynamically --- src/index.css | 6 ++++++ src/index.html | 1 + src/index.js | 9 ++++++++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/index.css b/src/index.css index 4a05dbf..dfc55f4 100644 --- a/src/index.css +++ b/src/index.css @@ -20,6 +20,12 @@ pre, code { min-width: 600px; } +#blocklyDiv2 { + flex-basis: 100%; + height: 100%; + min-width: 600px; +} + #outputPane { display: flex; flex-direction: column; diff --git a/src/index.html b/src/index.html index fa24967..f84003f 100644 --- a/src/index.html +++ b/src/index.html @@ -11,6 +11,7 @@
+
diff --git a/src/index.js b/src/index.js index 0ee963d..59de7b6 100644 --- a/src/index.js +++ b/src/index.js @@ -25,7 +25,14 @@ const codeDiv = document.getElementById('generatedCode').firstChild; 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 From dd74c4ca9622a3a5756f5de807c4d5781a135b58 Mon Sep 17 00:00:00 2001 From: Nadine Martin Date: Mon, 4 Mar 2024 15:47:28 +0000 Subject: [PATCH 2/7] added output block, and now puts solution in block --- src/blocks/essence.js | 14 ++++++++++++++ src/index.js | 17 ++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/blocks/essence.js b/src/blocks/essence.js index 92d98e7..b462cdc 100644 --- a/src/blocks/essence.js +++ b/src/blocks/essence.js @@ -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": "" +} ]) diff --git a/src/index.js b/src/index.js index 59de7b6..f1e9ff7 100644 --- a/src/index.js +++ b/src/index.js @@ -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 @@ -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 From 61b1f3825685e295ab6848ccd1edc2cae97d18db Mon Sep 17 00:00:00 2001 From: Nadine Martin Date: Tue, 5 Mar 2024 15:38:24 +0000 Subject: [PATCH 3/7] cleaned up block output --- src/index.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/index.js b/src/index.js index f1e9ff7..53e1e8d 100644 --- a/src/index.js +++ b/src/index.js @@ -25,7 +25,7 @@ const codeDiv = document.getElementById('generatedCode').firstChild; const outputDiv = document.getElementById('output'); const blocklyDiv = document.getElementById('blocklyDiv'); const ws = Blockly.inject(blocklyDiv, {toolbox}); -const blockOut = Blockly.inject(document.getElementById('blocklyDiv2'), {toolbox}); +const blockOut = Blockly.inject(document.getElementById('blocklyDiv2'), {}); //variable category using https://www.npmjs.com/package/@blockly/plugin-typed-variable-modal. // much of the code below is from the usage instructions @@ -181,12 +181,15 @@ async function getSolution() { 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) + for (let sol of solution.solution){ + for (let v in sol){ + let newBlock = blockOut.newBlock("output"); + newBlock.setFieldValue(v + " = " + sol[v], 'SOLUTION'); + let addNewBlockEvent = new Blockly.Events.BlockCreate(newBlock); + addNewBlockEvent.run(true) + } + } + } } @@ -198,7 +201,6 @@ function downloadEssenceCode() { let filename = prompt("Please enter essence file name", "test"); filename = filename + ".essence" let code = essenceGenerator.workspaceToCode(ws); - console.log(code) let file = new File([code], filename); let url = URL.createObjectURL(file); const a = document.createElement("a"); From 1682789ced2690ad3db1d71cd86ec6aacc38608e Mon Sep 17 00:00:00 2001 From: Nadine Martin Date: Thu, 7 Mar 2024 16:36:56 +0000 Subject: [PATCH 4/7] now outputs variable block --- src/index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 53e1e8d..1ea9ca8 100644 --- a/src/index.js +++ b/src/index.js @@ -183,8 +183,10 @@ async function getSolution() { if (solution.status == "ok"){ for (let sol of solution.solution){ for (let v in sol){ - let newBlock = blockOut.newBlock("output"); - newBlock.setFieldValue(v + " = " + sol[v], 'SOLUTION'); + blockOut.createVariable(v); + let newBlock = blockOut.newBlock('variables_get_dynamic'); + newBlock.setFieldValue(blockOut.getVariable(v).getId(), 'VAR') + //newBlock.setFieldValue(v + " = " + sol[v], 'SOLUTION'); let addNewBlockEvent = new Blockly.Events.BlockCreate(newBlock); addNewBlockEvent.run(true) } From 4a513454f62a1fc020c1305913e84672f00b79ba Mon Sep 17 00:00:00 2001 From: Nadine Martin Date: Thu, 7 Mar 2024 16:39:54 +0000 Subject: [PATCH 5/7] now uses set block --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 1ea9ca8..54a6845 100644 --- a/src/index.js +++ b/src/index.js @@ -184,7 +184,7 @@ async function getSolution() { for (let sol of solution.solution){ for (let v in sol){ blockOut.createVariable(v); - let newBlock = blockOut.newBlock('variables_get_dynamic'); + let newBlock = blockOut.newBlock('variables_set'); newBlock.setFieldValue(blockOut.getVariable(v).getId(), 'VAR') //newBlock.setFieldValue(v + " = " + sol[v], 'SOLUTION'); let addNewBlockEvent = new Blockly.Events.BlockCreate(newBlock); From a0e90b24135831da7c1b40b19b4e5b422f34bd86 Mon Sep 17 00:00:00 2001 From: Nadine Martin Date: Fri, 8 Mar 2024 14:04:07 +0000 Subject: [PATCH 6/7] outputs variable set block and value block connected --- src/index.js | 33 ++++++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/src/index.js b/src/index.js index 54a6845..da0ecd2 100644 --- a/src/index.js +++ b/src/index.js @@ -15,6 +15,7 @@ import {essenceGenerator} from './generators/essence'; import {save, load} from './serialization'; import {toolbox} from './toolbox'; import './index.css'; +import { variables } from 'blockly/blocks'; // Register the blocks and generator with Blockly Blockly.common.defineBlocks(blocks); @@ -184,11 +185,33 @@ async function getSolution() { for (let sol of solution.solution){ for (let v in sol){ blockOut.createVariable(v); - let newBlock = blockOut.newBlock('variables_set'); - newBlock.setFieldValue(blockOut.getVariable(v).getId(), 'VAR') - //newBlock.setFieldValue(v + " = " + sol[v], 'SOLUTION'); - let addNewBlockEvent = new Blockly.Events.BlockCreate(newBlock); - addNewBlockEvent.run(true) + let varBlock = blockOut.newBlock('variables_set'); + varBlock.setFieldValue(blockOut.getVariable(v).getId(), 'VAR'); + console.log(typeof(sol[v])); + let valueBlock; + switch (typeof(sol[v])){ + case("bigint"): + case("number"): { + valueBlock = blockOut.newBlock('math_number'); + valueBlock.setFieldValue(sol[v], "NUM"); + break; + } + case("object"): { + console.log("enum"); + valueBlock = null; + break; + } + default:{ + console.log("idk"); + valueBlock = null; + break; + } + + }; + varBlock.getInput("VALUE").connection.connect(valueBlock.outputConnection); + let addVarBlock = new Blockly.Events.BlockCreate(varBlock); + addVarBlock.run(true); + } } From 2d9ce052d6f1e8ad486fc6ded8c812424b45acaa Mon Sep 17 00:00:00 2001 From: Nadine Martin Date: Sat, 9 Mar 2024 12:17:26 +0000 Subject: [PATCH 7/7] got out working for values in int and enum domain --- src/index.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/index.js b/src/index.js index da0ecd2..1c736c2 100644 --- a/src/index.js +++ b/src/index.js @@ -187,7 +187,7 @@ async function getSolution() { blockOut.createVariable(v); let varBlock = blockOut.newBlock('variables_set'); varBlock.setFieldValue(blockOut.getVariable(v).getId(), 'VAR'); - console.log(typeof(sol[v])); + //console.log(typeof(sol[v])); let valueBlock; switch (typeof(sol[v])){ case("bigint"): @@ -196,9 +196,10 @@ async function getSolution() { valueBlock.setFieldValue(sol[v], "NUM"); break; } - case("object"): { + case("string"): { console.log("enum"); - valueBlock = null; + valueBlock = blockOut.newBlock('text'); + valueBlock.setFieldValue(sol[v], "TEXT"); break; } default:{