feat: add muted option (#7714)

* feat: add muted option

* fix: linter

* Update core/workspace_audio.ts

Co-authored-by: Beka Westberg <bwestberg@google.com>

* Update core/workspace_audio.ts

Co-authored-by: Beka Westberg <bwestberg@google.com>

* Update core/workspace_audio.ts

Co-authored-by: Beka Westberg <bwestberg@google.com>

* Update core/workspace_audio.ts

Co-authored-by: Beka Westberg <bwestberg@google.com>

---------

Co-authored-by: Beka Westberg <bwestberg@google.com>
This commit is contained in:
truongductri01
2024-01-11 23:35:09 +07:00
committed by GitHub
parent 187e4cc3d7
commit 7243b48d47

View File

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