From 44da136962f8c5ce4af35b814c4179f91c01a6f7 Mon Sep 17 00:00:00 2001 From: Silver Kuusik Date: Wed, 15 Aug 2018 20:07:26 +0200 Subject: [PATCH] fix resuming blocks and code --- assets/js/blockly.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/assets/js/blockly.js b/assets/js/blockly.js index 8b57a99..c23d024 100644 --- a/assets/js/blockly.js +++ b/assets/js/blockly.js @@ -186,6 +186,15 @@ window.addEventListener('load', function() { var xml = Blockly.Xml.textToDom(getLocalStorageItem('sumorobot.blockly')); // Resume the blocks Blockly.Xml.domToWorkspace(xml, workspace); + // For the code processor + sumorobot.setBlocklyCode(Blockly.Python.workspaceToCode(workspace)); + // Show the code in the ace editor, filter out block IDs + readOnlyCodingEditor.setValue('\n' + sumorobot.getBlocklyCode().replace(/;;.{20}/g, '')); + readOnlyCodingEditor.clearSelection(); + // Disable the if condition block in the toolbox if it's already used + if (/if/.test(sumorobot.getBlocklyCode())) { + workspace.updateToolbox(document.getElementById('toolbox_no_if')); + } // On Blockly code change function onCodeChanged(event) {