Let the game determine song length.

This commit is contained in:
Paul Chote
2010-09-10 20:24:22 +12:00
parent b8ed9d7da5
commit 190311c68c
5 changed files with 49 additions and 96 deletions

View File

@@ -102,6 +102,20 @@ namespace OpenRA.FileFormats
return output;
}
public static float SoundLength(Stream s)
{
var br = new BinaryReader(s);
var sampleRate = br.ReadUInt16();
/*var dataSize = */ br.ReadInt32();
var outputSize = br.ReadInt32();
var flags = (SoundFlags) br.ReadByte();
var samples = outputSize;
if (0 != (flags & SoundFlags.Stereo)) samples /= 2;
if (0 != (flags & SoundFlags._16Bit)) samples /= 2;
return samples / sampleRate;
}
public static byte[] LoadSound(Stream s)
{
var br = new BinaryReader(s);

View File

@@ -14,15 +14,21 @@ namespace OpenRA.GameRules
{
public class MusicInfo
{
[FieldLoader.Load] public readonly string Filename = null;
[FieldLoader.Load] public readonly string Title = null;
[FieldLoader.Load] public readonly int Length = 0; // seconds
public readonly string Filename = null;
public readonly string Title = null;
public readonly int Length = 0; // seconds
public readonly bool Exists = false;
public MusicInfo( string key, MiniYaml value )
{
FieldLoader.Load(this, value);
if (Filename == null)
Filename = key+".aud";
Filename = key+".aud";
Title = value.Value;
if (!FileSystem.Exists(Filename))
return;
Exists = true;
Length = (int)AudLoader.SoundLength(FileSystem.Open(Filename));
}
}
}

View File

@@ -86,12 +86,9 @@ namespace OpenRA.Widgets.Delegates
var itemTemplate = ml.GetWidget<LabelWidget>("MUSIC_TEMPLATE");
int offset = itemTemplate.Bounds.Y;
foreach (var kv in Rules.Music)
foreach (var kv in Rules.Music.Where(m => m.Value.Exists))
{
var song = kv.Key;
if (!FileSystem.Exists(Rules.Music[song].Filename))
continue;
if (CurrentSong == null)
CurrentSong = song;

View File

@@ -1,3 +1 @@
aoi:
Title: Act on Instinct
Length: 0
aoi: Act on Instinct

View File

@@ -1,83 +1,21 @@
await_r:
Title: Afterlife
Length: 0
bigf225m:
Title: Bigfoot
Length: 0
credits:
Title: End Credits
Length: 0
crus226m:
Title: Crush
Length: 0
dense_r:
Title: Dense
Length: 0
fac1225m:
Title: Face to the Enemy 1
Length: 0
fac2226m:
Title: Face to the Enemy 2
Length: 0
fogger1a:
Title: Fogger
Length: 0
hell225m:
Title: Hell March
Length: 0
mud1a:
Title: Mud
Length: 0
radio2:
Title: Radio 2
Length: 0
rollout:
Title: Roll Out
Length: 0
run1225m:
Title: Run for your Life
Length: 0
score:
Title: Mission Accomplished
Length: 0
smsh225m:
Title: Smash
Length: 0
snake:
Title: Snake
Length: 0
terminat:
Title: Terminate
Length: 0
tren226m:
Title: Trenches
Length: 0
twin:
Title: Twin
Length: 0
vector1a:
Title: Vector
Length: 0
work226m:
Title: Workmen
Length: 0
await_r: Afterlife
bigf226m: Bigfoot
credits: End Credits
crus226m: Crush
dense_r: Dense
fac1226m: Face to the Enemy 1
fac2226m: Face to the Enemy 2
fogger1a: Fogger
hell226m: Hell March
mud1a: Mud
radio2: Radio 2
rollout: Roll Out
run1226m: Run for your Life
score: Mission Accomplished
smsh226m: Smash
snake: Snake
terminat: Terminate
tren226m: Trenches
twin: Twin
vector1a: Vector
work226m: Workmen