Skip to content

Commit

Permalink
* (klein0r) Added new blocks: new line, random number, value between …
Browse files Browse the repository at this point in the history
…min and max, if empty
  • Loading branch information
GermanBluefox committed Jun 13, 2023
1 parent 01ee3e8 commit a6db742
Show file tree
Hide file tree
Showing 26 changed files with 284 additions and 161 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -46,7 +46,8 @@ Since v5.5.0 of the JavaScript adapter the following locations (relative to the
<!--
### **WORK IN PROGRESS**
-->
### 7.0.9 (2023-06-13)
### **WORK IN PROGRESS**
* (klein0r) Added new blocks: new line, random number, value between min and max, if empty
* (bluefox) corrected blockly

### 7.0.8 (2023-06-12)
Expand Down
@@ -1,34 +1,11 @@
'use strict';

if (typeof goog !== 'undefined') {
goog.provide('Blockly.JavaScript.Other');

goog.require('Blockly.JavaScript');
}

// --- logic between --------------------------------------------------

Blockly.System.blocks['logic_between'] =
'<block type="logic_between">'
+' <value name="MIN">'
+' <block type="math_number">'
+' <field name="NUM">0</field>'
+' </block>'
+' </value>'
+' <field name="MIN_OPERATOR">LE</field>'
+' <value name="VALUE">'
+' <shadow type="math_number">'
+' <field name="NUM">42</field>'
+' </shadow>'
+' </value>'
+' <field name="MAX_OPERATOR">LE</field>'
+' <value name="MAX">'
+' <block type="math_number">'
+' <field name="NUM">100</field>'
+' </block>'
+' </value>'
+'</block>';

Blockly.Blocks['logic_between'] = {
init: function() {
this.appendValueInput('MIN')
Expand All @@ -39,12 +16,12 @@ Blockly.Blocks['logic_between'] = {
this.appendValueInput('MAX')
.setCheck('Number')
.appendField(new Blockly.FieldDropdown([['<', 'LT'], ['≤', 'LE']]), 'MAX_OPERATOR');

this.setInputsInline(true);
this.setOutput(true, 'Boolean');
this.setColour(Blockly.Constants.Logic.HUE);
this.setColour("%{BKY_LOGIC_HUE}");
this.setTooltip(Blockly.Translate('logic_between_tooltip'));
this.setHelpUrl(Blockly.Translate('logic_between_helpurl'));
// this.setHelpUrl(Blockly.Translate('logic_between_helpurl'));
}
}

Expand All @@ -55,18 +32,10 @@ Blockly.JavaScript['logic_between'] = function(block) {
const minOperator = block.getFieldValue('MIN_OPERATOR') === 'LT' ? '<' : '<=';
const maxOperator = block.getFieldValue('MAX_OPERATOR') === 'LT' ? '<' : '<=';

const code = `${min} ${minOperator} ${value} && ${value} ${maxOperator} ${max}`;
return [code, Blockly.JavaScript.ORDER_LOGICAL_AND];
return [`${min} ${minOperator} ${value} && ${value} ${maxOperator} ${max}`, Blockly.JavaScript.ORDER_LOGICAL_AND];
}

// --- logic_ifempty --------------------------------------------------
Blockly.System.blocks['logic_ifempty'] =
'<block type="logic_ifempty">'
+' <value name="VALUE">'
+' </value>'
+' <value name="DEFLT">'
+' </value>'
+'</block>';
// --- logic ifempty --------------------------------------------------

Blockly.Blocks['logic_ifempty'] = {
init: function() {
Expand All @@ -81,9 +50,9 @@ Blockly.Blocks['logic_ifempty'] = {

this.setOutput(true, null);
this.setInputsInline(true);
this.setColour(Blockly.Constants.Logic.HUE);
this.setColour("%{BKY_LOGIC_HUE}");
this.setTooltip(Blockly.Translate('logic_ifempty_tooltip'));
this.setHelpUrl(Blockly.Translate('logic_ifempty_helpurl'));
// this.setHelpUrl(Blockly.Translate('logic_ifempty_helpurl'));
}
}

Expand Down
25 changes: 25 additions & 0 deletions admin/google-blockly/own/blocks_number.js
@@ -0,0 +1,25 @@
'use strict';

// --- Round Number to n decimal places -------------------------------

Blockly.Blocks['math_rndfixed'] = {
init: function() {
this.appendValueInput('x')
.setCheck('Number')
.appendField(Blockly.Translate('math_rndfixed_round'));
this.appendDummyInput()
.appendField(Blockly.Translate('math_rndfixed_to'))
.appendField(new Blockly.FieldNumber(0, 1, 25), 'n')
.appendField(Blockly.Translate('math_rndfixed_decplcs'));
this.setInputsInline(true);
this.setColour(Blockly.Msg['MATH_HUE']);
this.setOutput(true, 'Number');
this.setTooltip(Blockly.Translate('math_rndfixed_tooltip'));
}
};

Blockly.JavaScript['math_rndfixed'] = function(block) {
var x = Blockly.JavaScript.valueToCode(block, 'x', Blockly.JavaScript.ORDER_ATOMIC);
var exp = Math.pow(10, block.getFieldValue('n'));
return ['Math.round(' + x + ' * ' + exp + ') / ' + exp, Blockly.JavaScript.ORDER_ATOMIC];
};
4 changes: 0 additions & 4 deletions admin/google-blockly/own/blocks_system.js
Expand Up @@ -9,10 +9,6 @@ if (typeof goog !== 'undefined') {
Blockly.CustomBlocks = Blockly.CustomBlocks || [];
Blockly.CustomBlocks.push('System');

function getHelp(word) {
return 'https://github.com/ioBroker/ioBroker.javascript/blob/master/docs/en/javascript.md#' + Blockly.Words[word][systemLang];
}

Blockly.System = {
HUE: 210,
blocks: {}
Expand Down
23 changes: 23 additions & 0 deletions admin/google-blockly/own/blocks_text.js
@@ -0,0 +1,23 @@
'use strict';

// --- Text new line --------------------------------------------------

Blockly.Blocks['text_newline'] = {
// Checkbox.
init: function() {
this.appendDummyInput()
.appendField(Blockly.Translate('text_newline'));

this.appendDummyInput()
.appendField(new Blockly.FieldDropdown([['\\n', '\\n'], ['\\r\\n', '\\r\\n'], ['\\r', '\\r']]), 'Type');
this.setInputsInline(true);
this.setColour(Blockly.Msg['TEXTS_HUE']);
this.setOutput(true, 'String');
this.setTooltip(Blockly.Translate('text_newline_tooltip'));
}
};

Blockly.JavaScript['text_newline'] = function(block) {
var dropdown_type = block.getFieldValue('Type');
return ['\'' + dropdown_type + '\'', Blockly.JavaScript.ORDER_ATOMIC];
};

0 comments on commit a6db742

Please sign in to comment.