Files
GameJamDungeon/Zennysoft.Game.Ma.Implementation/Audio/AudioManager.cs
2025-09-08 23:24:33 -07:00

31 lines
1.2 KiB
C#

using Godot;
namespace Zennysoft.Ma.Adapter;
public partial class AudioManager : Node
{
#pragma warning disable IDE0044 // Add readonly modifier
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
private static string _sfxPath = $"res://src/audio/sfx";
private AudioStreamPlayer _audioPlayer;
private IDictionary<SoundEffects, AudioStream> _sfxDictionary;
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
#pragma warning restore IDE0044 // Add readonly modifier
public override void _Ready()
{
_audioPlayer = new AudioStreamPlayer();
_sfxDictionary = new Dictionary<SoundEffects, AudioStream>();
var soundEffects = Enum.GetValues(typeof(SoundEffects));
foreach (var effect in soundEffects)
_sfxDictionary.Add((SoundEffects)effect, GD.Load<AudioStream>(_sfxPath + effect + ".ogg"));
}
public void Play(SoundEffects soundEffect)
{
_sfxDictionary.TryGetValue(soundEffect, out var stream);
_audioPlayer.Stream = stream;
_audioPlayer.Play();
}
}