Let the game determine song length.
This commit is contained in:
@@ -102,6 +102,20 @@ namespace OpenRA.FileFormats
|
|||||||
return output;
|
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)
|
public static byte[] LoadSound(Stream s)
|
||||||
{
|
{
|
||||||
var br = new BinaryReader(s);
|
var br = new BinaryReader(s);
|
||||||
|
|||||||
@@ -14,15 +14,21 @@ namespace OpenRA.GameRules
|
|||||||
{
|
{
|
||||||
public class MusicInfo
|
public class MusicInfo
|
||||||
{
|
{
|
||||||
[FieldLoader.Load] public readonly string Filename = null;
|
public readonly string Filename = null;
|
||||||
[FieldLoader.Load] public readonly string Title = null;
|
public readonly string Title = null;
|
||||||
[FieldLoader.Load] public readonly int Length = 0; // seconds
|
public readonly int Length = 0; // seconds
|
||||||
|
public readonly bool Exists = false;
|
||||||
|
|
||||||
public MusicInfo( string key, MiniYaml value )
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,12 +86,9 @@ namespace OpenRA.Widgets.Delegates
|
|||||||
var itemTemplate = ml.GetWidget<LabelWidget>("MUSIC_TEMPLATE");
|
var itemTemplate = ml.GetWidget<LabelWidget>("MUSIC_TEMPLATE");
|
||||||
int offset = itemTemplate.Bounds.Y;
|
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;
|
var song = kv.Key;
|
||||||
if (!FileSystem.Exists(Rules.Music[song].Filename))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (CurrentSong == null)
|
if (CurrentSong == null)
|
||||||
CurrentSong = song;
|
CurrentSong = song;
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1 @@
|
|||||||
aoi:
|
aoi: Act on Instinct
|
||||||
Title: Act on Instinct
|
|
||||||
Length: 0
|
|
||||||
@@ -1,83 +1,21 @@
|
|||||||
await_r:
|
await_r: Afterlife
|
||||||
Title: Afterlife
|
bigf226m: Bigfoot
|
||||||
Length: 0
|
credits: End Credits
|
||||||
|
crus226m: Crush
|
||||||
bigf225m:
|
dense_r: Dense
|
||||||
Title: Bigfoot
|
fac1226m: Face to the Enemy 1
|
||||||
Length: 0
|
fac2226m: Face to the Enemy 2
|
||||||
|
fogger1a: Fogger
|
||||||
credits:
|
hell226m: Hell March
|
||||||
Title: End Credits
|
mud1a: Mud
|
||||||
Length: 0
|
radio2: Radio 2
|
||||||
|
rollout: Roll Out
|
||||||
crus226m:
|
run1226m: Run for your Life
|
||||||
Title: Crush
|
score: Mission Accomplished
|
||||||
Length: 0
|
smsh226m: Smash
|
||||||
|
snake: Snake
|
||||||
dense_r:
|
terminat: Terminate
|
||||||
Title: Dense
|
tren226m: Trenches
|
||||||
Length: 0
|
twin: Twin
|
||||||
|
vector1a: Vector
|
||||||
fac1225m:
|
work226m: Workmen
|
||||||
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
|
|
||||||
Reference in New Issue
Block a user