From 3cb80084a4c1193460e2de440707299a794b4a38 Mon Sep 17 00:00:00 2001 From: LilyMakesThings <127533508+LilyMakesThings@users.noreply.github.com> Date: Mon, 14 Aug 2023 05:06:17 +0100 Subject: [PATCH] Update SoundExpanded.js --- extensions/Lily/SoundExpanded.js | 114 ++++++++++++------------------- 1 file changed, 45 insertions(+), 69 deletions(-) diff --git a/extensions/Lily/SoundExpanded.js b/extensions/Lily/SoundExpanded.js index c8fb17e0da..0b1a3ab0b9 100644 --- a/extensions/Lily/SoundExpanded.js +++ b/extensions/Lily/SoundExpanded.js @@ -26,9 +26,9 @@ name: "Sound Expanded", blocks: [ { - opcode: 'startSoundOnLoop', + opcode: 'startLooping', blockType: Scratch.BlockType.COMMAND, - text: 'start sound [SOUND] on loop', + text: 'start looping [SOUND]', arguments: { SOUND: { type: Scratch.ArgumentType.SOUND @@ -40,22 +40,9 @@ } }, { - opcode: 'stopSound', - blockType: Scratch.BlockType.COMMAND, - text: 'stop sound [SOUND]', - arguments: { - SOUND: { - type: Scratch.ArgumentType.SOUND - } - } - }, - - '---', - - { - opcode: 'pauseSounds', + opcode: 'stopLooping', blockType: Scratch.BlockType.COMMAND, - text: 'pause all sounds', + text: 'end looping [SOUND]', arguments: { SOUND: { type: Scratch.ArgumentType.SOUND @@ -63,9 +50,9 @@ } }, { - opcode: 'resumeSounds', - blockType: Scratch.BlockType.COMMAND, - text: 'resume all sounds', + opcode: 'isLooping', + blockType: Scratch.BlockType.BOOLEAN, + text: '[SOUND] is looping?', arguments: { SOUND: { type: Scratch.ArgumentType.SOUND @@ -76,9 +63,9 @@ '---', { - opcode: 'startLooping', + opcode: 'stopSound', blockType: Scratch.BlockType.COMMAND, - text: 'begin looping [SOUND]', + text: 'stop sound [SOUND]', arguments: { SOUND: { type: Scratch.ArgumentType.SOUND @@ -86,9 +73,9 @@ } }, { - opcode: 'stopLooping', + opcode: 'pauseSounds', blockType: Scratch.BlockType.COMMAND, - text: 'end looping [SOUND]', + text: 'pause all sounds', arguments: { SOUND: { type: Scratch.ArgumentType.SOUND @@ -96,9 +83,9 @@ } }, { - opcode: 'isLooping', - blockType: Scratch.BlockType.BOOLEAN, - text: '[SOUND] is looping?', + opcode: 'resumeSounds', + blockType: Scratch.BlockType.COMMAND, + text: 'resume all sounds', arguments: { SOUND: { type: Scratch.ArgumentType.SOUND @@ -193,23 +180,48 @@ }; } - startSoundOnLoop(args, util) { + startLooping(args, util) { const index = this._getSoundIndex(args.SOUND, util); if (index < 0) return 0; const target = util.target; - const sprite = target.sprite; - const duration = args.START; + const sprite = util.target.sprite; const soundId = sprite.sounds[index].soundId; - soundCategory._addWaitingSound(target.id, soundId); - sprite.soundBank.playSound(util.target, soundId); - const soundPlayer = sprite.soundBank.soundPlayers[soundId]; + if (!soundPlayer.isPlaying) { + soundCategory._addWaitingSound(target.id, soundId); + sprite.soundBank.playSound(util.target, soundId); + } + if (!soundPlayer.outputNode) return; soundPlayer.outputNode.loop = true; } + stopLooping(args, util) { + const index = this._getSoundIndex(args.SOUND, util); + if (index < 0) return false; + const sprite = util.target.sprite; + + const soundId = sprite.sounds[index].soundId; + const soundPlayer = sprite.soundBank.soundPlayers[soundId]; + + if (!soundPlayer.outputNode) return; + soundPlayer.outputNode.loop = false; + } + + isLooping(args, util) { + const index = this._getSoundIndex(args.SOUND, util); + if (index < 0) return false; + const sprite = util.target.sprite; + + const soundId = sprite.sounds[index].soundId; + const soundPlayer = sprite.soundBank.soundPlayers[soundId]; + + if (!soundPlayer.outputNode) return false; + return soundPlayer.outputNode.loop; + } + stopSound(args, util) { const index = this._getSoundIndex(args.SOUND, util); if (index < 0) return 0; @@ -242,42 +254,6 @@ } } - startLooping(args, util) { - const index = this._getSoundIndex(args.SOUND, util); - if (index < 0) return false; - const sprite = util.target.sprite; - - const soundId = sprite.sounds[index].soundId; - const soundPlayer = sprite.soundBank.soundPlayers[soundId]; - - if (!soundPlayer.outputNode) return; - soundPlayer.outputNode.loop = true; - } - - stopLooping(args, util) { - const index = this._getSoundIndex(args.SOUND, util); - if (index < 0) return false; - const sprite = util.target.sprite; - - const soundId = sprite.sounds[index].soundId; - const soundPlayer = sprite.soundBank.soundPlayers[soundId]; - - if (!soundPlayer.outputNode) return; - soundPlayer.outputNode.loop = false; - } - - isLooping(args, util) { - const index = this._getSoundIndex(args.SOUND, util); - if (index < 0) return false; - const sprite = util.target.sprite; - - const soundId = sprite.sounds[index].soundId; - const soundPlayer = sprite.soundBank.soundPlayers[soundId]; - - if (!soundPlayer.outputNode) return false; - return soundPlayer.outputNode.loop; - } - isSoundPlaying(args, util) { const index = this._getSoundIndex(args.SOUND, util); if (index < 0) return false;