Skip to content

Commit 6a7cc42

Browse files
committed
Add some ruby-to-blocks-converter function on microbit_more
1 parent 4af8c93 commit 6a7cc42

File tree

1 file changed

+93
-22
lines changed

1 file changed

+93
-22
lines changed

src/lib/ruby-to-blocks-converter/microbit_more.js

Lines changed: 93 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,41 @@ const MicroBitMoreConverter = {
1616
rubyBlockArgs && rubyBlockArgs.length === 0 &&
1717
rubyBlock) {
1818
switch (args[0].value) {
19-
case 'microbit_more_button_pressed':
19+
case 'mbit_more_button_pressed':
2020
if (args.length === 2 && this._isString(args[1])) {
21-
block = this._createBlock('microbit_more_whenButtonPressed', 'hat');
21+
block = this._createBlock('microbitMore_whenButtonPressed', 'hat');
2222
this._addFieldInput(
23-
block, 'BTN', 'microbit_more_menu_buttons', 'buttons',
23+
block, 'BTN', 'microbitMore_menu_buttons', 'buttons',
2424
args[1], 'A'
2525
);
2626
this._setParent(rubyBlock, block);
2727
}
2828
break;
29-
case 'microbit_more_gesture':
29+
case 'mbit_more_gesture':
3030
if (args.length === 2 && this._isString(args[1])) {
31-
block = this._createBlock('microbit_more_whenGesture', 'hat');
31+
block = this._createBlock('microbitMore_whenGesture', 'hat');
3232
this._addFieldInput(
33-
block, 'GESTURE', 'microbit_more_menu_gestures', 'gestures',
33+
block, 'GESTURE', 'microbitMore_menu_gestures', 'gestures',
3434
args[1], 'moved'
3535
);
3636
this._setParent(rubyBlock, block);
3737
}
3838
break;
39-
case 'microbit_more_tilted':
39+
case 'mbit_more_tilted':
4040
if (args.length === 2 && this._isString(args[1])) {
41-
block = this._createBlock('microbit_more_whenTilted', 'hat');
41+
block = this._createBlock('microbitMore_whenTilted', 'hat');
4242
this._addFieldInput(
43-
block, 'DIRECTION', 'microbit_more_menu_tiltDirectionAny', 'tiltDirectionAny',
43+
block, 'DIRECTION', 'microbitMore_menu_tiltDirectionAny', 'tiltDirectionAny',
4444
args[1], 'any'
4545
);
4646
this._setParent(rubyBlock, block);
4747
}
4848
break;
49-
case 'microbit_more_pin_connected':
49+
case 'mbit_more_pin_connected':
5050
if (args.length === 2 && this._isNumber(args[1])) {
51-
block = this._createBlock('microbit_more_whenPinConnected', 'hat');
51+
block = this._createBlock('microbitMore_whenPinConnected', 'hat');
5252
this._addFieldInput(
53-
block, 'PIN', 'microbit_more_menu_touchPins', 'touchPins',
53+
block, 'PIN', 'microbitMore_menu_gpio', 'gpio',
5454
args[1], '0'
5555
);
5656
this._setParent(rubyBlock, block);
@@ -59,7 +59,7 @@ const MicroBitMoreConverter = {
5959
}
6060
} else if (this._isSelf(receiver) || receiver === Opal.nil) {
6161
switch (name) {
62-
case 'microbit_more':
62+
case 'mbit_more':
6363
if (args.length === 0) {
6464
block = this._createRubyExpressionBlock(MicroBitMore, node);
6565
}
@@ -69,19 +69,19 @@ const MicroBitMoreConverter = {
6969
switch (name) {
7070
case 'button_pressed?':
7171
if (args.length === 1 && this._isString(args[0])) {
72-
block = this._changeBlock(receiver, 'microbit_more_isButtonPressed', 'value_boolean');
72+
block = this._changeBlock(receiver, 'microbitMore_isButtonPressed', 'value_boolean');
7373
delete this._context.blocks[receiver.inputs.EXPRESSION.block];
7474
delete receiver.inputs.EXPRESSION;
7575

7676
this._addFieldInput(
77-
block, 'BTN', 'microbit_more_menu_buttons', 'buttons',
77+
block, 'BTN', 'microbitMore_menu_buttons', 'buttons',
7878
args[0], 'A'
7979
);
8080
}
8181
break;
8282
case 'display':
8383
if (args.length === 5 && args.every(i => this._isString(i))) {
84-
block = this._changeBlock(receiver, 'microbit_more_displaySymbol', 'statement');
84+
block = this._changeBlock(receiver, 'microbitMore_displaySymbol', 'statement');
8585
delete this._context.blocks[receiver.inputs.EXPRESSION.block];
8686
delete receiver.inputs.EXPRESSION;
8787

@@ -98,7 +98,7 @@ const MicroBitMoreConverter = {
9898
break;
9999
case 'display_text':
100100
if (args.length === 1 && this._isString(args[0])) {
101-
block = this._changeBlock(receiver, 'microbit_more_displayText', 'statement');
101+
block = this._changeBlock(receiver, 'microbitMore_displayText', 'statement');
102102
delete this._context.blocks[receiver.inputs.EXPRESSION.block];
103103
delete receiver.inputs.EXPRESSION;
104104

@@ -107,35 +107,106 @@ const MicroBitMoreConverter = {
107107
break;
108108
case 'clear_display':
109109
if (args.length === 0) {
110-
block = this._changeBlock(receiver, 'microbit_more_displayClear', 'statement');
110+
block = this._changeBlock(receiver, 'microbitMore_displayClear', 'statement');
111111
delete this._context.blocks[receiver.inputs.EXPRESSION.block];
112112
delete receiver.inputs.EXPRESSION;
113113
}
114114
break;
115115
case 'tilted?':
116116
if (args.length === 1 && this._isString(args[0])) {
117-
block = this._changeBlock(receiver, 'microbit_more_isTilted', 'value_boolean');
117+
block = this._changeBlock(receiver, 'microbitMore_isTilted', 'value_boolean');
118118
delete this._context.blocks[receiver.inputs.EXPRESSION.block];
119119
delete receiver.inputs.EXPRESSION;
120120

121121
this._addFieldInput(
122-
block, 'DIRECTION', 'microbit_more_menu_tiltDirectionAny', 'tiltDirectionAny',
122+
block, 'DIRECTION', 'microbitMore_menu_tiltDirectionAny', 'tiltDirectionAny',
123123
args[0], 'any'
124124
);
125125
}
126126
break;
127127
case 'tilt_angle':
128128
if (args.length === 1 && this._isString(args[0])) {
129-
block = this._changeBlock(receiver, 'microbit_more_getTiltAngle', 'value');
129+
block = this._changeBlock(receiver, 'microbitMore_getTiltAngle', 'value');
130130
delete this._context.blocks[receiver.inputs.EXPRESSION.block];
131131
delete receiver.inputs.EXPRESSION;
132132

133133
this._addFieldInput(
134-
block, 'DIRECTION', 'microbit_more_menu_tiltDirection', 'tiltDirection',
134+
block, 'DIRECTION', 'microbitMore_menu_tiltDirection', 'tiltDirection',
135135
args[0], 'front'
136136
);
137137
}
138138
break;
139+
case 'pin_connected?':
140+
if (args.length === 1 && this._isNumber(args[0])) {
141+
block = this._changeBlock(receiver, 'microbitMore_isPinConnected', 'value_boolean');
142+
delete this._context.blocks[receiver.inputs.EXPRESSION.block];
143+
delete receiver.inputs.EXPRESSION;
144+
145+
this._addFieldInput(
146+
block, 'PIN', 'microbitMore_menu_gpio', 'gpio',
147+
args[0], '0'
148+
);
149+
}
150+
break;
151+
case 'light_level':
152+
if (args.length === 0){
153+
block = this._changeBlock(receiver, 'microbitMore_getLightLevel', 'value');
154+
delete this._context.blocks[receiver.inputs.EXPRESSION.block];
155+
delete receiver.inputs.EXPRESSION;
156+
}
157+
break;
158+
case 'temperature':
159+
if (args.length === 0){
160+
block = this._changeBlock(receiver, 'microbitMore_getTemperature', 'value');
161+
delete this._context.blocks[receiver.inputs.EXPRESSION.block];
162+
delete receiver.inputs.EXPRESSION;
163+
}
164+
break;
165+
case 'compass_heading':
166+
if (args.length === 0){
167+
block = this._changeBlock(receiver, 'microbitMore_getCompassHeading', 'value');
168+
delete this._context.blocks[receiver.inputs.EXPRESSION.block];
169+
delete receiver.inputs.EXPRESSION;
170+
}
171+
break;
172+
case 'pitch':
173+
if (args.length === 0){
174+
block = this._changeBlock(receiver, 'microbitMore_getPitch', 'value');
175+
delete this._context.blocks[receiver.inputs.EXPRESSION.block];
176+
delete receiver.inputs.EXPRESSION;
177+
}
178+
break;
179+
case 'roll':
180+
if (args.length === 0){
181+
block = this._changeBlock(receiver, 'microbitMore_getRoll', 'value');
182+
delete this._context.blocks[receiver.inputs.EXPRESSION.block];
183+
delete receiver.inputs.EXPRESSION;
184+
}
185+
break;
186+
case 'get_magnetic_force':
187+
if (args.length === 1 && this._isString(args[0])) {
188+
block = this._changeBlock(receiver, 'microbitMore_getMagneticForce', 'value');
189+
delete this._context.blocks[receiver.inputs.EXPRESSION.block];
190+
delete receiver.inputs.EXPRESSION;
191+
192+
this._addFieldInput(
193+
block, 'AXIS', 'microbitMore_menu_axis', 'axis',
194+
args[0], 'absolute'
195+
);
196+
}
197+
break;
198+
case 'get_acceleration':
199+
if (args.length === 1 && this._isString(args[0])) {
200+
block = this._changeBlock(receiver, 'microbitMore_getAcceleration', 'value');
201+
delete this._context.blocks[receiver.inputs.EXPRESSION.block];
202+
delete receiver.inputs.EXPRESSION;
203+
204+
this._addFieldInput(
205+
block, 'AXIS', 'microbitMore_menu_axis', 'axis',
206+
args[0], 'x'
207+
);
208+
}
209+
break;
139210
}
140211
}
141212
return block;

0 commit comments

Comments
 (0)