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
2 changes: 2 additions & 0 deletions src/lib/ruby-generator/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import PenBlocks from './pen.js';
import VideoBlocks from './video.js';
import Text2SpeechBlocks from './text2speech.js';
import TranslateBlocks from './translate.js';
import MakeyMakeyBlocks from './makeymakey.js';
import MicrobitBlocks from './microbit.js';

const SCALAR_TYPE = '';
Expand Down Expand Up @@ -445,6 +446,7 @@ PenBlocks(RubyGenerator);
VideoBlocks(RubyGenerator);
Text2SpeechBlocks(RubyGenerator);
TranslateBlocks(RubyGenerator);
MakeyMakeyBlocks(RubyGenerator);
MicrobitBlocks(RubyGenerator);

export default RubyGenerator;
19 changes: 19 additions & 0 deletions src/lib/ruby-generator/makeymakey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Define Ruby code generator for MakeyMakey Blocks
* @param {RubyGenerator} Generator The RubyGenerator
* @return {RubyGenerator} same as param.
*/
export default function (Generator) {
Generator.makeymakey_menu_KEY = function (block) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここは、 [スペースキー▼]"SPACE" という文字列に変換する処理です。どうやって、 makeymakey_menu_KEY という名前を見つけるかが難しいところです。

まず /smalruby3-gui/node_modules/scratch-vm/src/extensions/scratch3_makeymakey/index.jsgetInfo メソッドをみます。

その中から menus: { という記述を見つけます。

すぐ下に KEY { とありますが、これが名前です。

id(=makeymakey) と menus と ↑の KEY を組み合わせて
makeymakey_menus_KEY という名前を導きました。

const key = Generator.quote_(Generator.getFieldValue(block, 'KEY') || 'SPACE');
return [key, Generator.ORDER_ATOMIC];
};

Generator.makeymakey_whenMakeyKeyPressed = function (block) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここが ^[スペースキー▼]が押されたとき| ブロックを self.when(:makey_key_pressed, "SPACE") do 〜 end というRubyのプログラムに変換するところです。

block.isStatement = true;
const key = Generator.valueToCode(block, 'KEY', Generator.ORDER_NONE) || null;
return `${Generator.spriteName()}.when(:makey_key_pressed, ${key}) do\n`;
};

return Generator;
}