diff --git a/OpenRA.Game/GameRules/MusicInfo.cs b/OpenRA.Game/GameRules/MusicInfo.cs index d8568ac898..68ee8c63f7 100644 --- a/OpenRA.Game/GameRules/MusicInfo.cs +++ b/OpenRA.Game/GameRules/MusicInfo.cs @@ -15,8 +15,10 @@ namespace OpenRA.GameRules { public class MusicInfo { - public readonly string Filename = null; - public readonly string Title = null; + public readonly string Filename; + public readonly string Title; + public readonly bool Hidden; + public int Length { get; private set; } // seconds public bool Exists { get; private set; } @@ -25,17 +27,23 @@ namespace OpenRA.GameRules Title = value.Value; var nd = value.ToDictionary(); + if (nd.ContainsKey("Hidden")) + bool.TryParse(nd["Hidden"].Value, out Hidden); + var ext = nd.ContainsKey("Extension") ? nd["Extension"].Value : "aud"; Filename = (nd.ContainsKey("Filename") ? nd["Filename"].Value : key) + "." + ext; + if (!GlobalFileSystem.Exists(Filename)) return; Exists = true; using (var s = GlobalFileSystem.Open(Filename)) + { if (Filename.ToLowerInvariant().EndsWith("wav")) Length = (int)WavLoader.WaveLength(s); else Length = (int)AudLoader.SoundLength(s); + } } public void Reload() @@ -45,10 +53,12 @@ namespace OpenRA.GameRules Exists = true; using (var s = GlobalFileSystem.Open(Filename)) + { if (Filename.ToLowerInvariant().EndsWith("wav")) Length = (int)WavLoader.WaveLength(s); else Length = (int)AudLoader.SoundLength(s); + } } } } diff --git a/OpenRA.Game/Traits/World/MusicPlaylist.cs b/OpenRA.Game/Traits/World/MusicPlaylist.cs index babef06050..eb7c3f353c 100644 --- a/OpenRA.Game/Traits/World/MusicPlaylist.cs +++ b/OpenRA.Game/Traits/World/MusicPlaylist.cs @@ -41,6 +41,7 @@ namespace OpenRA.Traits readonly MusicInfo[] random; readonly MusicInfo[] playlist; + public readonly bool IsMusicInstalled; public readonly bool IsMusicAvailable; public bool CurrentSongIsBackground { get; private set; } @@ -52,13 +53,17 @@ namespace OpenRA.Traits this.info = info; this.world = world; - IsMusicAvailable = world.Map.Rules.InstalledMusic.Any(); - - playlist = world.Map.Rules.InstalledMusic.Select(a => a.Value).ToArray(); - - if (!IsMusicAvailable) + IsMusicInstalled = world.Map.Rules.InstalledMusic.Any(); + if (!IsMusicInstalled) return; + playlist = world.Map.Rules.InstalledMusic + .Where(a => !a.Value.Hidden) + .Select(a => a.Value) + .ToArray(); + + IsMusicAvailable = playlist.Any(); + random = playlist.Shuffle(Game.CosmeticRandom).ToArray(); // Always start with a random song @@ -100,9 +105,6 @@ namespace OpenRA.Traits public void GameOver(World world) { - if (!IsMusicAvailable) - return; - if (world.LocalPlayer != null && world.LocalPlayer.WinState == WinState.Won) { if (SongExists(info.VictoryMusic)) @@ -125,7 +127,7 @@ namespace OpenRA.Traits void Play() { - if (!SongExists(currentSong) || !IsMusicAvailable) + if (!SongExists(currentSong)) return; Sound.PlayMusicThen(currentSong, () => @@ -139,7 +141,7 @@ namespace OpenRA.Traits public void Play(MusicInfo music) { - if (music == null || !IsMusicAvailable) + if (music == null) return; currentSong = music; @@ -150,7 +152,7 @@ namespace OpenRA.Traits public void Play(MusicInfo music, Action onComplete) { - if (music == null || !IsMusicAvailable) + if (music == null) return; currentSong = music;