Skip to content

Commit 65728b9

Browse files
authored
feat: separate the extension in basics and modulino (#13)
1 parent ad7a3d1 commit 65728b9

File tree

5 files changed

+164
-70
lines changed

5 files changed

+164
-70
lines changed

assets/gui.js

Lines changed: 89 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
return /******/ (() => { // webpackBootstrap
1212
/******/ var __webpack_modules__ = ({
1313

14-
/***/ "../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/scratch3_arduino/index.js":
15-
/*!********************************************************************************************************!*\
16-
!*** ../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/scratch3_arduino/index.js ***!
17-
\********************************************************************************************************/
14+
/***/ "../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_basics/index.js":
15+
/*!******************************************************************************************************!*\
16+
!*** ../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_basics/index.js ***!
17+
\******************************************************************************************************/
1818
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1919

2020
// const formatMessage = require('../../../../../../scratch-editor/node_modules/format-message');
2121
const BlockType = __webpack_require__(/*! ../../../../../../scratch-editor/packages/scratch-vm/src/extension-support/block-type */ "../scratch-vm/src/extension-support/block-type.js");
2222
const ArgumentType = __webpack_require__(/*! ../../../../../../scratch-editor/packages/scratch-vm/src/extension-support/argument-type */ "../scratch-vm/src/extension-support/argument-type.js");
23-
const io = __webpack_require__(/*! ./socket.io.min.js */ "../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/scratch3_arduino/socket.io.min.js");
23+
const io = __webpack_require__(/*! ../socket.io.min.js */ "../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/socket.io.min.js");
2424

2525
/**
2626
* Url of icon to be displayed at the left edge of each extension block.
@@ -36,28 +36,21 @@ const iconURI = '';
3636
// eslint-disable-next-line max-len
3737
const menuIconURI = '';
3838
const wsServerURL = "".concat(window.location.protocol, "//").concat(window.location.hostname, ":7000");
39-
class Scratch3Arduino {
39+
class ArduinoBasics {
4040
constructor(runtime) {
4141
this.runtime = runtime;
4242
this.io = io(wsServerURL, {
4343
path: '/socket.io',
4444
transports: ['polling', 'websocket'],
4545
autoConnect: true
4646
});
47-
48-
// TODO: move to ModulinoPeripheral
49-
this._button_pressed = '';
50-
this.io.on('modulino_buttons_pressed', data => {
51-
console.log("Modulino button pressed event received: ".concat(data.btn));
52-
this._button_pressed = data.btn.toUpperCase();
53-
});
5447
}
5548
}
5649
;
57-
Scratch3Arduino.prototype.getInfo = function () {
50+
ArduinoBasics.prototype.getInfo = function () {
5851
return {
59-
id: 'arduino',
60-
name: "Arduino",
52+
id: 'arduinobasics',
53+
name: "Arduino Basics",
6154
menuIconURI: menuIconURI,
6255
blockIconURI: iconURI,
6356
blocks: [{
@@ -71,7 +64,68 @@ Scratch3Arduino.prototype.getInfo = function () {
7164
defaultValue: '0101010101100010101000100'
7265
}
7366
}
74-
}, {
67+
}]
68+
};
69+
};
70+
ArduinoBasics.prototype.matrixDraw = function (args) {
71+
console.log("Drawing frame on matrix: ".concat(args));
72+
this.io.emit("matrix_draw", {
73+
frame: args.FRAME
74+
});
75+
};
76+
module.exports = ArduinoBasics;
77+
78+
/***/ }),
79+
80+
/***/ "../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_modulino/index.js":
81+
/*!********************************************************************************************************!*\
82+
!*** ../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_modulino/index.js ***!
83+
\********************************************************************************************************/
84+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
85+
86+
const BlockType = __webpack_require__(/*! ../../../../../../scratch-editor/packages/scratch-vm/src/extension-support/block-type */ "../scratch-vm/src/extension-support/block-type.js");
87+
const ArgumentType = __webpack_require__(/*! ../../../../../../scratch-editor/packages/scratch-vm/src/extension-support/argument-type */ "../scratch-vm/src/extension-support/argument-type.js");
88+
const io = __webpack_require__(/*! ../socket.io.min.js */ "../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/socket.io.min.js");
89+
90+
/**
91+
* Url of icon to be displayed at the left edge of each extension block.
92+
* @type {string}
93+
*/
94+
// eslint-disable-next-line max-len
95+
const iconURI = '';
96+
97+
/**
98+
* Url of icon to be displayed in the toolbox menu for the extension category.
99+
* @type {string}
100+
*/
101+
// eslint-disable-next-line max-len
102+
const menuIconURI = '';
103+
const wsServerURL = "".concat(window.location.protocol, "//").concat(window.location.hostname, ":7000");
104+
class ArduinoModulino {
105+
constructor(runtime) {
106+
this.runtime = runtime;
107+
this.io = io(wsServerURL, {
108+
path: '/socket.io',
109+
transports: ['polling', 'websocket'],
110+
autoConnect: true
111+
});
112+
113+
// TODO: move to ModulinoPeripheral
114+
this._button_pressed = '';
115+
this.io.on('modulino_buttons_pressed', data => {
116+
console.log("Modulino button pressed event received: ".concat(data.btn));
117+
this._button_pressed = data.btn.toUpperCase();
118+
});
119+
}
120+
}
121+
;
122+
ArduinoModulino.prototype.getInfo = function () {
123+
return {
124+
id: 'arduinomodulino',
125+
name: "Arduino Modulino",
126+
menuIconURI: menuIconURI,
127+
blockIconURI: iconURI,
128+
blocks: [{
75129
opcode: 'whenModulinoButtonsPressed',
76130
blockType: BlockType.HAT,
77131
text: 'when modulino button [BTN] pressed',
@@ -89,27 +143,21 @@ Scratch3Arduino.prototype.getInfo = function () {
89143
}
90144
};
91145
};
92-
Scratch3Arduino.prototype.matrixDraw = function (args) {
93-
console.log("Drawing frame on matrix: ".concat(args));
94-
this.io.emit("matrix_draw", {
95-
frame: args.FRAME
96-
});
97-
};
98-
Scratch3Arduino.prototype.whenModulinoButtonsPressed = function (args) {
146+
ArduinoModulino.prototype.whenModulinoButtonsPressed = function (args) {
99147
if (args.BTN === this._button_pressed) {
100148
this._button_pressed = '';
101149
return true;
102150
}
103151
return false;
104152
};
105-
module.exports = Scratch3Arduino;
153+
module.exports = ArduinoModulino;
106154

107155
/***/ }),
108156

109-
/***/ "../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/scratch3_arduino/socket.io.min.js":
110-
/*!****************************************************************************************************************!*\
111-
!*** ../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/scratch3_arduino/socket.io.min.js ***!
112-
\****************************************************************************************************************/
157+
/***/ "../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/socket.io.min.js":
158+
/*!***********************************************************************************************!*\
159+
!*** ../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/socket.io.min.js ***!
160+
\***********************************************************************************************/
113161
/***/ (function(module) {
114162

115163
/*!
@@ -376463,7 +376511,8 @@ const builtinExtensions = {
376463376511
gdxfor: () => __webpack_require__(/*! ../extensions/scratch3_gdx_for */ "../scratch-vm/src/extensions/scratch3_gdx_for/index.js"),
376464376512
faceSensing: () => __webpack_require__(/*! ../extensions/scratch3_face_sensing */ "../scratch-vm/src/extensions/scratch3_face_sensing/index.js")
376465376513
};
376466-
builtinExtensions.Scratch3Arduino = () => __webpack_require__(/*! ../extensions/scratch3_arduino */ "../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/scratch3_arduino/index.js");
376514+
builtinExtensions.ArduinoBasics = () => __webpack_require__(/*! ../extensions/arduino_basics */ "../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_basics/index.js");
376515+
builtinExtensions.ArduinoModulino = () => __webpack_require__(/*! ../extensions/arduino_modulino */ "../../../scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_modulino/index.js");
376467376516

376468376517
/**
376469376518
* @typedef {object} ArgumentInfo - Information about an extension block argument
@@ -398054,17 +398103,16 @@ const {
398054398103
__webpack_require__(/*! canvas-toBlob */ "../../node_modules/canvas-toBlob/canvas-toBlob.js");
398055398104
const RESERVED_NAMES = ['_mouse_', '_stage_', '_edge_', '_myself_', '_random_'];
398056398105
const CORE_EXTENSIONS = [
398057-
// 'motion',
398058-
// 'looks',
398059-
// 'sound',
398060-
// 'events',
398061-
// 'control',
398062-
// 'sensing',
398063-
// 'operators',
398064-
// 'variables',
398065-
// 'myBlocks'
398066-
];
398067-
CORE_EXTENSIONS.push('Scratch3Arduino');
398106+
// 'motion',
398107+
// 'looks',
398108+
// 'sound',
398109+
// 'events',
398110+
// 'control',
398111+
// 'sensing',
398112+
// 'operators',
398113+
// 'variables',
398114+
// 'myBlocks'
398115+
'ArduinoBasics', 'ArduinoModulino'];
398068398116

398069398117
/**
398070398118
* Handles connections between blocks, stage, and extensions.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
// const formatMessage = require('../../../../../../scratch-editor/node_modules/format-message');
2+
const BlockType = require('../../../../../../scratch-editor/packages/scratch-vm/src/extension-support/block-type');
3+
const ArgumentType = require('../../../../../../scratch-editor/packages/scratch-vm/src/extension-support/argument-type');
4+
const io = require('../socket.io.min.js');
5+
6+
/**
7+
* Url of icon to be displayed at the left edge of each extension block.
8+
* @type {string}
9+
*/
10+
// eslint-disable-next-line max-len
11+
const iconURI = '';
12+
13+
/**
14+
* Url of icon to be displayed in the toolbox menu for the extension category.
15+
* @type {string}
16+
*/
17+
// eslint-disable-next-line max-len
18+
const menuIconURI = ''
19+
20+
const wsServerURL = `${window.location.protocol}//${window.location.hostname}:7000`;
21+
22+
class ArduinoBasics {
23+
constructor(runtime) {
24+
this.runtime = runtime;
25+
26+
this.io = io(wsServerURL, {
27+
path: '/socket.io',
28+
transports: ['polling', 'websocket'],
29+
autoConnect: true
30+
});
31+
}
32+
};
33+
34+
ArduinoBasics.prototype.getInfo = function () {
35+
return {
36+
id: 'arduinobasics',
37+
name: "Arduino Basics",
38+
menuIconURI: menuIconURI,
39+
blockIconURI: iconURI,
40+
blocks: [
41+
{
42+
opcode: 'matrixDraw',
43+
blockType: BlockType.COMMAND,
44+
text: 'draw [FRAME] on matrix',
45+
func: 'matrixDraw',
46+
arguments: {
47+
FRAME: {
48+
type: ArgumentType.MATRIX,
49+
defaultValue: '0101010101100010101000100'
50+
}
51+
}
52+
}
53+
]
54+
};
55+
}
56+
57+
ArduinoBasics.prototype.matrixDraw = function (args) {
58+
console.log(`Drawing frame on matrix: ${args}`);
59+
this.io.emit("matrix_draw", { frame: args.FRAME });
60+
};
61+
62+
module.exports = ArduinoBasics;

scratch-arduino-extensions/packages/scratch-vm/src/extensions/scratch3_arduino/index.js renamed to scratch-arduino-extensions/packages/scratch-vm/src/extensions/arduino_modulino/index.js

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// const formatMessage = require('../../../../../../scratch-editor/node_modules/format-message');
21
const BlockType = require('../../../../../../scratch-editor/packages/scratch-vm/src/extension-support/block-type');
32
const ArgumentType = require('../../../../../../scratch-editor/packages/scratch-vm/src/extension-support/argument-type');
4-
const io = require('./socket.io.min.js');
3+
const io = require('../socket.io.min.js');
4+
55

66
/**
77
* Url of icon to be displayed at the left edge of each extension block.
@@ -19,7 +19,7 @@ const menuIconURI = ''
1919

2020
const wsServerURL = `${window.location.protocol}//${window.location.hostname}:7000`;
2121

22-
class Scratch3Arduino {
22+
class ArduinoModulino {
2323
constructor(runtime) {
2424
this.runtime = runtime;
2525
this.io = io(wsServerURL, {
@@ -37,25 +37,13 @@ class Scratch3Arduino {
3737
}
3838
};
3939

40-
Scratch3Arduino.prototype.getInfo = function () {
40+
ArduinoModulino.prototype.getInfo = function () {
4141
return {
42-
id: 'arduino',
43-
name: "Arduino",
42+
id: 'arduinomodulino',
43+
name: "Arduino Modulino",
4444
menuIconURI: menuIconURI,
4545
blockIconURI: iconURI,
4646
blocks: [
47-
{
48-
opcode: 'matrixDraw',
49-
blockType: BlockType.COMMAND,
50-
text: 'draw [FRAME] on matrix',
51-
func: 'matrixDraw',
52-
arguments: {
53-
FRAME: {
54-
type: ArgumentType.MATRIX,
55-
defaultValue: '0101010101100010101000100'
56-
}
57-
}
58-
},
5947
{
6048
opcode: 'whenModulinoButtonsPressed',
6149
blockType: BlockType.HAT,
@@ -76,17 +64,12 @@ Scratch3Arduino.prototype.getInfo = function () {
7664
};
7765
}
7866

79-
Scratch3Arduino.prototype.matrixDraw = function (args) {
80-
console.log(`Drawing frame on matrix: ${args}`);
81-
this.io.emit("matrix_draw", { frame: args.FRAME });
82-
};
83-
84-
Scratch3Arduino.prototype.whenModulinoButtonsPressed = function (args) {
67+
ArduinoModulino.prototype.whenModulinoButtonsPressed = function (args) {
8568
if (args.BTN === this._button_pressed) {
8669
this._button_pressed = '';
8770
return true;
8871
}
8972
return false;
9073
};
9174

92-
module.exports = Scratch3Arduino;
75+
module.exports = ArduinoModulino;

scratch-arduino-extensions/scripts/patch-gui.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ const path = require("path");
22
const fs = require("fs");
33

44
const extensions = [
5-
{ name: "Scratch3Arduino", directory: "scratch3_arduino" },
5+
{ name: "ArduinoBasics", directory: "arduino_basics" },
6+
{ name: "ArduinoModulino", directory: "arduino_modulino" }
67
];
78

89
// base dir is the 'scratch-arduino-extensions' folder
910
const BaseDir = path.resolve(__dirname, "../");
1011

1112
extensions.forEach(extension => {
12-
console.log(`${extension.name} (${extension.directory})`);
13+
console.log(`\n${extension.name} (${extension.directory})`);
1314

1415
process.stdout.write("\t - add symbolic link: ");
1516
const scratchVmExtensionsDir = path.resolve(BaseDir,"../scratch-editor/packages/scratch-vm/src/extensions",extension.directory);
@@ -39,8 +40,8 @@ extensions.forEach(extension => {
3940
if (!vmCode.includes(extension.name)) {
4041
fs.copyFileSync(scratchVmVirtualMachineFile, `${scratchVmVirtualMachineFile}.orig`);
4142
vmCode = vmCode.replace(
42-
/CORE_EXTENSIONS = \[[\s\S]*?\];/,
43-
`$&\n\nCORE_EXTENSIONS.push('${extension.name}');`,
43+
/(CORE_EXTENSIONS = \[[\s\S]*?)\];/,
44+
`$1'${extension.name}',\n];`,
4445
);
4546
fs.writeFileSync(scratchVmVirtualMachineFile, vmCode);
4647
process.stdout.write("done\n");

0 commit comments

Comments
 (0)