mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-06-11 21:11:10 -04:00
Merge 79df2a0ddc
into 9acb2c6ea3
This commit is contained in:
commit
ad5d4bb93b
2 changed files with 195 additions and 1 deletions
src
|
@ -23,7 +23,9 @@ const builtinExtensions = {
|
|||
ev3: () => require('../extensions/scratch3_ev3'),
|
||||
makeymakey: () => require('../extensions/scratch3_makeymakey'),
|
||||
boost: () => require('../extensions/scratch3_boost'),
|
||||
gdxfor: () => require('../extensions/scratch3_gdx_for')
|
||||
gdxfor: () => require('../extensions/scratch3_gdx_for'),
|
||||
myScratchExtension: () => require('../extensions/scratch3_myExtension'),
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
192
src/extensions/scratch3_myExtension/index.js
Normal file
192
src/extensions/scratch3_myExtension/index.js
Normal file
|
@ -0,0 +1,192 @@
|
|||
const BlockType = require('../../extension-support/block-type');
|
||||
const ArgumentType = require('../../extension-support/argument-type');
|
||||
const TargetType = require('../../extension-support/target-type');
|
||||
|
||||
class Scratch3myExtension {
|
||||
|
||||
constructor (runtime) {
|
||||
// put any setup for your extension here
|
||||
this.runtime = runtime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the metadata about your extension.
|
||||
*/
|
||||
getInfo () {
|
||||
return {
|
||||
// unique ID for your extension
|
||||
id: 'myScratchExtension',
|
||||
|
||||
// name that will be displayed in the Scratch UI
|
||||
name: 'wifi car',
|
||||
|
||||
// colours to use for your extension blocks
|
||||
color1: '#2088e8',
|
||||
color2: '#660066',
|
||||
|
||||
// icons to display
|
||||
// blockIconURI: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAFCAAAAACyOJm3AAAAFklEQVQYV2P4DwMMEMgAI/+DEUIMBgAEWB7i7uidhAAAAABJRU5ErkJggg==',
|
||||
// menuIconURI: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAkAAAAFCAAAAACyOJm3AAAAFklEQVQYV2P4DwMMEMgAI/+DEUIMBgAEWB7i7uidhAAAAABJRU5ErkJggg==',
|
||||
|
||||
// your Scratch blocks
|
||||
blocks: [
|
||||
{
|
||||
|
||||
opcode: 'cameraUp',
|
||||
|
||||
|
||||
blockType: BlockType.COMMAND,
|
||||
|
||||
// label to display on the block
|
||||
text: 'Camera up',
|
||||
|
||||
|
||||
filter: [ TargetType.SPRITE, TargetType.STAGE ],
|
||||
|
||||
|
||||
},
|
||||
{
|
||||
|
||||
opcode: 'cameraDown',
|
||||
|
||||
|
||||
blockType: BlockType.COMMAND,
|
||||
|
||||
// label to display on the block
|
||||
text: 'Camera down',
|
||||
|
||||
|
||||
filter: [ TargetType.SPRITE, TargetType.STAGE ],
|
||||
|
||||
|
||||
},
|
||||
|
||||
{
|
||||
|
||||
opcode: 'moveForward',
|
||||
|
||||
|
||||
blockType: BlockType.COMMAND,
|
||||
|
||||
// label to display on the block
|
||||
text: 'move Forward',
|
||||
|
||||
|
||||
filter: [ TargetType.SPRITE, TargetType.STAGE ],
|
||||
|
||||
|
||||
},
|
||||
{
|
||||
|
||||
opcode: 'moveBackward',
|
||||
|
||||
|
||||
blockType: BlockType.COMMAND,
|
||||
|
||||
// label to display on the block
|
||||
text: 'move Backward',
|
||||
|
||||
|
||||
filter: [ TargetType.SPRITE, TargetType.STAGE ],
|
||||
|
||||
|
||||
},
|
||||
{
|
||||
|
||||
opcode: 'rotateLeft',
|
||||
|
||||
|
||||
blockType: BlockType.COMMAND,
|
||||
|
||||
// label to display on the block
|
||||
text: 'rotate Left',
|
||||
|
||||
|
||||
filter: [ TargetType.SPRITE, TargetType.STAGE ],
|
||||
|
||||
|
||||
},
|
||||
{
|
||||
|
||||
opcode: 'rotateRight',
|
||||
|
||||
|
||||
blockType: BlockType.COMMAND,
|
||||
|
||||
// label to display on the block
|
||||
text: 'rotate Right',
|
||||
|
||||
|
||||
filter: [ TargetType.SPRITE, TargetType.STAGE ],
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
]
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* implementation of the block with the opcode that matches this name
|
||||
* this will be called when the block is used
|
||||
*/
|
||||
cameraUp () {
|
||||
|
||||
console.log('working');
|
||||
fetch("http://192.168.4.1/state?cmd=H")
|
||||
.then((response) => response.json())
|
||||
.then((json) => console.log(json));
|
||||
|
||||
|
||||
}
|
||||
|
||||
cameraDown () {
|
||||
|
||||
fetch("http://192.168.4.1/state?cmd=G")
|
||||
.then((response) => response.json())
|
||||
.then((json) => console.log(json));
|
||||
|
||||
|
||||
}
|
||||
|
||||
moveForward () {
|
||||
|
||||
fetch("http://192.168.4.1/state?cmd=F")
|
||||
.then((response) => response.json())
|
||||
.then((json) => console.log(json));
|
||||
|
||||
|
||||
}
|
||||
|
||||
moveBackward () {
|
||||
|
||||
fetch("http://192.168.4.1/state?cmd=B")
|
||||
.then((response) => response.json())
|
||||
.then((json) => console.log(json));
|
||||
|
||||
|
||||
}
|
||||
|
||||
rotateLeft () {
|
||||
|
||||
fetch("http://192.168.4.1/state?cmd=L")
|
||||
.then((response) => response.json())
|
||||
.then((json) => console.log(json));
|
||||
|
||||
|
||||
}
|
||||
|
||||
rotateRight () {
|
||||
|
||||
fetch("http://192.168.4.1/state?cmd=R")
|
||||
.then((response) => response.json())
|
||||
.then((json) => console.log(json));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = Scratch3myExtension;
|
Loading…
Add table
Add a link
Reference in a new issue