|
| 1 | +/** |
| 2 | + * Define Ruby code generator for BOOST Blocks |
| 3 | + * @param {RubyGenerator} Generator The RubyGenerator |
| 4 | + * @return {RubyGenerator} same as param. |
| 5 | + */ |
| 6 | +export default function (Generator) { |
| 7 | + Generator.boost_menu_MOTOR_ID = function (block) { |
| 8 | + const index = Generator.getFieldValue(block, 'MOTOR_ID') || 0; |
| 9 | + const motorid = Generator.quote_(index); |
| 10 | + return [motorid, Generator.ORDER_ATOMIC]; |
| 11 | + }; |
| 12 | + |
| 13 | + Generator.boost_motorOnFor = function (block) { |
| 14 | + const motorid = Generator.valueToCode(block, 'MOTOR_ID', Generator.ORDER_NONE) || null; |
| 15 | + const duration = Generator.valueToCode(block, 'DURATION', Generator.ORDER_NONE) || null; |
| 16 | + return `boost_motor_turn_on_for(${motorid}, ${duration})\n`; |
| 17 | + }; |
| 18 | + |
| 19 | + Generator.boost_motorOnForRotation = function (block) { |
| 20 | + const motorid = Generator.valueToCode(block, 'MOTOR_ID', Generator.ORDER_NONE) || null; |
| 21 | + const rotation = Generator.valueToCode(block, 'ROTATION', Generator.ORDER_NONE) || null; |
| 22 | + return `boost_motor_turn_this_way_for(${motorid}, ${rotation})\n`; |
| 23 | + }; |
| 24 | + |
| 25 | + Generator.boost_motorOn = function (block) { |
| 26 | + const motorid = Generator.valueToCode(block, 'MOTOR_ID', Generator.ORDER_NONE) || null; |
| 27 | + return `boost_motor_turn_on_for(${motorid})\n`; |
| 28 | + }; |
| 29 | + |
| 30 | + Generator.boost_motorOff = function (block) { |
| 31 | + const motorid = Generator.valueToCode(block, 'MOTOR_ID', Generator.ORDER_NONE) || null; |
| 32 | + return `boost_motor_turn_off_for(${motorid})\n`; |
| 33 | + }; |
| 34 | + |
| 35 | + Generator.boost_setMotorPower = function (block) { |
| 36 | + const motorid = Generator.valueToCode(block, 'MOTOR_ID', Generator.ORDER_NONE) || null; |
| 37 | + const power = Generator.valueToCode(block, 'POWER', Generator.ORDER_NONE) || null; |
| 38 | + return `boost_motor_set_power_for(${motorid}, ${power})\n`; |
| 39 | + }; |
| 40 | + |
| 41 | + return Generator; |
| 42 | +} |
0 commit comments