add sound category

This commit is contained in:
sussy layers dev 2023-11-09 21:10:21 +00:00 committed by GitHub
commit 9456498417
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 1 deletions

View file

@ -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>

View 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;

View file

@ -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'];

View file

@ -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();