Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 68 additions & 4 deletions extensions/Lily/SoundExpanded.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

const vm = Scratch.vm;
const runtime = vm.runtime;
const soundCategory = runtime.ext_scratch3_sound;

Check warning on line 12 in extensions/Lily/SoundExpanded.js

View workflow job for this annotation

GitHub Actions / type-warnings

Type warning - may indicate a bug - ignore if no bug

Property 'ext_scratch3_sound' does not exist on type 'Runtime'.

class SoundExpanded {
getInfo() {
Expand Down Expand Up @@ -179,6 +179,18 @@
},
extensions: ["colours_sounds"],
},
{
opcode: "stopAllSpriteSounds",
blockType: Scratch.BlockType.COMMAND,
text: Scratch.translate("stop all sounds in [TARGET]"),
arguments: {
TARGET: {
type: Scratch.ArgumentType.STRING,
menu: "preciseTargets",
},
},
extensions: ["colours_sounds"],
},
{
opcode: "pauseSounds",
blockType: Scratch.BlockType.COMMAND,
Expand Down Expand Up @@ -307,6 +319,10 @@
acceptReporters: true,
items: "_getTargets",
},
preciseTargets: {
acceptReporters: true,
items: "_getPreciseTargets",
},
},
};
}
Expand Down Expand Up @@ -496,6 +512,37 @@
soundBank.stop(target, soundId);
}

stopAllSpriteSounds(args, util) {
const targets = [];
switch (args.TARGET) {
case "_myself_":
targets.push(util.target);
break;
case "_stage_":
targets.push(runtime.getTargetForStage());
break;
case "_myfamily_":
targets.push(...util.target.sprite.clones);
break;
default:
targets.push(runtime.getSpriteTargetByName(args.TARGET));
}

for (const target of targets) {
if (!target) continue;

const sprite = target.sprite;
const soundBank = sprite.soundBank;

const allSounds = Object.values(soundBank.soundPlayers);
for (const sound of allSounds) {
if (sound.isPlaying) {
soundBank.stop(target, sound.id);
}
}
}
}

pauseSounds(args, util) {
this._toggleSoundState(args, util, true);
}
Expand Down Expand Up @@ -611,15 +658,32 @@
return n - Math.floor((n - min) / range) * range;
}

_populateTargetMenu() {
const targets = Scratch.vm.runtime.targets
.filter((target) => target.isOriginal && !target.isStage)
.map((target) => target.getName());

return targets;
}

_getTargets() {
let spriteNames = [
{ text: "myself", value: "_myself_" },
{ text: "Stage", value: "_stage_" },
];
const targets = Scratch.vm.runtime.targets
.filter((target) => target.isOriginal && !target.isStage)
.map((target) => target.getName());
spriteNames = spriteNames.concat(targets);

spriteNames = spriteNames.concat(this._populateTargetMenu());

Check warning on line 675 in extensions/Lily/SoundExpanded.js

View workflow job for this annotation

GitHub Actions / type-warnings

Type warning - may indicate a bug - ignore if no bug

No overload matches this call. Overload 1 of 2, '(...items: ConcatArray<{ text: string; value: string; }>[]): { text: string; value: string; }[]', gave the following error. Argument of type 'string[]' is not assignable to parameter of type 'ConcatArray<{ text: string; value: string; }>'. The types returned by 'slice(...)' are incompatible between these types. Type 'string[]' is not assignable to type '{ text: string; value: string; }[]'. Type 'string' is not assignable to type '{ text: string; value: string; }'. Overload 2 of 2, '(...items: ({ text: string; value: string; } | ConcatArray<{ text: string; value: string; }>)[]): { text: string; value: string; }[]', gave the following error. Argument of type 'string[]' is not assignable to parameter of type '{ text: string; value: string; } | ConcatArray<{ text: string; value: string; }>'. Type 'string[]' is not assignable to type 'ConcatArray<{ text: string; value: string; }>'. The types returned by 'slice(...)' are incompatible between these types. Type 'string[]' is not assignable to type '{ text: string; value: string; }[]'. Type 'string' is not assignable to type '{ text: string; value: string; }'.
return spriteNames;
}

_getPreciseTargets() {
let spriteNames = [
{ text: "myself", value: "_myself_" },
{ text: "myself and clones", value: "_myfamily_" },
{ text: "Stage", value: "_stage_" },
];

spriteNames = spriteNames.concat(this._populateTargetMenu());

Check warning on line 686 in extensions/Lily/SoundExpanded.js

View workflow job for this annotation

GitHub Actions / type-warnings

Type warning - may indicate a bug - ignore if no bug

No overload matches this call. Overload 1 of 2, '(...items: ConcatArray<{ text: string; value: string; }>[]): { text: string; value: string; }[]', gave the following error. Argument of type 'string[]' is not assignable to parameter of type 'ConcatArray<{ text: string; value: string; }>'. The types returned by 'slice(...)' are incompatible between these types. Type 'string[]' is not assignable to type '{ text: string; value: string; }[]'. Type 'string' is not assignable to type '{ text: string; value: string; }'. Overload 2 of 2, '(...items: ({ text: string; value: string; } | ConcatArray<{ text: string; value: string; }>)[]): { text: string; value: string; }[]', gave the following error. Argument of type 'string[]' is not assignable to parameter of type '{ text: string; value: string; } | ConcatArray<{ text: string; value: string; }>'. Type 'string[]' is not assignable to type 'ConcatArray<{ text: string; value: string; }>'. The types returned by 'slice(...)' are incompatible between these types. Type 'string[]' is not assignable to type '{ text: string; value: string; }[]'. Type 'string' is not assignable to type '{ text: string; value: string; }'.
return spriteNames;
}
}
Expand Down