app/assets/htmls/gs-element-blockly.html in gobstones-blockly-0.20.1 vs app/assets/htmls/gs-element-blockly.html in gobstones-blockly-0.21.0
- old
+ new
@@ -5079,10 +5079,32 @@
// do something with parent
}
}
};
+Blockly.Blocks.OperadoresDeEnumeracion = {
+ init: function () {
+ this.jsonInit({
+ message0: '%1 %2',
+ args0: [
+ {
+ type: 'field_dropdown',
+ name: 'OPERATOR',
+ options: [['siguiente', 'siguiente'], ['previo', 'previo'], ['opuesto', 'opuesto']]
+ },
+ {
+ type: 'input_value',
+ name: 'VALUE'
+ }
+ ],
+ colour: Blockly.CUSTOM_COLORS.OperadoresDeEnumeracion || Blockly.CUSTOM_COLORS.operator,
+ inputsInline: true,
+ output: "*"
+ })
+ }
+};
+
Blockly.Blocks.not = createSingleParameterExpressionBlock('no','Bool');
Blockly.Blocks.siguiente = createSingleParameterExpressionBlock('siguiente','*');
Blockly.Blocks.previo = createSingleParameterExpressionBlock('previo','*');
Blockly.Blocks.opuesto = createSingleParameterExpressionBlock('opuesto','*');
@@ -5502,10 +5524,14 @@
*/
var code = argument0 + ' ' + operator + ' ' + argument1;
return [code, order];
};
+Blockly.GobstonesLanguage.OperadoresDeEnumeracion = function(block) {
+ return exprParamsBlockCodeGenerator(block.getFieldValue('OPERATOR'), ['VALUE'])(block);
+};
+
Blockly.GobstonesLanguage.not = exprParamsBlockCodeGenerator('not',['VALUE']);
Blockly.GobstonesLanguage.siguiente = exprParamsBlockCodeGenerator('siguiente',['VALUE']);
Blockly.GobstonesLanguage.previo = exprParamsBlockCodeGenerator('previo',['VALUE']);
Blockly.GobstonesLanguage.opuesto = exprParamsBlockCodeGenerator('opuesto',['VALUE']);
@@ -6049,10 +6075,13 @@
let tree = []
let xml = toolboxXML || this.$$('#toolbox').innerHTML;
this._processCustomCategories(xml);
+ setTimeout(() => {
+ this._processCustomCategoryStyles(xml);
+ });
// TODO: Este parseo por strings es tremendo, y esa property `xml` de los nodos se usa en _toolboxBlockXML, _toolboxBlockXML, etc. Hay que hacer de vuelta todo lo de acciones primitivas.
xml = xml.replace(/> *<\/category>/g, ">\n</category>");
let toolboxDefaultLines = xml.split("\n");
@@ -6636,9 +6665,38 @@
this.primitiveProceduresCategoryName = name;
}
if (custom === "PRIMITIVE_FUNCTIONS") {
this.primitiveFunctionsCategoryName = name;
+ }
+ });
+ },
+
+ _processCustomCategoryStyles(xml) {
+ const parsedXml = Blockly.Xml.textToDom(`<xml>${xml}</xml>`);
+
+ const forEachNode = (node, action) => {
+ action(node);
+ node.childNodes.forEach((node) => forEachNode(node, action));
+ }
+
+ forEachNode(parsedXml, (node) => {
+ if (!node.getAttribute) return;
+
+ const name = node.getAttribute("name");
+ const custom = node.getAttribute("gbs_custom");
+
+ if (custom === "SEPARATOR") {
+ const toolbar = document.querySelector("#blocklyDiv div div div").childNodes[1];
+
+ forEachNode(toolbar, (toolbarNode) => {
+ const isLabel = toolbarNode.classList && toolbarNode.classList[0] === "blocklyTreeLabel";
+ const isTheRightCategory = toolbarNode.textContent === name;
+
+ if (isLabel && isTheRightCategory) {
+ toolbarNode.innerHTML = `<strong>${toolbarNode.innerText}</strong>`;
+ }
+ });
}
});
},
_mapToolboxTree: function(toolboxTree, f){
\ No newline at end of file