Skip to content

Commit 844a774

Browse files
authored
Merge pull request #234 from smalruby/smalrubot-s1-extension
Smalrubot s1 extension
2 parents f3833d4 + ff9b0a6 commit 844a774

File tree

16 files changed

+593
-7
lines changed

16 files changed

+593
-7
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,6 @@
151151
},
152152
"dependencies": {
153153
"lodash.camelcase": "^4.3.0",
154-
"scratch-vm": "github:smalruby/scratch-vm#develop"
154+
"scratch-vm": "github:smalruby/scratch-vm#smalrubot-s1-extension"
155155
}
156156
}

src/lib/libraries/extensions/index.jsx

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ import meshInsetIconURL from './mesh/mesh-small.png';
5151
import meshConnectionIconURL from './mesh/mesh-illustration.png';
5252
import meshConnectionSmallIconURL from './mesh/mesh-small.png';
5353

54+
import smalrubotS1IconURL from './smalrubot-s1/smalrubot-s1.png';
55+
import smalrubotS1InsetIconURL from './smalrubot-s1/smalrubot-s1-small.png';
56+
import smalrubotS1ConnectionIconURL from './smalrubot-s1/smalrubot-s1-illustration.png';
57+
import smalrubotS1ConnectionSmallIconURL from './smalrubot-s1/smalrubot-s1-small.png';
58+
5459
export default [
5560
{
5661
name: (
@@ -356,5 +361,40 @@ export default [
356361
/>
357362
),
358363
helpLink: 'https://github.com/smalruby/smalruby3-gui/wiki/Mesh'
364+
},
365+
{
366+
name: (
367+
<FormattedMessage
368+
defaultMessage="Smalrubot S1"
369+
description="Name for the 'Smalrubot S1' extension"
370+
id="gui.smalruby3.extension.smalrubotS1.name"
371+
/>
372+
),
373+
extensionId: 'smalrubotS1',
374+
iconURL: smalrubotS1IconURL,
375+
insetIconURL: smalrubotS1InsetIconURL,
376+
description: (
377+
<FormattedMessage
378+
defaultMessage="Control the Smalrubot S1."
379+
description="Description for the 'Smalrubot S1' extension"
380+
id="gui.smalruby3.extension.smalrubotS1.description"
381+
/>
382+
),
383+
featured: true,
384+
disabled: false,
385+
bluetoothRequired: false,
386+
internetConnectionRequired: false,
387+
launchPeripheralConnectionFlow: true,
388+
useAutoScan: true,
389+
connectionIconURL: smalrubotS1ConnectionIconURL,
390+
connectionSmallIconURL: smalrubotS1ConnectionSmallIconURL,
391+
connectingMessage: (
392+
<FormattedMessage
393+
defaultMessage="Connecting"
394+
description="Message to help people connect to their Smalrubot S1."
395+
id="gui.smalruby3.extension.smalrubotS1.connectingMessage"
396+
/>
397+
),
398+
helpLink: 'https://github.com/smalruby/smalruby3-gui/wiki/SmalrubotS1'
359399
}
360400
];
17.1 KB
Loading
4.1 KB
Loading
286 KB
Loading

src/lib/ruby-generator/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import EV3Blocks from './ev3.js';
2828
import WeDo2Blocks from './wedo2.js';
2929
import GdxForBlocks from './gdx_for.js';
3030
import MeshBlocks from './mesh.js';
31+
import SmalrubotS1Blocks from './smalrubot_s1.js';
3132

3233
const SCALAR_TYPE = '';
3334
const LIST_TYPE = 'list';
@@ -457,5 +458,6 @@ EV3Blocks(RubyGenerator);
457458
WeDo2Blocks(RubyGenerator);
458459
GdxForBlocks(RubyGenerator);
459460
MeshBlocks(RubyGenerator);
461+
SmalrubotS1Blocks(RubyGenerator);
460462

461463
export default RubyGenerator;

src/lib/ruby-generator/mesh.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default function (Generator) {
1111

1212
Generator.mesh_getSensorValue = function (block) {
1313
const name = Generator.valueToCode(block, 'NAME', Generator.ORDER_NONE) || '" "';
14-
return `mesh_sensor_value(${name})\n`;
14+
return [`mesh_sensor_value(${name})`, Generator.ORDER_ATOMIC];
1515
};
1616

1717
return Generator;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Define Ruby code generator for Smalrubot S1 Blocks
3+
* @param {RubyGenerator} Generator The RubyGenerator
4+
* @return {RubyGenerator} same as param.
5+
*/
6+
export default function (Generator) {
7+
Generator.smalrubotS1_action = function (block) {
8+
const action = Generator.quote_(
9+
Generator.getFieldValue(block, 'ACTION', Generator.ORDER_NONE) || 'forward'
10+
);
11+
return `smalrubot_s1.action(${action})\n`;
12+
};
13+
14+
Generator.smalrubotS1_actionAndStopAfter = function (block) {
15+
const action = Generator.quote_(
16+
Generator.getFieldValue(block, 'ACTION', Generator.ORDER_NONE) || 'forward'
17+
);
18+
const secs = Generator.valueToCode(block, 'SECS', Generator.ORDER_NONE) || 1;
19+
return `smalrubot_s1.action(${action}, ${secs})\n`;
20+
};
21+
22+
Generator.smalrubotS1_bendArm = function (block) {
23+
const degree = Generator.valueToCode(block, 'DEGREE', Generator.ORDER_NONE) || 90;
24+
const secs = Generator.valueToCode(block, 'SECS', Generator.ORDER_NONE) || 1;
25+
return `smalrubot_s1.bend_arm(${degree}, ${secs})\n`;
26+
};
27+
28+
Generator.smalrubotS1_getSensorValue = function (block) {
29+
const position = Generator.quote_(
30+
Generator.getFieldValue(block, 'POSITION', Generator.ORDER_NONE) || 'left'
31+
);
32+
return [`smalrubot_s1.sensor_value(${position})`, Generator.ORDER_ATOMIC];
33+
};
34+
35+
Generator.smalrubotS1_turnLedOn = function (block) {
36+
const position = Generator.quote_(
37+
Generator.getFieldValue(block, 'POSITION', Generator.ORDER_NONE) || 'left'
38+
);
39+
return `smalrubot_s1.led(${position}, true)\n`;
40+
};
41+
42+
Generator.smalrubotS1_turnLedOff = function (block) {
43+
const position = Generator.quote_(
44+
Generator.getFieldValue(block, 'POSITION', Generator.ORDER_NONE) || 'left'
45+
);
46+
return `smalrubot_s1.led(${position}, false)\n`;
47+
};
48+
49+
Generator.smalrubotS1_getMotorSpeed = function (block) {
50+
const position = Generator.quote_(
51+
Generator.getFieldValue(block, 'POSITION', Generator.ORDER_NONE) || 'left'
52+
);
53+
return [`smalrubot_s1.get_motor_speed(${position})`, Generator.ORDER_ATOMIC];
54+
};
55+
56+
Generator.smalrubotS1_setMotorSpeed = function (block) {
57+
const position = Generator.quote_(
58+
Generator.getFieldValue(block, 'POSITION', Generator.ORDER_NONE) || 'left'
59+
);
60+
const speed = Generator.valueToCode(block, 'SPEED', Generator.ORDER_NONE) || 1;
61+
return `smalrubot_s1.set_motor_speed(${position}, ${speed})\n`;
62+
};
63+
64+
return Generator;
65+
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import EV3Converter from './ev3';
2424
import Wedo2Converter from './wedo2';
2525
import GdxForConverter from './gdx_for';
2626
import MeshConverter from './mesh';
27+
import SmalrubotS1Converter from './smalrubot_s1';
2728

2829
/* eslint-disable no-invalid-this */
2930
const ColorRegexp = /^#[0-9a-fA-F]{6}$/;
@@ -68,6 +69,7 @@ class RubyToBlocksConverter {
6869
Wedo2Converter,
6970
GdxForConverter,
7071
MeshConverter,
72+
SmalrubotS1Converter,
7173

7274
MotionConverter,
7375
LooksConverter,
@@ -359,6 +361,10 @@ class RubyToBlocksConverter {
359361
return _.isNumber(value) || (value && (value.type === 'int' || value.type === 'float'));
360362
}
361363

364+
_isTrue (value) {
365+
return value === true || (value && value.type === 'true');
366+
}
367+
362368
_isFalse (value) {
363369
return value === false || (value && value.type === 'false');
364370
}
@@ -781,6 +787,15 @@ class RubyToBlocksConverter {
781787
return block;
782788
}
783789

790+
_changeRubyExpressionBlock (block, opcode, blockType) {
791+
this._changeBlock(block, opcode, blockType);
792+
793+
delete this._context.blocks[block.inputs.EXPRESSION.block];
794+
delete block.inputs.EXPRESSION;
795+
796+
return block;
797+
}
798+
784799
_changeToBooleanArgument (varName) {
785800
varName = varName.toString();
786801
const variable = this._context.localVariables[varName];

0 commit comments

Comments
 (0)