Static settings wrapper for local game preferences. Stores music and sfx volumes and a reduce-strobe accessibility flag, persists them to engine cookies, applies music volume on change, and exposes derived accessibility scales.
namespace NoChillquarium;
/// <summary>
/// Lightweight local prefs. Cookie-backed so volumes survive restarts.
/// </summary>
public static class GameSettings
{
const string CookieMusic = "nochill.music_vol";
const string CookieSfx = "nochill.sfx_vol";
const string CookieStrobe = "nochill.reduce_strobe";
static float _musicVolume = 0.55f;
static float _sfxVolume = 0.85f;
static bool _reduceStrobe;
public static float MusicVolume
{
get => _musicVolume;
set
{
_musicVolume = Clamp01( value );
WriteCookie( CookieMusic, _musicVolume.ToString( "0.###" ) );
GameAudio.ApplyMusicVolume();
}
}
public static float SfxVolume
{
get => _sfxVolume;
set
{
_sfxVolume = Clamp01( value );
WriteCookie( CookieSfx, _sfxVolume.ToString( "0.###" ) );
}
}
public static bool ReduceStrobe
{
get => _reduceStrobe;
set
{
_reduceStrobe = value;
WriteCookie( CookieStrobe, value ? "1" : "0" );
}
}
/// <summary>Multiplies screen shake when accessibility is on.</summary>
public static float ShakeScale => _reduceStrobe ? 0.18f : 1f;
/// <summary>Multiplies red/white flash overlays when accessibility is on.</summary>
public static float FlashScale => _reduceStrobe ? 0.22f : 1f;
/// <summary>Softens frantic CSS pulse classes when accessibility is on.</summary>
public static bool SoftFx => _reduceStrobe;
public static void Load()
{
if ( float.TryParse( ReadCookie( CookieMusic, "0.55" ), out var music ) )
_musicVolume = Clamp01( music );
if ( float.TryParse( ReadCookie( CookieSfx, "0.85" ), out var sfx ) )
_sfxVolume = Clamp01( sfx );
_reduceStrobe = ReadCookie( CookieStrobe, "0" ) == "1";
}
static float Clamp01( float v ) => v < 0f ? 0f : (v > 1f ? 1f : v);
static string ReadCookie( string key, string fallback )
{
try
{
#pragma warning disable CS0618 // Cookie → Game.Cookies migration; keep working on current editor
return Cookie.Get( key, fallback ) ?? fallback;
#pragma warning restore CS0618
}
catch
{
return fallback;
}
}
static void WriteCookie( string key, string value )
{
try
{
#pragma warning disable CS0618
Cookie.Set( key, value );
#pragma warning restore CS0618
}
catch
{
// In-memory only if cookies unavailable.
}
}
}