Skip to content

Commit da294b5

Browse files
committed
support makeymakey_whenMakeyKeyPressed block to ruby.
1 parent 923d8db commit da294b5

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/lib/ruby-generator/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import PenBlocks from './pen.js';
2121
import VideoBlocks from './video.js';
2222
import Text2SpeechBlocks from './text2speech.js';
2323
import TranslateBlocks from './translate.js';
24+
import MakeyMakeyBlocks from './makeymakey.js';
2425
import MicrobitBlocks from './microbit.js';
2526

2627
const SCALAR_TYPE = '';
@@ -445,6 +446,7 @@ PenBlocks(RubyGenerator);
445446
VideoBlocks(RubyGenerator);
446447
Text2SpeechBlocks(RubyGenerator);
447448
TranslateBlocks(RubyGenerator);
449+
MakeyMakeyBlocks(RubyGenerator);
448450
MicrobitBlocks(RubyGenerator);
449451

450452
export default RubyGenerator;

src/lib/ruby-generator/makeymakey.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Define Ruby code generator for MakeyMakey Blocks
3+
* @param {RubyGenerator} Generator The RubyGenerator
4+
* @return {RubyGenerator} same as param.
5+
*/
6+
export default function (Generator) {
7+
Generator.makeymakey_menu_KEY = function (block) {
8+
const key = Generator.quote_(Generator.getFieldValue(block, 'KEY') || 'SPACE');
9+
return [key, Generator.ORDER_ATOMIC];
10+
};
11+
12+
Generator.makeymakey_whenMakeyKeyPressed = function (block) {
13+
block.isStatement = true;
14+
const key = Generator.valueToCode(block, 'KEY', Generator.ORDER_NONE) || null;
15+
return `${Generator.spriteName()}.when(:makey_key_pressed, ${key}) do\n`;
16+
};
17+
18+
return Generator;
19+
}

0 commit comments

Comments
 (0)