Skip to content

Commit 182db15

Browse files
authored
Merge pull request #206 from yusuke0227/develop
Boostのブロック追加
2 parents d2e48f0 + 4cb39bb commit 182db15

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/lib/ruby-generator/boost.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
}

src/lib/ruby-generator/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import Text2SpeechBlocks from './text2speech.js';
2323
import TranslateBlocks from './translate.js';
2424
import MakeyMakeyBlocks from './makeymakey.js';
2525
import MicrobitBlocks from './microbit.js';
26+
import BoostBlocks from './boost.js';
2627

2728
const SCALAR_TYPE = '';
2829
const LIST_TYPE = 'list';
@@ -448,5 +449,6 @@ Text2SpeechBlocks(RubyGenerator);
448449
TranslateBlocks(RubyGenerator);
449450
MakeyMakeyBlocks(RubyGenerator);
450451
MicrobitBlocks(RubyGenerator);
452+
BoostBlocks(RubyGenerator);
451453

452454
export default RubyGenerator;

0 commit comments

Comments
 (0)