mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-24 06:52:40 -05:00
Draft of goforce blocks
This commit is contained in:
parent
ad6f15bfa1
commit
26067a9287
2 changed files with 193 additions and 1 deletions
|
@ -17,6 +17,7 @@ const Scratch3VideoSensingBlocks = require('../extensions/scratch3_video_sensing
|
|||
const Scratch3Speech2TextBlocks = require('../extensions/scratch3_speech2text');
|
||||
const Scratch3Ev3Blocks = require('../extensions/scratch3_ev3');
|
||||
const Scratch3MakeyMakeyBlocks = require('../extensions/scratch3_makeymakey');
|
||||
const Scratch3GoForceBlocks = require('../extensions/scratch3_goforce');
|
||||
|
||||
const builtinExtensions = {
|
||||
pen: Scratch3PenBlocks,
|
||||
|
@ -28,7 +29,8 @@ const builtinExtensions = {
|
|||
videoSensing: Scratch3VideoSensingBlocks,
|
||||
speech2text: Scratch3Speech2TextBlocks,
|
||||
ev3: Scratch3Ev3Blocks,
|
||||
makeymakey: Scratch3MakeyMakeyBlocks
|
||||
makeymakey: Scratch3MakeyMakeyBlocks,
|
||||
goforce: Scratch3GoForceBlocks
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
190
src/extensions/scratch3_goforce/index.js
Normal file
190
src/extensions/scratch3_goforce/index.js
Normal file
|
@ -0,0 +1,190 @@
|
|||
const ArgumentType = require('../../extension-support/argument-type');
|
||||
const BlockType = require('../../extension-support/block-type');
|
||||
const log = require('../../util/log');
|
||||
const cast = require('../../util/cast');
|
||||
const formatMessage = require('format-message');
|
||||
const BLE = require('../../io/ble');
|
||||
const Base64Util = require('../../util/base64-util');
|
||||
|
||||
/**
|
||||
* Icon png to be displayed at the left edge of each extension block, encoded as a data URI.
|
||||
* @type {string}
|
||||
*/
|
||||
// eslint-disable-next-line max-len
|
||||
const blockIconURI = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFAAAABQCAYAAACOEfKtAAAACXBIWXMAABYlAAAWJQFJUiTwAAAKcElEQVR42u2cfXAU9RnHv7u3L3d7l9yR5PIGXO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41BVmSUIn+toAKIUTJskKoQUknCxKlkISKb/sM0NMyyVAhXW+AlYosfgOgQlUJVadTSUWBKoQoudvPioPbenq5oIUTaRUqenhWKi3oyVIUqKpKREoLggDhF6hQb4CV9LRM9rctMPN6glChp2SdTqeSskwoAECSKnG61fzFR/XsGu+FhmONriYl7TImsjoYKJyZSeB8CoBQo6spqU8TCO1fgE7gDVUNoCYaQA2gBlADqAHURAOoAdQAagA10QCOgfwfNp/hXbfBMCAAAAAASUVORK5CYII=';
|
||||
|
||||
const CompareOptionsMenu = ['>', '<', '='];
|
||||
|
||||
const DirectionOptionsMenu = ['x', 'y', 'z'];
|
||||
|
||||
|
||||
/**
|
||||
* Scratch 3.0 blocks to interact with a GoForce peripheral.
|
||||
*/
|
||||
class Scratch3GoForceBlocks {
|
||||
|
||||
/**
|
||||
* Construct a set of GoForce blocks.
|
||||
* @param {Runtime} runtime - the Scratch 3.0 runtime.
|
||||
*/
|
||||
constructor (runtime) {
|
||||
/**
|
||||
* The Scratch 3.0 runtime.
|
||||
* @type {Runtime}
|
||||
*/
|
||||
this.runtime = runtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns {object} metadata for this extension and its blocks.
|
||||
*/
|
||||
getInfo () {
|
||||
return {
|
||||
id: Scratch3GoForceBlocks.EXTENSION_ID,
|
||||
name: Scratch3GoForceBlocks.EXTENSION_NAME,
|
||||
blockIconURI: blockIconURI,
|
||||
showStatusButton: true,
|
||||
blocks: [
|
||||
{
|
||||
opcode: 'whenAccelerationCompare',
|
||||
text: formatMessage({
|
||||
id: 'ev3.whenAccelerationCompare',
|
||||
default: 'when acceleration [DIRECTION] [COMPARE] [VALUE] m/s\u{00B2}',
|
||||
description: 'when the value measured by the acceleration sensor is compared to some value'
|
||||
}),
|
||||
blockType: BlockType.HAT,
|
||||
arguments: {
|
||||
DIRECTION: {
|
||||
type: ArgumentType.STRING,
|
||||
menu: 'directionOptions',
|
||||
defaultValue: 0
|
||||
},
|
||||
COMPARE: {
|
||||
type: ArgumentType.STRING,
|
||||
menu: 'compareOptions',
|
||||
defaultValue: 0
|
||||
},
|
||||
VALUE: {
|
||||
type: ArgumentType.NUMBER,
|
||||
defaultValue: 5
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
opcode: 'whenTiltCompare',
|
||||
text: formatMessage({
|
||||
id: 'ev3.whenTitleCompare',
|
||||
default: 'when tilt [DIRECTION] [COMPARE] [VALUE] rad/s',
|
||||
description: 'when the value measured by the acceleration sensor is compared to some value'
|
||||
}),
|
||||
blockType: BlockType.HAT,
|
||||
arguments: {
|
||||
DIRECTION: {
|
||||
type: ArgumentType.STRING,
|
||||
menu: 'directionOptions',
|
||||
defaultValue: 0
|
||||
},
|
||||
COMPARE: {
|
||||
type: ArgumentType.STRING,
|
||||
menu: 'compareOptions',
|
||||
defaultValue: 0
|
||||
},
|
||||
VALUE: {
|
||||
type: ArgumentType.NUMBER,
|
||||
defaultValue: 5
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
opcode: 'whenForceCompare',
|
||||
text: formatMessage({
|
||||
id: 'ev3.whenForceCompare',
|
||||
default: 'when force [COMPARE] [VALUE] N',
|
||||
description: 'when the value measured by the force sensor is compared to some value'
|
||||
}),
|
||||
blockType: BlockType.HAT,
|
||||
arguments: {
|
||||
COMPARE: {
|
||||
type: ArgumentType.STRING,
|
||||
menu: 'compareOptions',
|
||||
defaultValue: 0
|
||||
},
|
||||
VALUE: {
|
||||
type: ArgumentType.NUMBER,
|
||||
defaultValue: 5
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
opcode: 'getAcceleration',
|
||||
text: formatMessage({
|
||||
id: 'ev3.getAcceleration',
|
||||
default: 'acceleration [DIRECTION]',
|
||||
description: 'gets acceleration'
|
||||
}),
|
||||
blockType: BlockType.REPORTER,
|
||||
arguments: {
|
||||
DIRECTION: {
|
||||
type: ArgumentType.STRING,
|
||||
menu: 'directionOptions',
|
||||
defaultValue: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
opcode: 'getTilt',
|
||||
text: formatMessage({
|
||||
id: 'ev3.getTitle',
|
||||
default: 'tilt [DIRECTION]',
|
||||
description: 'gets tilt'
|
||||
}),
|
||||
blockType: BlockType.REPORTER,
|
||||
arguments: {
|
||||
DIRECTION: {
|
||||
type: ArgumentType.STRING,
|
||||
menu: 'directionOptions',
|
||||
defaultValue: 0
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
opcode: 'getForce',
|
||||
text: formatMessage({
|
||||
id: 'ev3.getForce',
|
||||
default: 'force',
|
||||
description: 'gets force'
|
||||
}),
|
||||
blockType: BlockType.REPORTER
|
||||
}
|
||||
],
|
||||
menus: {
|
||||
directionOptions: this._formatMenu(DirectionOptionsMenu),
|
||||
compareOptions: this._formatMenu(CompareOptionsMenu),
|
||||
motorPorts: this._formatMenu(Ev3MotorMenu),
|
||||
sensorPorts: this._formatMenu(Ev3SensorMenu)
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
whenAccelerationCompare (args) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
whenTiltCompare (args) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
whenForceCompare (args) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
getAcceleration (args) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
getTilt (args) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
getForce (args) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = Scratch3GoForceBlocks;
|
Loading…
Reference in a new issue