Skip to content

Commit

Permalink
fix blockly sound effects (#9746)
Browse files Browse the repository at this point in the history
  • Loading branch information
riknoll authored Oct 26, 2023
1 parent 4faef75 commit 980db66
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions localtypings/pxtarget.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ declare namespace pxt {
condenseProfile?: boolean; // if set, will make the profile dialog smaller
cloudProfileIcon?: string; // the file path for added imagery on smaller profile dialogs
timeMachine?: boolean; // Save/restore old versions of a project experiment
blocklySoundVolume?: number; // A number between 0 and 1 that sets the volume for blockly sounds (e.g. connect, disconnect, click)
}

interface DownloadDialogTheme {
Expand Down
14 changes: 13 additions & 1 deletion webapp/src/blocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,19 @@ export class Editor extends toolboxeditor.ToolboxEditor {

const oldAudioPlay = (Blockly as any).WorkspaceAudio.prototype.play;
(Blockly as any).WorkspaceAudio.prototype.play = function (name: string, opt_volume?: number) {
if (editor && editor.parent.state.mute) opt_volume = 0;
const themeVolume = pxt.appTarget?.appTheme?.blocklySoundVolume;

if (editor?.parent.state.mute === pxt.editor.MuteState.Muted) {
opt_volume = 0;
}
else if (themeVolume != undefined) {
if (opt_volume != undefined) {
opt_volume *= themeVolume;
}
else {
opt_volume = themeVolume;
}
}
oldAudioPlay.call(this, name, opt_volume);
};
}
Expand Down

0 comments on commit 980db66

Please sign in to comment.