forked from marva/sumorobot-web
fix resuming blocks & code
This commit is contained in:
parent
1a8bbaf087
commit
342d07ee58
@ -186,13 +186,6 @@ window.addEventListener('load', function() {
|
|||||||
var xml = Blockly.Xml.textToDom(getLocalStorageItem('sumorobot.blockly'));
|
var xml = Blockly.Xml.textToDom(getLocalStorageItem('sumorobot.blockly'));
|
||||||
// Resume the blocks
|
// Resume the blocks
|
||||||
Blockly.Xml.domToWorkspace(xml, workspace);
|
Blockly.Xml.domToWorkspace(xml, workspace);
|
||||||
// Show the code in the ace editor, filter out block IDs
|
|
||||||
readOnlyCodingEditor.setValue('\n' + Blockly.Python.workspaceToCode(workspace).replace(/;;.{20}/g, ''));
|
|
||||||
readOnlyCodingEditor.clearSelection();
|
|
||||||
// Disable the if condition block in the toolbox if it's already used
|
|
||||||
if (/controls_if/.test(xml)) {
|
|
||||||
workspace.updateToolbox(document.getElementById('toolbox_no_if'));
|
|
||||||
}
|
|
||||||
|
|
||||||
// On Blockly code change
|
// On Blockly code change
|
||||||
function onCodeChanged(event) {
|
function onCodeChanged(event) {
|
||||||
@ -221,11 +214,8 @@ window.addEventListener('load', function() {
|
|||||||
// Only process change and move commands
|
// Only process change and move commands
|
||||||
if (event.type != Blockly.Events.CHANGE && event.type != Blockly.Events.MOVE) return;
|
if (event.type != Blockly.Events.CHANGE && event.type != Blockly.Events.MOVE) return;
|
||||||
|
|
||||||
// Generate code from the used blocks
|
|
||||||
sumorobot.setBlocklyCode(Blockly.Python.workspaceToCode(workspace));
|
|
||||||
|
|
||||||
// Show the code in the ace editor, filter out block IDs
|
// Show the code in the ace editor, filter out block IDs
|
||||||
readOnlyCodingEditor.setValue('\n' + sumorobot.getBlocklyCode().replace(/;;.{20}/g, ''));
|
readOnlyCodingEditor.setValue('\n' + Blockly.Python.workspaceToCode(workspace).replace(/;;.{20}/g, ''));
|
||||||
readOnlyCodingEditor.clearSelection();
|
readOnlyCodingEditor.clearSelection();
|
||||||
|
|
||||||
// Save the code to the local storage
|
// Save the code to the local storage
|
||||||
|
Loading…
Reference in New Issue
Block a user