From a9e679401fd29faa583ac28935bfe752c66f9259 Mon Sep 17 00:00:00 2001 From: Alexey Nesterov Date: Thu, 30 Nov 2023 10:08:57 +1000 Subject: [PATCH] Added new blocks: common_eye_new_eye common_eye_run_anim --- source/blocks/adam_common.js | 35 +++++++++++++++++++++++++ source/generators/python/adam_common.js | 18 ++++++++++++- source/generators/python/adam_three.js | 3 +++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/source/blocks/adam_common.js b/source/blocks/adam_common.js index 6b57ea1..bc2203c 100644 --- a/source/blocks/adam_common.js +++ b/source/blocks/adam_common.js @@ -8,6 +8,41 @@ Blockly.defineBlocksWithJsonArray([ +/*new eye pack*/ +{ + "type": "common_eye_new_eye", + "message0": "Новый экземпляр класса RobotEyeDisplay()", + "output": null, + "colour": 230, + "tooltip": "", + "helpUrl": "" +}, + +{ + "type": "common_eye_run_anim", + "message0": "переменная класса RobotEyeDisplay() %1 анимация правого глаза %2 анимация левого глаза %3", + "args0": [ + { + "type": "input_value", + "name": "instance_class_variable" + }, + { + "type": "input_value", + "name": "right_eye_gif_path" + }, + { + "type": "input_value", + "name": "left_path_gif_path" + } + ], + "previousStatement": null, + "nextStatement": null, + "colour": 230, + "tooltip": "", + "helpUrl": "" +}, + + /** * common_eye_pack * diff --git a/source/generators/python/adam_common.js b/source/generators/python/adam_common.js index f4ba186..b10c522 100644 --- a/source/generators/python/adam_common.js +++ b/source/generators/python/adam_common.js @@ -5,7 +5,23 @@ 'use strict'; // If any new block imports any library, add that library name here. -Blockly.Python.addReservedWords('smbus, board, adafruit_extended_bus, ExtendedI2C, musicpy, os, sh, RHVoice, pygame'); +Blockly.Python.addReservedWords('smbus, board, adafruit_extended_bus, ExtendedI2C, musicpy, os, sh, RHVoice, pygame, RobotEyeDisplay'); + +/* common_eye_new_eye */ +Blockly.Python['common_eye_new_eye'] = function(block) { + Blockly.Python.definitions_['from_robot_eye_display_import_RobotEyeDisplay'] = 'from robot_eye_display import RobotEyeDisplay'; + var code = 'RobotEyeDisplay()'; + return [code, Blockly.Python.ORDER_NONE]; +}; + +/* common_eye_run_anim */ +Blockly.Python['common_eye_run_anim'] = function(block) { + var value_instance_class_variable = Blockly.Python.valueToCode(block, 'instance_class_variable', Blockly.Python.ORDER_ATOMIC); + var value_right_eye_gif_path = Blockly.Python.valueToCode(block, 'right_eye_gif_path', Blockly.Python.ORDER_NONE); + var value_left_path_gif_path = Blockly.Python.valueToCode(block, 'left_path_gif_path', Blockly.Python.ORDER_NONE); + var code = value_instance_class_variable + '.run(' + value_right_eye_gif_path + ', ' + value_left_path_gif_path + ')\n'; + return code; +}; /** * common_eye_pack diff --git a/source/generators/python/adam_three.js b/source/generators/python/adam_three.js index b38d778..d783cd3 100644 --- a/source/generators/python/adam_three.js +++ b/source/generators/python/adam_three.js @@ -165,6 +165,9 @@ Blockly.Python['controller_handle_command'] = function(block) { return code; }; + + + Blockly.Python['controller_speed_variable'] = function(block) { var number_speed = block.getFieldValue('speed'); var code = number_speed;