Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/lib/ruby-generator/boost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Define Ruby code generator for BOOST Blocks
* @param {RubyGenerator} Generator The RubyGenerator
* @return {RubyGenerator} same as param.
*/
export default function (Generator) {
Generator.boost_menu_MOTOR_ID = function (block) {
const index = Generator.getFieldValue(block, 'MOTOR_ID') || 0;
const motorid = Generator.quote_(index);
return [motorid, Generator.ORDER_ATOMIC];
};

Generator.boost_motorOnFor = function (block) {
const motorid = Generator.valueToCode(block, 'MOTOR_ID', Generator.ORDER_NONE) || null;
const duration = Generator.valueToCode(block, 'DURATION', Generator.ORDER_NONE) || null;
return `boost_motor_turn_on_for(${motorid}, ${duration})\n`;
};

Generator.boost_motorOnForRotation = function (block) {
const motorid = Generator.valueToCode(block, 'MOTOR_ID', Generator.ORDER_NONE) || null;
const rotation = Generator.valueToCode(block, 'ROTATION', Generator.ORDER_NONE) || null;
return `boost_motor_turn_this_way_for(${motorid}, ${rotation})\n`;
};

Generator.boost_motorOn = function (block) {
const motorid = Generator.valueToCode(block, 'MOTOR_ID', Generator.ORDER_NONE) || null;
return `boost_motor_turn_on_for(${motorid})\n`;
};

Generator.boost_motorOff = function (block) {
const motorid = Generator.valueToCode(block, 'MOTOR_ID', Generator.ORDER_NONE) || null;
return `boost_motor_turn_off_for(${motorid})\n`;
};

Generator.boost_setMotorPower = function (block) {
const motorid = Generator.valueToCode(block, 'MOTOR_ID', Generator.ORDER_NONE) || null;
const power = Generator.valueToCode(block, 'POWER', Generator.ORDER_NONE) || null;
return `boost_motor_set_power_for(${motorid}, ${power})\n`;
};

return Generator;
}
2 changes: 2 additions & 0 deletions src/lib/ruby-generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Text2SpeechBlocks from './text2speech.js';
import TranslateBlocks from './translate.js';
import MakeyMakeyBlocks from './makeymakey.js';
import MicrobitBlocks from './microbit.js';
import BoostBlocks from './boost.js';

const SCALAR_TYPE = '';
const LIST_TYPE = 'list';
Expand Down Expand Up @@ -448,5 +449,6 @@ Text2SpeechBlocks(RubyGenerator);
TranslateBlocks(RubyGenerator);
MakeyMakeyBlocks(RubyGenerator);
MicrobitBlocks(RubyGenerator);
BoostBlocks(RubyGenerator);

export default RubyGenerator;