diff --git a/msg/json/en.json b/msg/json/en.json index 2ad462e2e8..0cdefd8b4e 100644 --- a/msg/json/en.json +++ b/msg/json/en.json @@ -171,6 +171,9 @@ "OPERATORS_MATHOP_LOG": "log", "OPERATORS_MATHOP_EEXP": "e ^", "OPERATORS_MATHOP_10EXP": "10 ^", + "OPERATORS_CONVERT": "convert %1 to %2", + "OPERATORS_CONVERT_DECIMAL": "decimal", + "OPERATORS_CONVERT_PERCENT": "percent", "PROCEDURES_DEFINITION": "define %1", "SENSING_TOUCHINGOBJECT": "touching %1?", "SENSING_TOUCHINGOBJECT_POINTER": "mouse-pointer", diff --git a/src/blocks/math.ts b/src/blocks/math.ts index efecdf1289..87b4f2e481 100644 --- a/src/blocks/math.ts +++ b/src/blocks/math.ts @@ -128,3 +128,32 @@ Blockly.Blocks.math_angle = { }) }, } + +Blockly.Blocks.math_number_convert = { + /** + * Block for converting a number to a decimal or percentage. + */ + init: function (this: Blockly.Block) { + this.jsonInit({ + message0: 'convert %1 to %2', + args0: [ + { + type: 'input_value', + name: 'NUM', + check: 'Number', + }, + { + type: 'field_dropdown', + name: 'CONVERT_TYPE', + options: [ + ['decimal', 'DECIMAL'], + ['percent', 'PERCENT'], + ], + }, + ], + output: 'Number', + outputShape: Constants.OUTPUT_SHAPE_ROUND, + extensions: ['colours_textfield'], + }) + }, +} diff --git a/src/blocks/operators.ts b/src/blocks/operators.ts index b54161f496..2f6bf1e04d 100644 --- a/src/blocks/operators.ts +++ b/src/blocks/operators.ts @@ -422,3 +422,29 @@ Blockly.Blocks.operator_mathop = { }) }, } + +Blockly.Blocks.operator_convert = { + /** + * Block for converting a number to a decimal or percentage. + */ + init: function (this: Blockly.Block) { + this.jsonInit({ + message0: Blockly.Msg.OPERATORS_CONVERT, + args0: [ + { + type: 'input_value', + name: 'NUM', + }, + { + type: 'field_dropdown', + name: 'CONVERT_TYPE', + options: [ + [Blockly.Msg.OPERATORS_CONVERT_DECIMAL, 'DECIMAL'], + [Blockly.Msg.OPERATORS_CONVERT_PERCENT, 'PERCENT'], + ], + }, + ], + extensions: ['colours_operators', 'output_number'], + }) + }, +}