add sound category
This commit is contained in:
parent
a214faadf0
commit
9456498417
4 changed files with 40 additions and 1 deletions
|
|
@ -8,6 +8,9 @@
|
|||
<block type="control_default" />
|
||||
<block type="control_break" />
|
||||
</category>
|
||||
<category name="Sound" colour="#CF63CF">
|
||||
<block type="sound_startsound" />
|
||||
</category>
|
||||
<category name="Sensing" colour="#5CB1D6">
|
||||
<block type="sensing_keypress" />
|
||||
</category>
|
||||
|
|
|
|||
34
src/resources/blocks/sound.js
Normal file
34
src/resources/blocks/sound.js
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import javascriptGenerator from '../javascriptGenerator';
|
||||
import registerBlock from '../register';
|
||||
import { compileVars } from '../compiler/compileVarSection.js'
|
||||
|
||||
const categoryPrefix = 'sound_';
|
||||
const categoryColor = '#CF63CF';
|
||||
|
||||
function register() {
|
||||
// start playing a sound (and also it needs to load lol!!)
|
||||
registerBlock(`${categoryPrefix}startsound`, {
|
||||
message0: 'start sound %1',
|
||||
args0: [
|
||||
{
|
||||
"type": "field_input",
|
||||
"name": "SOUND",
|
||||
"value": "https://www.myinstants.com/media/sounds/extra-reverb-fard-noise.mp3",
|
||||
"spellcheck": false
|
||||
},
|
||||
],
|
||||
previousStatement: null,
|
||||
nextStatement: null,
|
||||
inputsInline: true,
|
||||
colour: categoryColor,
|
||||
}, (block) => {
|
||||
const SOUND = block.getFieldValue('SOUND')
|
||||
const code = `var ${compileVars.new()} = new Audio(\`${encodeURI(SOUND)}\`);
|
||||
${compileVars.new()}.addEventListener("canplaythrough", (event) => {
|
||||
${compileVars.new()}.play();
|
||||
});`;
|
||||
return `${code}\n`;
|
||||
})
|
||||
}
|
||||
|
||||
export default register;
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
const throwAwayVars = {}; // used for repeat loops
|
||||
const compileVars = {};
|
||||
export const compileVars = {};
|
||||
compileVars._idx = 0;
|
||||
compileVars.new = () => {
|
||||
const _listLow = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@
|
|||
import registerCore from "../resources/blocks/core.js";
|
||||
import registerControl from "../resources/blocks/control.js";
|
||||
import registerSensing from "../resources/blocks/sensing.js";
|
||||
import registerSound from "../resources/blocks/sound.js";
|
||||
import registerLiterals from "../resources/blocks/literals.js";
|
||||
import registerOperators from "../resources/blocks/operators.js";
|
||||
import registerVariables from "../resources/blocks/variables.js";
|
||||
|
|
@ -61,6 +62,7 @@
|
|||
|
||||
registerCore();
|
||||
registerControl();
|
||||
registerSound();
|
||||
registerSensing();
|
||||
registerLiterals();
|
||||
registerOperators();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue