app/assets/htmls/gs-element-blockly.html in gobstones-blockly-0.11.1 vs app/assets/htmls/gs-element-blockly.html in gobstones-blockly-0.11.2

- old
+ new

@@ -3571,18 +3571,42 @@ this.workspace.options.parentWorkspace.options.comments)) && comment) { this.setCommentText(comment); } this.setCommentText(null); - this.setColour(Blockly.Blocks.procedures.HUE); + this.setColour(( + Blockly.CUSTOM_COLORS && ( + Blockly.CUSTOM_COLORS[this.type] || + Blockly.CUSTOM_COLORS[withReturn ? "function" : "procedure"] + )) || Blockly.Blocks.procedures.HUE); this.setTooltip(tooltip); this.setHelpUrl(helpUrl); this.arguments_ = []; this.setStatements_(withStatements); this.statementConnection_ = null; // if (!withParametersMutator) this.updateParams_(); + + // [!] adding create call button + // TODO: Hacer esto + // var xmlMutation = goog.dom.createDom('mutation'); + // xmlMutation.setAttribute('name', name); + // for (var i = 0; i < self.arguments_.length; i++) { + // var xmlArg = goog.dom.createDom('arg'); + // xmlArg.setAttribute('name', self.arguments_[i]); + // xmlMutation.appendChild(xmlArg); + // } + // var xmlBlock = goog.dom.createDom('block', null, xmlMutation); + // xmlBlock.setAttribute('type', self.callType_); + // var createCallButton = new Blockly.FieldImage( + // WAND, + // 16, + // 16, + // "", + // Blockly.ContextMenu.callbackFactory(self, xmlBlock) + // ); + // input.appendField(createCallButton); }; }; // ----------------------- // [!] Custom context menu @@ -3646,26 +3670,48 @@ options.pop(); // [!] Remove help }; }; - // ---------------------------------------------------- - // [!] Setting custom statement type to procedure calls - // ---------------------------------------------------- + // --------------------------------------------------------------------- + // [!] Setting custom statement type to procedure calls and adding color + // --------------------------------------------------------------------- var oldProceduresCallNoReturnInit = Blockly.Blocks['procedures_callnoreturn'].init; Blockly.Blocks['procedures_callnoreturn'].init = function() { oldProceduresCallNoReturnInit.call(this); + if (customStatementType) { this.jsonInit({ type: customStatementType, previousStatement: customStatementType, nextStatement: customStatementType }); } + + this.setColour(( + Blockly.CUSTOM_COLORS && ( + Blockly.CUSTOM_COLORS[this.type] || + Blockly.CUSTOM_COLORS.procedure_call + )) || Blockly.Blocks.procedures.HUE); }; + // ---------------------------------- + // [!] Adding color to function calls + // ---------------------------------- + + var oldProceduresCallReturnInit = Blockly.Blocks['procedures_callreturn'].init; + Blockly.Blocks['procedures_callreturn'].init = function() { + oldProceduresCallReturnInit.call(this); + + this.setColour(( + Blockly.CUSTOM_COLORS && ( + Blockly.CUSTOM_COLORS[this.type] || // TODO: Usar this.type en todos los cosos de colors + Blockly.CUSTOM_COLORS.function_call + )) || Blockly.Blocks.procedures.HUE); + }; + // ------------------------------- // [!] Patching default procedures // ------------------------------- var makeUpdateParams = function() { return function() { }; }; @@ -3983,14 +4029,15 @@ } </script> <script>initProcedsBlockly("Statement");</script> <script>var MINUS = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAQAAAAEACAQAAAD2e2DtAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QA/4ePzL8AAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAHdElNRQfhDAUCCi+xWH4JAAABcUlEQVR42u3c7ZGCMBSG0etuYcTKls7AyrSEVWd4+bjnUECMeSbhD6kCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIBzu4XHm2rUvPekD2yutR57/4itTLXU0/Pvs9SUW5TcDrDUyE3r9Na6ZwZKBWD5PxVKIBPAVGtknGsZibeBTADPyCjXE1idn8A0/gJjXFPgn0sEwIEljgAHwPc2Xx87QHMCaE4AzQmgOQE0J4DmBNCcAJoTQHMCaE4AzQmgOQE0J4DmBNCcAJoTQHMCaE4AzQmgOQE0J4DmBNDcb2SUsfc0T2re/utAO0BzPg49sot8HOoI+M5IDJIJ4OF+gI+F7gpyRcwxxa6Iyb0E3mvYB96y1kgtv2vijubS18QBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMAWXq7xrTQhKAi3AAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE3LTEyLTA1VDAyOjEwOjQ3LTA1OjAwdZLI/gAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxNy0xMi0wNVQwMjoxMDo0Ny0wNTowMATPcEIAAAAASUVORK5CYII="; +var HAND = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QAAKqNIzIAAAAJcEhZcwAACxMAAAsTAQCanBgAAAAHdElNRQfiBAUBKBeKSgeBAAABTElEQVQoz22QzyvDcRjHX5/vvrMyStI2uZgftdVCSpJCyW1y00oUF+Xg4OIkx5VyUyJOsgv/gnJw4YCSSFMyB5pGbLJ99/k8LltreB2f9+v50eOigoc5FvGTJF8pugCwaKaNaE98uf9zMBXwjtNpbvmuaH2B0+HXuuyMEbOlQ4U1M5ZVcYbowg02YfZW5cnE9JIROdI7jsiOacoMPLZdEYPR1ouQkxCRG+feESlIXkQOzLR+NhvCpc3UbPcHAoRsADcAQ0Twq0ZosQgEVY0SqvGpkAUCxkIUYRP4bZRRNi9pvaD+TwXyFseHuYzy/Kt8CWfQ5Ems6C/5y7uZyDEH0Nt8vq0dUx0XzaapPyIIoIi23+47+SrlTvrTjLhKy2wmO95OqiacS+QBH9gAFDlOZnYbrimWOixSZCwUlK+vZd7bXiPldyi0yqX1OtkfCBS/9XAtDKAAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTgtMDQtMDVUMDQ6NDQ6NDItMDM6MDD+uUN1AAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE4LTA0LTA1VDA0OjQwOjIzLTAzOjAw5hdZgAAAAABJRU5ErkJggg=="; /* global Blockly */ -Blockly.GOBSTONES_COLORS = { +Blockly.CUSTOM_COLORS = { globalHsvSaturation: Blockly.HSV_SATURATION, globalHsvValue: Blockly.HSV_VALUE, primitiveCommand: "#8DA65B", assignation: "#5B68A6", controlStructure: "#A6A65B", @@ -3998,10 +4045,17 @@ expression: "#745BA6", program: "#74A65B", interactiveProgram: "#A6805B", interactiveBinding: "#A6995B", procedure: "#995BA6", + function: "#774A77", + primitiveProcedure: "#CACACA", + primitiveFunction: "#BABABA", + procedure_call: "#661CF6", + function_call: "#330610", + variable: "#FF0000", + parameter: "#0000FF", complete: "#A65C5B", }; /** * Create the svg representation of a block and render @@ -4034,11 +4088,11 @@ "name": "program", "check": ["Statement"] } ] }) - this.setColour(Blockly.GOBSTONES_COLORS.program); + this.setColour(Blockly.CUSTOM_COLORS.Program || Blockly.CUSTOM_COLORS.program); this.setDeletable(true); this.setEditable(true); this.setMovable(true); }, @@ -4078,11 +4132,11 @@ "name": "interactiveprogram", "check": ["InteractiveBinding"] } ] }); - this.setColour(Blockly.GOBSTONES_COLORS.interactiveProgram); + this.setColour(Blockly.CUSTOM_COLORS.InteractiveProgram || Blockly.CUSTOM_COLORS.interactiveProgram); this.setDeletable(true); this.setEditable(true); this.setMovable(true); }, @@ -4220,11 +4274,11 @@ type: "field_dropdown", name: "InteractiveBindingDropdownKey", options: keys.map(it => [it.name, it.code]), } ], - colour: Blockly.GOBSTONES_COLORS.interactiveBinding, + colour: Blockly.CUSTOM_COLORS.InteractiveBinding || Blockly.CUSTOM_COLORS.interactiveBinding, tooltip: "Escoger una entrada", }); this.appendStatementInput('block').setCheck(["Statement"]); }, @@ -4321,11 +4375,11 @@ type: "Statement", previousStatement: "Statement", nextStatement: "Statement", }); - this.setColour(Blockly.GOBSTONES_COLORS.controlStructure); + this.setColour(Blockly.CUSTOM_COLORS.RepeticionSimple || Blockly.CUSTOM_COLORS.controlStructure); this.appendValueInput('count') .appendField('repetir'); this.appendDummyInput() .appendField('veces'); this.appendStatementInput('block').setCheck(["Statement"]); @@ -4339,11 +4393,11 @@ type: "Statement", previousStatement: "Statement", nextStatement: "Statement", }); - this.setColour(Blockly.GOBSTONES_COLORS.controlStructure); + this.setColour(Blockly.CUSTOM_COLORS.RepeticionCondicional || Blockly.CUSTOM_COLORS.controlStructure); this.appendValueInput('condicion') .setCheck('Bool') .appendField('repetir hasta que'); this.appendStatementInput('block').setCheck(["Statement"]); this.setInputsInline(true); @@ -4356,11 +4410,11 @@ type: "Statement", previousStatement: "Statement", nextStatement: "Statement", }); - this.setColour(Blockly.GOBSTONES_COLORS.controlStructure); + this.setColour(Blockly.CUSTOM_COLORS.AlternativaSimple || Blockly.CUSTOM_COLORS.controlStructure); this.appendValueInput('condicion') .appendField(Blockly.Msg["CONTROLS_IF_MSG_IF"]); this.appendStatementInput('block').setCheck(["Statement"]); this.setInputsInline(true); } @@ -4428,11 +4482,11 @@ "helpUrl": "%{BKY_CONTROLS_IF_HELPURL}", "mutator": "controls_if_mutator_without_ui", "extensions": ["controls_if_tooltip"] }); - this.setColour(Blockly.GOBSTONES_COLORS.controlStructure); + this.setColour(Blockly.CUSTOM_COLORS.AlternativaCompleta || Blockly.CUSTOM_COLORS.controlStructure); this.setInputsInline(true); this.elseCount_++; this.updateShape_(); }, @@ -4491,11 +4545,11 @@ { type: 'input_value', name: 'COLOR' } ], - colour: Blockly.GOBSTONES_COLORS.primitiveCommand, + colour: Blockly.CUSTOM_COLORS.Poner || Blockly.CUSTOM_COLORS.primitiveCommand, tooltip: 'Poner color en casillero.', inputsInline: true }); } }; @@ -4511,11 +4565,11 @@ { type: 'input_value', name: 'COLOR' } ], - colour: Blockly.GOBSTONES_COLORS.primitiveCommand, + colour: Blockly.CUSTOM_COLORS.Sacar || Blockly.CUSTOM_COLORS.primitiveCommand, tooltip: 'Sacar color de casillero.', inputsInline: true }); } }; @@ -4531,11 +4585,11 @@ { type: 'input_value', name: 'DIRECCION' } ], - colour: Blockly.GOBSTONES_COLORS.primitiveCommand, + colour: Blockly.CUSTOM_COLORS.Mover || Blockly.CUSTOM_COLORS.primitiveCommand, tooltip: 'Mover en una dirección.', inputsInline: true }); } }; @@ -4551,11 +4605,11 @@ { type: 'input_value', name: 'DIRECCION' } ], - colour: Blockly.GOBSTONES_COLORS.primitiveCommand, + colour: Blockly.CUSTOM_COLORS.IrAlBorde || Blockly.CUSTOM_COLORS.primitiveCommand, tooltip: 'Ir al borde del tablero.', inputsInline: true }); } }; @@ -4565,11 +4619,11 @@ this.jsonInit({ type: "Statement", previousStatement: "Statement", nextStatement: "Statement", message0: 'Vaciar tablero', - colour: Blockly.GOBSTONES_COLORS.primitiveCommand, + colour: Blockly.CUSTOM_COLORS.VaciarTablero || Blockly.CUSTOM_COLORS.primitiveCommand, tooltip: 'Vaciar el tablero.', inputsInline: true }); } }; @@ -4591,11 +4645,11 @@ "name": "boomDescription", "text": "Ingresar motivo..." } ], "inputsInline": false, - "colour": Blockly.GOBSTONES_COLORS.primitiveCommand, + "colour": Blockly.CUSTOM_COLORS.BOOM || Blockly.CUSTOM_COLORS.primitiveCommand, "tooltip": "Este comando hace que estalle todo." }); } }; @@ -4611,11 +4665,11 @@ "type": "Statement", "previousStatement": "Statement", "nextStatement": "Statement", "lastDummyAlign0": "RIGHT", "message0": "COMPLETAR", - "colour": Blockly.GOBSTONES_COLORS.complete, + "colour": Blockly.CUSTOM_COLORS.ComandoCompletar || Blockly.CUSTOM_COLORS.complete, "tooltip": "Tenés que reemplazar este bloque por tu solución" }); }, onchange: Blockly.Blocks.makeShadowEventListener @@ -4627,11 +4681,11 @@ "type": "InteractiveBinding", "previousStatement": "InteractiveBinding", "nextStatement": "InteractiveBinding", "lastDummyAlign0": "RIGHT", "message0": "COMPLETAR", - "colour": Blockly.GOBSTONES_COLORS.complete, + "colour": Blockly.CUSTOM_COLORS.AsociacionDeTeclaCompletar || Blockly.CUSTOM_COLORS.complete, "tooltip": "Tenés que reemplazar este bloque por tu solución" }); }, onchange: Blockly.Blocks.makeShadowEventListener @@ -4639,17 +4693,34 @@ // ------------------------------------------------------ // Expresiones: // ------------------------------------------------------ +function deepCopyObj(aObject) { + var bObject, v, k; + bObject = Array.isArray(aObject) ? [] : {}; + for (k in aObject) { + v = aObject[k]; + bObject[k] = (typeof v === "object") ? deepCopyObj(v) : v; + } + return bObject; +} + +const oldMathNumber = Blockly.Blocks.math_number; +Blockly.Blocks.math_number = deepCopyObj(Blockly.Blocks.math_number); +Blockly.Blocks.math_number.init = function() { + oldMathNumber.init.call(this); + this.setColour(Blockly.CUSTOM_COLORS.math_number || Blockly.CUSTOM_COLORS.literalExpression); +} + Blockly.Blocks.ExpresionCompletar = { init: function () { this.jsonInit({ "type": "completar_expression", "message0": "COMPLETAR", "output": "any", - "colour": Blockly.GOBSTONES_COLORS.complete, + "colour": Blockly.CUSTOM_COLORS.ExpresionCompletar || Blockly.CUSTOM_COLORS.complete, "tooltip": "Tenés que reemplazar este bloque por tu solución" }); }, onchange: Blockly.Blocks.makeShadowEventListener @@ -4665,11 +4736,11 @@ type: "field_dropdown", name: type + "Dropdown", options: values.map(value => [value,value]), }], output: type, - colour: Blockly.GOBSTONES_COLORS.literalExpression, + colour: Blockly.CUSTOM_COLORS[`${type}Selector`] || Blockly.CUSTOM_COLORS.literalExpression, tooltip: "Escoger " + type, }); } }; } @@ -4687,11 +4758,11 @@ { type: 'input_value', name: 'VALUE' } ], - colour: Blockly.GOBSTONES_COLORS.expression, + colour: Blockly.CUSTOM_COLORS[this.type] || Blockly.CUSTOM_COLORS.expression, inputsInline: true, output: returnType }) } }; @@ -4725,11 +4796,11 @@ { type: 'input_value', name: 'arg2' } ], - colour: Blockly.GOBSTONES_COLORS.expression, + colour: Blockly.CUSTOM_COLORS.OperadorDeComparacion || Blockly.CUSTOM_COLORS.expression, inputsInline: false, output: 'Bool' }); } }; @@ -4754,11 +4825,11 @@ { type: 'input_value', name: 'arg2' } ], - colour: Blockly.GOBSTONES_COLORS.expression, + colour: Blockly.CUSTOM_COLORS.OperadorNumerico || Blockly.CUSTOM_COLORS.expression, inputsInline: false, output: 'Number' }); } }; @@ -4773,37 +4844,37 @@ name: 'arg1' }, { type: 'field_dropdown', name: 'OPERATOR', - options: [['y también', '&&'], ['o bien', '||']] + options: [['y también', 'AND'], ['o bien', '||']] }, { type: 'input_dummy' }, { type: 'input_value', name: 'arg2' } ], - colour: Blockly.GOBSTONES_COLORS.expression, + colour: Blockly.CUSTOM_COLORS.OperadorLogico || Blockly.CUSTOM_COLORS.expression, inputsInline: false, output: 'Bool' }); } }; Blockly.Blocks.Asignacion = { init: function () { this.jsonInit({ "type": "asignacion", - "message0": "%1 %2 := %3 %4", + "message0": "Recordar que %1 %2 vale %3 %4", "args0": [ { "type": "field_input", "name": "varName", - "text": "nombre de variable", + "text": "una variable", "class": Blockly.Procedures.rename }, { "type": "input_dummy" }, @@ -4816,15 +4887,28 @@ } ], "inputsInline": true, "previousStatement": null, "nextStatement": null, - "colour": Blockly.GOBSTONES_COLORS.assignation, + "colour": Blockly.CUSTOM_COLORS.Asignacion || Blockly.CUSTOM_COLORS.assignation, "tooltip": "", "helpUrl": "" }); - this.getters = []; + + var self = this; + var createGetterButton = new Blockly.FieldImage( + HAND, + 16, + 16, + "Obtener variable", + function() { + var name = self.getFieldValue('varName'); + self.createVariableBlock(name); + } + ); + + this.appendDummyInput().appendField(createGetterButton); }, customContextMenu: function(options) { var name = this.getFieldValue('varName'); @@ -4835,24 +4919,11 @@ createVariableBlock: function(name) { return Blockly.createBlockSvg(this.workspace, 'variables_get', b => { b.setFieldValue(name, 'VAR'); b.moveBy(10,5); - b.parentAssignmentBlock = this; - this.getters.push(b); }); - }, - - removeGetter: function(block){ - this.getters.splice(this.getters.indexOf(block),1); - }, - - onchange: function(event){ - if(event.blockId == this.id && event.type == Blockly.Events.BLOCK_CHANGE && - event.element == 'field'){ - this.getters.forEach(block => block.setFieldValue(event.newValue,'VAR')); - }; } }; Blockly.Blocks.variables_get = { @@ -4860,17 +4931,17 @@ this.jsonInit({ "type": "variables_get", "message0": "%1", "args0": [ { - "type": "field_label", + "type": "field_input", "name": "VAR", "text": "nombre de variable" } ], "output": null, - "colour": 230, + "colour": Blockly.CUSTOM_COLORS.variable, "tooltip": "", "helpUrl": "", }); }, mutationToDom: function() { @@ -4884,13 +4955,20 @@ this.setFieldValue(var_name, 'VAR'); this.$parent = xmlElement.getAttribute("parent") || null; }, onchange: function(event){ - if(event.blockId == this.id && event.type == Blockly.Events.BLOCK_DELETE){ - this.parentAssignmentBlock.removeGetter(this); + if (this.$parent) { + this.getField("VAR").EDITABLE = false; + this.setColour(Blockly.CUSTOM_COLORS.parameter); + } else { + this.setColour(Blockly.CUSTOM_COLORS.variable); } + + if (event.blockId == this.id && event.type == Blockly.Events.BLOCK_DELETE) { + // do something with parent + } } }; Blockly.Blocks.not = createSingleParameterExpressionBlock('no','Bool'); Blockly.Blocks.siguiente = createSingleParameterExpressionBlock('siguiente','*'); @@ -5267,10 +5345,11 @@ }; Blockly.GobstonesLanguage.OperadorLogico = function(block) { // Operations 'and', 'or'. var operator = block.getFieldValue('OPERATOR'); + if (operator === "AND") operator = "&&"; var order = (operator == '&&') ? Blockly.GobstonesLanguage.ORDER_LOGICAL_AND : Blockly.GobstonesLanguage.ORDER_LOGICAL_OR; var argument0 = Blockly.GobstonesLanguage.valueToCode(block, 'arg1', order) || '()'; var argument1 = Blockly.GobstonesLanguage.valueToCode(block, 'arg2', order) || '()'; /* Este código lo comento porque creo que prefiero que estalle gobstones web if (!argument0 && !argument1) { @@ -5952,11 +6031,11 @@ const addCustomActionsChilds = (ttree) => { for (var item of ttree) { if (item.type !== "category") continue; - if (item.name === BLOCKLY_PRIMITIVE_PROCEDURES) + if (item.name === categoryName) item.child = customTree; else addCustomActionsChilds(item.child); } }; @@ -6002,13 +6081,13 @@ xml.push('</xml>'); } return xml.join('\n'); }, - _getPartsByConvention(name) { + _getPartsByConvention(isProcedure, name) { let parts = name.replace(/([A-Z])/g, " $1").toLowerCase(); - parts = parts[1].toUpperCase() + parts.substring(2); + if (isProcedure) parts = parts[1].toUpperCase() + parts.substring(2); parts = this._getParts(parts); return parts; }, @@ -6023,18 +6102,18 @@ const name = this._getPrimitiveName(definition); const customName = definition.attributes && definition.attributes.block_name; const icon = definition.attributes && definition.attributes.block_icon; const finalName = customName || name; - const parts = (customName ? this._getParts : this._getPartsByConvention) + const parts = (customName ? this._getParts : this._getPartsByConvention.bind(this, true)) .bind(this)(finalName); // Bloque Blockly.Blocks[name] = { init: function () { let argsIndex = 1; - this.setColour(Blockly.GOBSTONES_COLORS.primitiveCommand); + this.setColour(Blockly.CUSTOM_COLORS.primitiveProcedure); if (icon) { this.appendDummyInput().appendField(new Blockly.FieldImage( icon, 16, @@ -6083,18 +6162,18 @@ const name = this._getPrimitiveName(definition); const customName = definition.attributes && definition.attributes.block_name; const icon = definition.attributes && definition.attributes.block_icon; const finalName = customName || name; - const parts = (customName ? this._getParts : this._getPartsByConvention) + const parts = (customName ? this._getParts : this._getPartsByConvention.bind(this, false)) .bind(this)(finalName); // Bloque Blockly.Blocks[name] = { init: function () { let argsIndex = 1; - this.setColour(Blockly.GOBSTONES_COLORS.primitiveCommand); + this.setColour(Blockly.CUSTOM_COLORS.primitiveFunction); if (icon) { this.appendDummyInput().appendField(new Blockly.FieldImage( icon, 16, @@ -6237,11 +6316,14 @@ } } }, _onWorkspaceUpdate: function () { - if(this.workspaceXml != this._blocklyWorkspaceXML) { + const hasReloadedXml = this._runWorkspaceXmlRetrocompatibilityFixes(); + if (hasReloadedXml) return; + + if (this.workspaceXml != this._blocklyWorkspaceXML) { this.workspace.clear(); let dom = Blockly.Xml.textToDom(this.workspaceXml); try { Blockly.Xml.domToWorkspace(dom, this.workspace); } catch (e) { @@ -6256,10 +6338,20 @@ } } } }, + _runWorkspaceXmlRetrocompatibilityFixes: function() { + const oldAndOperator = `<field name="OPERATOR">&&</field>`; + const newAndOperator = `<field name="OPERATOR">AND</field>`; + + if (this.workspaceXml.includes(oldAndOperator)) { + this.workspaceXml = this.workspaceXml.replace(new RegExp(oldAndOperator, "g"), newAndOperator); + return true; + } + }, + /** * Reinicializa el workspace, dejando solo el bloque programa */ resetWorkspace: function() { let xmlInicial = '<xml xmlns="http://www.w3.org/1999/xhtml"><block type="Program" x="30" y="30"></block></xml>'; @@ -6470,19 +6562,21 @@ showBlockError: function(blockId, errorKind) { this.workspace.showBlockError(blockId, errorKind); }, testColors(colors) { - Blockly.GOBSTONES_COLORS = colors; + Blockly.CUSTOM_COLORS = colors; Blockly.HSV_SATURATION = colors.globalHsvSaturation; Blockly.HSV_VALUE = colors.globalHsvValue; - Blockly.Constants.Math.HUE = colors.literalExpression; - Blockly.Msg.MATH_HUE = colors.literalExpression.toString(); Blockly.Blocks.procedures.HUE = colors.procedure; - var xml = Blockly.Xml.workspaceToDom(this.workspace); + var xmlDom = Blockly.Xml.workspaceToDom(this.workspace); + const xml = Blockly.Xml.domToText(xmlDom); this.resetWorkspace(); - Blockly.Xml.domToWorkspace(xml, this.workspace); + + setTimeout(() => { + this.workspaceXml = xml; + }, 0); } }); </script> </dom-module> </body></html> \ No newline at end of file