Half of having choices of music and a player of it (not finished)

This commit is contained in:
alzeih
2010-05-05 23:06:42 +12:00
parent acf55f1bb0
commit 30ee0afdc0
7 changed files with 88 additions and 6 deletions

View File

@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using OpenRA.FileFormats;
namespace OpenRA.GameRules
{
public class MusicInfo
{
public readonly Lazy<Dictionary<string, MusicPool>> Pools;
public readonly string[] Music = { };
public MusicInfo( MiniYaml y )
{
FieldLoader.Load(this, y);
Pools = Lazy.New(() =>
new Dictionary<string, MusicPool>
{
{ "Music", new MusicPool(Music) },
});
}
}
public class MusicPool
{
readonly string[] clips;
readonly List<string> liveclips = new List<string>();
public MusicPool(params string[] clips)
{
this.clips = clips;
}
public string GetNext()
{
if (liveclips.Count == 0)
liveclips.AddRange(clips);
if (liveclips.Count == 0)
return null; /* avoid crashing if there's no clips at all */
var i = Game.CosmeticRandom.Next(liveclips.Count);
var s = liveclips[i];
liveclips.RemoveAt(i);
return s;
}
}
}

View File

@@ -33,6 +33,7 @@ namespace OpenRA
public static Dictionary<string, ActorInfo> Info;
public static Dictionary<string, WeaponInfo> Weapons;
public static Dictionary<string, VoiceInfo> Voices;
public static Dictionary<string, MusicInfo> Music;
public static Dictionary<TerrainType, TerrainCost> TerrainTypes;
public static void LoadRules(Manifest m)
@@ -44,6 +45,7 @@ namespace OpenRA
Info = LoadYamlRules(m.Rules, (k, y) => new ActorInfo(k.Key.ToLowerInvariant(), k.Value, y));
Weapons = LoadYamlRules(m.Weapons, (k, _) => new WeaponInfo(k.Key.ToLowerInvariant(), k.Value));
Voices = LoadYamlRules(m.Voices, (k, _) => new VoiceInfo(k.Value));
Music = LoadYamlRules(m.Music, (k, _) => new MusicInfo(k.Value));
TerrainTypes = LoadYamlRules(m.Terrain, (k, _) => new TerrainCost(k.Value))
.ToDictionary(kv => (TerrainType)Enum.Parse(typeof(TerrainType), kv.Key, true), kv => kv.Value);