diff --git a/source/TextBlade.ConsoleRunner/Game.cs b/source/TextBlade.ConsoleRunner/Game.cs index eb9185a..092a6b8 100644 --- a/source/TextBlade.ConsoleRunner/Game.cs +++ b/source/TextBlade.ConsoleRunner/Game.cs @@ -1,4 +1,5 @@ -using Spectre.Console; +using System.Media; +using Spectre.Console; using TextBlade.ConsoleRunner.IO; using TextBlade.Core.Characters; using TextBlade.Core.Commands; @@ -14,21 +15,34 @@ namespace TextBlade.ConsoleRunner; /// public class Game : IGame { + // Don't kill the messenger. I swear, it's bad enough this only works on Windows. + private const string SupportedAudioExtension = "wav"; + private Location _currentLocation = null!; private bool _isRunning = true; private List _party = new(); private Inventory _inventory = new(); + // TODO: investigate something cross-platform with minimal OS-specific dependencies. + // NAudio, System.Windows.Extensions, etc. are all Windows-only. Sigh. + private SoundPlayer _backgroundAudioPlayer = new(); + public static IGame Current { get; private set; } public Game() { Current = this; + _backgroundAudioPlayer.LoadCompleted += (sender, args) => _backgroundAudioPlayer.PlayLooping(); } + /// + /// Called whenever a location changes. Sleeping in an inn, descending a dungeon, do NOT trigger this. + /// + /// public void SetLocation(Location location) { _currentLocation = location; + PlayBackgroundAudio(); } public void Run() @@ -130,4 +144,16 @@ private void UnpackLocationSpecificdata(SaveData data) dungeon.SetState(floorNumber, isClear); } } + + private void PlayBackgroundAudio() + { + _backgroundAudioPlayer.Stop(); + if (string.IsNullOrWhiteSpace(_currentLocation.BackgroundAudio)) + { + return; + } + + _backgroundAudioPlayer.SoundLocation = Path.Join("Content", "Audio", $"{_currentLocation.BackgroundAudio}.{SupportedAudioExtension}"); + _backgroundAudioPlayer.Load(); + } } diff --git a/source/TextBlade.ConsoleRunner/TextBlade.ConsoleRunner.csproj b/source/TextBlade.ConsoleRunner/TextBlade.ConsoleRunner.csproj index c324712..48552eb 100644 --- a/source/TextBlade.ConsoleRunner/TextBlade.ConsoleRunner.csproj +++ b/source/TextBlade.ConsoleRunner/TextBlade.ConsoleRunner.csproj @@ -18,6 +18,7 @@ + diff --git a/source/TextBlade.Core/Locations/BaseLocation.cs b/source/TextBlade.Core/Locations/BaseLocation.cs index 377a87b..0a8d315 100644 --- a/source/TextBlade.Core/Locations/BaseLocation.cs +++ b/source/TextBlade.Core/Locations/BaseLocation.cs @@ -7,6 +7,7 @@ public abstract class BaseLocation { public string Name { get; set; } public string Description { get; set; } + public string BackgroundAudio { get; set; } = string.Empty; /// /// For custom code, this is the class name of the code-behind class for this location. diff --git a/source/VoidWalker.Main/Content/Audio/seagulls.wav b/source/VoidWalker.Main/Content/Audio/seagulls.wav new file mode 100644 index 0000000..8483391 Binary files /dev/null and b/source/VoidWalker.Main/Content/Audio/seagulls.wav differ diff --git a/source/VoidWalker.Main/VoidWalker.Main.csproj b/source/VoidWalker.Main/VoidWalker.Main.csproj index 0d7ed30..18713e0 100644 --- a/source/VoidWalker.Main/VoidWalker.Main.csproj +++ b/source/VoidWalker.Main/VoidWalker.Main.csproj @@ -22,13 +22,17 @@ - - + + - + + + + +