From 7243b48d47f35f6669f243e16711baa8173a6580 Mon Sep 17 00:00:00 2001 From: truongductri01 <58579187+truongductri01@users.noreply.github.com> Date: Thu, 11 Jan 2024 23:35:09 +0700 Subject: [PATCH] feat: add muted option (#7714) * feat: add muted option * fix: linter * Update core/workspace_audio.ts Co-authored-by: Beka Westberg * Update core/workspace_audio.ts Co-authored-by: Beka Westberg * Update core/workspace_audio.ts Co-authored-by: Beka Westberg * Update core/workspace_audio.ts Co-authored-by: Beka Westberg --------- Co-authored-by: Beka Westberg --- core/workspace_audio.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/workspace_audio.ts b/core/workspace_audio.ts index 9f4dc54fe..c2ab93222 100644 --- a/core/workspace_audio.ts +++ b/core/workspace_audio.ts @@ -31,6 +31,9 @@ export class WorkspaceAudio { /** Time that the last sound was played. */ private lastSound_: Date | null = null; + /** Whether the audio is muted or not. */ + private muted: boolean = false; + /** * @param parentWorkspace The parent of the workspace this audio object * belongs to, or null. @@ -121,6 +124,9 @@ export class WorkspaceAudio { * @param opt_volume Volume of sound (0-1). */ play(name: string, opt_volume?: number) { + if (this.muted) { + return; + } const sound = this.sounds.get(name); if (sound) { // Don't play one sound on top of another. @@ -148,4 +154,18 @@ export class WorkspaceAudio { this.parentWorkspace.getAudioManager().play(name, opt_volume); } } + + /** + * @param muted If true, mute sounds. Otherwise, play them. + */ + setMuted(muted: boolean) { + this.muted = muted; + } + + /** + * @returns Whether the audio is currently muted or not. + */ + getMuted(): boolean { + return this.muted; + } }