Skip to content

Commit 4d958c3

Browse files
committed
[ADD] converter of button_pressed? function
1 parent da61d00 commit 4d958c3

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,48 @@
11
/* global Opal */
22
import _ from 'lodash';
33

4+
const MicroBit = 'microbit';
45
/**
56
* MicroBit converter
67
*/
78
const MicroBitConverter = {
9+
// eslint-disable-next-line no-unused-vars
10+
onSend: function (receiver, name, args, rubyBlockArgs, rubyBlock) {
11+
let block;
12+
console.log(arguments);
13+
if ((this._isSelf(receiver) || receiver === Opal.nil) &&
14+
name === 'when' &&
15+
args.length >= 1 && args[0].type === 'sym' &&
16+
rubyBlockArgs && rubyBlockArgs.length === 0 &&
17+
rubyBlock) {
18+
switch (args[0].value) {
19+
}
20+
} else if (this._isSelf(receiver) || receiver === Opal.nil) {
21+
switch (name) {
22+
case 'microbit':
23+
if (args.length === 0) {
24+
block = this._createRubyExpressionBlock(MicroBit);
25+
}
26+
break;
27+
}
28+
} else if (this._equalRubyExpression(receiver, MicroBit)) {
29+
switch (name) {
30+
case 'button_pressed?':
31+
if (args.length === 1 && this._isString(args[0])) {
32+
block = this._changeBlock(receiver, 'microbit_isButtonPressed', 'value_boolean');
33+
delete this._context.blocks[receiver.inputs.EXPRESSION.block];
34+
delete receiver.inputs.EXPRESSION;
35+
36+
this._addFieldInput(
37+
block, 'BTN', 'microbit_menu_buttons', 'buttons',
38+
args[0], 'A'
39+
);
40+
}
41+
break;
42+
}
43+
}
44+
return block;
45+
}
846
};
947

1048
export default MicroBitConverter;

0 commit comments

Comments
 (0)