Re-implement audio managers

This commit is contained in:
2025-09-08 23:24:33 -07:00
parent d830a05d98
commit 4f1251d402
185 changed files with 1747 additions and 1673 deletions

View File

@@ -0,0 +1,30 @@
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();
}
}