Skip to content

Commit

Permalink
Update SfxPlayer to take ConfigurationProvider as a dependency. Coupl…
Browse files Browse the repository at this point in the history
…es configuration value check to playing of a given sound effect.
  • Loading branch information
ethanmoffat committed May 17, 2022
1 parent 110887c commit f195251
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions EndlessClient/Audio/SfxPlayer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using AutomaticTypeMapper;
using EndlessClient.Content;
using EOLib.Config;
using Microsoft.Xna.Framework.Audio;
using System;

Expand All @@ -9,37 +10,44 @@ namespace EndlessClient.Audio
public sealed class SfxPlayer : ISfxPlayer
{
private readonly IContentProvider _contentProvider;
private readonly IConfigurationProvider _configurationProvider;

private SoundEffectInstance _loopingSfx;

public SfxPlayer(IContentProvider contentProvider)
public SfxPlayer(IContentProvider contentProvider,
IConfigurationProvider configurationProvider)
{
_contentProvider = contentProvider;
_configurationProvider = configurationProvider;
}

public void PlaySfx(SoundEffectID id)
{
if (!_configurationProvider.SoundEnabled)
return;

_contentProvider.SFX[id].Play();
}

public void PlayHarpNote(int index)
{
if (index < 0 || index >= _contentProvider.HarpNotes.Count)
if (!_configurationProvider.SoundEnabled || index < 0 || index >= _contentProvider.HarpNotes.Count)
return;

_contentProvider.HarpNotes[index].Play();
}

public void PlayGuitarNote(int index)
{
if (index < 0 || index >= _contentProvider.GuitarNotes.Count)
if (!_configurationProvider.SoundEnabled || index < 0 || index >= _contentProvider.GuitarNotes.Count)
return;

_contentProvider.GuitarNotes[index].Play();
}

public void PlayLoopingSfx(SoundEffectID id)
{
if (_loopingSfx != null && _loopingSfx.State != SoundState.Stopped)
if (!_configurationProvider.SoundEnabled || (_loopingSfx != null && _loopingSfx.State != SoundState.Stopped))
return;

StopLoopingSfx();
Expand Down

0 comments on commit f195251

Please sign in to comment.