Add support for hiding music tracks.
This commit is contained in:
committed by
Paul Chote
parent
21254db120
commit
1d80c37fda
@@ -15,8 +15,10 @@ namespace OpenRA.GameRules
|
|||||||
{
|
{
|
||||||
public class MusicInfo
|
public class MusicInfo
|
||||||
{
|
{
|
||||||
public readonly string Filename = null;
|
public readonly string Filename;
|
||||||
public readonly string Title = null;
|
public readonly string Title;
|
||||||
|
public readonly bool Hidden;
|
||||||
|
|
||||||
public int Length { get; private set; } // seconds
|
public int Length { get; private set; } // seconds
|
||||||
public bool Exists { get; private set; }
|
public bool Exists { get; private set; }
|
||||||
|
|
||||||
@@ -25,17 +27,23 @@ namespace OpenRA.GameRules
|
|||||||
Title = value.Value;
|
Title = value.Value;
|
||||||
|
|
||||||
var nd = value.ToDictionary();
|
var nd = value.ToDictionary();
|
||||||
|
if (nd.ContainsKey("Hidden"))
|
||||||
|
bool.TryParse(nd["Hidden"].Value, out Hidden);
|
||||||
|
|
||||||
var ext = nd.ContainsKey("Extension") ? nd["Extension"].Value : "aud";
|
var ext = nd.ContainsKey("Extension") ? nd["Extension"].Value : "aud";
|
||||||
Filename = (nd.ContainsKey("Filename") ? nd["Filename"].Value : key) + "." + ext;
|
Filename = (nd.ContainsKey("Filename") ? nd["Filename"].Value : key) + "." + ext;
|
||||||
|
|
||||||
if (!GlobalFileSystem.Exists(Filename))
|
if (!GlobalFileSystem.Exists(Filename))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Exists = true;
|
Exists = true;
|
||||||
using (var s = GlobalFileSystem.Open(Filename))
|
using (var s = GlobalFileSystem.Open(Filename))
|
||||||
|
{
|
||||||
if (Filename.ToLowerInvariant().EndsWith("wav"))
|
if (Filename.ToLowerInvariant().EndsWith("wav"))
|
||||||
Length = (int)WavLoader.WaveLength(s);
|
Length = (int)WavLoader.WaveLength(s);
|
||||||
else
|
else
|
||||||
Length = (int)AudLoader.SoundLength(s);
|
Length = (int)AudLoader.SoundLength(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Reload()
|
public void Reload()
|
||||||
@@ -45,10 +53,12 @@ namespace OpenRA.GameRules
|
|||||||
|
|
||||||
Exists = true;
|
Exists = true;
|
||||||
using (var s = GlobalFileSystem.Open(Filename))
|
using (var s = GlobalFileSystem.Open(Filename))
|
||||||
|
{
|
||||||
if (Filename.ToLowerInvariant().EndsWith("wav"))
|
if (Filename.ToLowerInvariant().EndsWith("wav"))
|
||||||
Length = (int)WavLoader.WaveLength(s);
|
Length = (int)WavLoader.WaveLength(s);
|
||||||
else
|
else
|
||||||
Length = (int)AudLoader.SoundLength(s);
|
Length = (int)AudLoader.SoundLength(s);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ namespace OpenRA.Traits
|
|||||||
readonly MusicInfo[] random;
|
readonly MusicInfo[] random;
|
||||||
readonly MusicInfo[] playlist;
|
readonly MusicInfo[] playlist;
|
||||||
|
|
||||||
|
public readonly bool IsMusicInstalled;
|
||||||
public readonly bool IsMusicAvailable;
|
public readonly bool IsMusicAvailable;
|
||||||
public bool CurrentSongIsBackground { get; private set; }
|
public bool CurrentSongIsBackground { get; private set; }
|
||||||
|
|
||||||
@@ -52,13 +53,17 @@ namespace OpenRA.Traits
|
|||||||
this.info = info;
|
this.info = info;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
|
|
||||||
IsMusicAvailable = world.Map.Rules.InstalledMusic.Any();
|
IsMusicInstalled = world.Map.Rules.InstalledMusic.Any();
|
||||||
|
if (!IsMusicInstalled)
|
||||||
playlist = world.Map.Rules.InstalledMusic.Select(a => a.Value).ToArray();
|
|
||||||
|
|
||||||
if (!IsMusicAvailable)
|
|
||||||
return;
|
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();
|
random = playlist.Shuffle(Game.CosmeticRandom).ToArray();
|
||||||
|
|
||||||
// Always start with a random song
|
// Always start with a random song
|
||||||
@@ -100,9 +105,6 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public void GameOver(World world)
|
public void GameOver(World world)
|
||||||
{
|
{
|
||||||
if (!IsMusicAvailable)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (world.LocalPlayer != null && world.LocalPlayer.WinState == WinState.Won)
|
if (world.LocalPlayer != null && world.LocalPlayer.WinState == WinState.Won)
|
||||||
{
|
{
|
||||||
if (SongExists(info.VictoryMusic))
|
if (SongExists(info.VictoryMusic))
|
||||||
@@ -125,7 +127,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
void Play()
|
void Play()
|
||||||
{
|
{
|
||||||
if (!SongExists(currentSong) || !IsMusicAvailable)
|
if (!SongExists(currentSong))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Sound.PlayMusicThen(currentSong, () =>
|
Sound.PlayMusicThen(currentSong, () =>
|
||||||
@@ -139,7 +141,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public void Play(MusicInfo music)
|
public void Play(MusicInfo music)
|
||||||
{
|
{
|
||||||
if (music == null || !IsMusicAvailable)
|
if (music == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
currentSong = music;
|
currentSong = music;
|
||||||
@@ -150,7 +152,7 @@ namespace OpenRA.Traits
|
|||||||
|
|
||||||
public void Play(MusicInfo music, Action onComplete)
|
public void Play(MusicInfo music, Action onComplete)
|
||||||
{
|
{
|
||||||
if (music == null || !IsMusicAvailable)
|
if (music == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
currentSong = music;
|
currentSong = music;
|
||||||
|
|||||||
Reference in New Issue
Block a user