- added volume setting for sighting hits

This commit is contained in:
2025-10-17 16:12:02 +01:00
parent 3eb539fd9d
commit 82b84dc46e
14 changed files with 145 additions and 59 deletions

View File

@@ -7,13 +7,10 @@ type SoundContextType = {
audioArmed: boolean;
};
export const SoundContext = createContext<SoundContextType | undefined>(
undefined
);
export const SoundContext = createContext<SoundContextType | undefined>(undefined);
export const useSoundContext = () => {
const ctx = useContext(SoundContext);
if (!ctx)
throw new Error("useSoundContext must be used within <SoundContext>");
if (!ctx) throw new Error("useSoundContext must be used within <SoundContext>");
return ctx;
};

View File

@@ -1,11 +1,4 @@
import {
useEffect,
useMemo,
useReducer,
useRef,
useState,
type ReactNode,
} from "react";
import { useEffect, useMemo, useReducer, useRef, useState, type ReactNode } from "react";
import { SoundContext } from "../SoundContext";
import { initialState, reducer } from "../reducers/SoundContextReducer";
import { useCameraBlackboard } from "../../hooks/useCameraBlackboard";
@@ -27,7 +20,6 @@ const SoundContextProvider = ({ children }: SoundContextProviderProps) => {
operation: "VIEW",
path: "soundSettings",
});
dispatch({ type: "UPDATE", payload: result.result });
};
fetchSound();
@@ -63,13 +55,8 @@ const SoundContextProvider = ({ children }: SoundContextProviderProps) => {
};
}, []);
const value = useMemo(
() => ({ state, dispatch, audioArmed }),
[state, audioArmed]
);
return (
<SoundContext.Provider value={value}>{children}</SoundContext.Provider>
);
const value = useMemo(() => ({ state, dispatch, audioArmed }), [state, audioArmed]);
return <SoundContext.Provider value={value}>{children}</SoundContext.Provider>;
};
export default SoundContextProvider;

View File

@@ -13,6 +13,9 @@ export const initialState: SoundState = {
{ name: "Shutter", soundFile: "shutter" },
{ name: "Warning (voice)", soundFile: "warning" },
],
sightingVolume: 1,
NPEDsoundVolume: 1,
hotlistSoundVolume: 1,
};
export function reducer(state: SoundState, action: SoundAction): SoundState {
@@ -35,6 +38,18 @@ export function reducer(state: SoundState, action: SoundAction): SoundState {
soundOptions: [...(state.soundOptions ?? []), action.payload],
};
}
// todo: refactor to use single state coupled with sound name. e.g : {name: <soundname>, volume: <volume>}
case "SIGHTINGVOLUME":
return {
...state,
sightingVolume: action.payload,
};
case "NPEDVOLUME":
return {
...state,
NPEDsoundVolume: action.payload,
};
default:
return state;