Add ability to adjust sound effect volume.

This commit is contained in:
Half-Shot
2024-11-07 16:35:37 +00:00
committed by Robin
parent 1df2e0c48f
commit 7b57fc2942
5 changed files with 48 additions and 2 deletions

View File

@@ -8,12 +8,17 @@ Please see LICENSE in the repository root for full details.
import { ReactNode, useEffect, useRef } from "react";
import { useReactions } from "../useReactions";
import { playReactionsSound, useSetting } from "../settings/settings";
import {
playReactionsSound,
effectSoundVolume as effectSoundVolumeSetting,
useSetting,
} from "../settings/settings";
import { GenericReaction, ReactionSet } from "../reactions";
export function ReactionsAudioRenderer(): ReactNode {
const { reactions } = useReactions();
const [shouldPlay] = useSetting(playReactionsSound);
const [effectSoundVolume] = useSetting(effectSoundVolumeSetting);
const audioElements = useRef<Record<string, HTMLAudioElement | null>>({});
useEffect(() => {
@@ -30,6 +35,7 @@ export function ReactionsAudioRenderer(): ReactNode {
const audioElement =
audioElements.current[reactionName] ?? audioElements.current.generic;
if (audioElement?.paused) {
audioElement.volume = effectSoundVolume;
void audioElement.play();
}
}