diff --git a/OpenRA.Game/GameRules/MusicInfo.cs b/OpenRA.Game/GameRules/MusicInfo.cs index 68ee8c63f7..dd91bed550 100644 --- a/OpenRA.Game/GameRules/MusicInfo.cs +++ b/OpenRA.Game/GameRules/MusicInfo.cs @@ -32,21 +32,9 @@ namespace OpenRA.GameRules 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() + public void Load() { if (!GlobalFileSystem.Exists(Filename)) return; diff --git a/OpenRA.Game/GameRules/RulesetCache.cs b/OpenRA.Game/GameRules/RulesetCache.cs index b7cc7bd044..f2c26e6506 100644 --- a/OpenRA.Game/GameRules/RulesetCache.cs +++ b/OpenRA.Game/GameRules/RulesetCache.cs @@ -80,7 +80,7 @@ namespace OpenRA using (new PerfTimer("Music")) music = LoadYamlRules(musicCache, m.Music, - NoMapRules, + map != null ? map.MusicDefinitions : NoMapRules, (k, _) => new MusicInfo(k.Key, k.Value)); using (new PerfTimer("TileSets")) diff --git a/OpenRA.Game/Map/Map.cs b/OpenRA.Game/Map/Map.cs index e3da9d8192..9df9e0d5eb 100644 --- a/OpenRA.Game/Map/Map.cs +++ b/OpenRA.Game/Map/Map.cs @@ -18,6 +18,7 @@ using System.Linq; using System.Security.Cryptography; using System.Text; using OpenRA.FileSystem; +using OpenRA.GameRules; using OpenRA.Graphics; using OpenRA.Network; using OpenRA.Support; @@ -228,6 +229,7 @@ namespace OpenRA [FieldLoader.Ignore] public List VoxelSequenceDefinitions = new List(); [FieldLoader.Ignore] public List WeaponDefinitions = new List(); [FieldLoader.Ignore] public List VoiceDefinitions = new List(); + [FieldLoader.Ignore] public List MusicDefinitions = new List(); [FieldLoader.Ignore] public List NotificationDefinitions = new List(); [FieldLoader.Ignore] public List TranslationDefinitions = new List(); [FieldLoader.Ignore] public List PlayerDefinitions = new List(); @@ -360,6 +362,7 @@ namespace OpenRA VoxelSequenceDefinitions = MiniYaml.NodesOrEmpty(yaml, "VoxelSequences"); WeaponDefinitions = MiniYaml.NodesOrEmpty(yaml, "Weapons"); VoiceDefinitions = MiniYaml.NodesOrEmpty(yaml, "Voices"); + MusicDefinitions = MiniYaml.NodesOrEmpty(yaml, "Music"); NotificationDefinitions = MiniYaml.NodesOrEmpty(yaml, "Notifications"); TranslationDefinitions = MiniYaml.NodesOrEmpty(yaml, "Translations"); PlayerDefinitions = MiniYaml.NodesOrEmpty(yaml, "Players"); @@ -572,6 +575,7 @@ namespace OpenRA root.Add(new MiniYamlNode("VoxelSequences", null, VoxelSequenceDefinitions)); root.Add(new MiniYamlNode("Weapons", null, WeaponDefinitions)); root.Add(new MiniYamlNode("Voices", null, VoiceDefinitions)); + root.Add(new MiniYamlNode("Music", null, MusicDefinitions)); root.Add(new MiniYamlNode("Notifications", null, NotificationDefinitions)); root.Add(new MiniYamlNode("Translations", null, TranslationDefinitions)); diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index fa4713552d..b326a2cf36 100644 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -171,6 +171,11 @@ namespace OpenRA using (new Support.PerfTimer("Map.SequenceProvider.Preload")) map.SequenceProvider.Preload(); + // Load music with map assets mounted + using (new Support.PerfTimer("Map.Music")) + foreach (var entry in map.Rules.Music) + entry.Value.Load(); + VoxelProvider.Initialize(Manifest.VoxelSequences, map.VoxelSequenceDefinitions); VoxelLoader.Finish(); diff --git a/OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs b/OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs index 0955a66988..a9292fca8d 100644 --- a/OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs +++ b/OpenRA.Mods.Common/Scripting/Global/MediaGlobal.cs @@ -15,6 +15,7 @@ using Eluant; using OpenRA.Effects; using OpenRA.FileFormats; using OpenRA.FileSystem; +using OpenRA.GameRules; using OpenRA.Graphics; using OpenRA.Mods.Common.Effects; using OpenRA.Mods.Common.Traits; @@ -55,14 +56,22 @@ namespace OpenRA.Mods.Common.Scripting } Action onComplete; - [Desc("Play track defined in music.yaml or keep it empty for a random song.")] + [Desc("Play track defined in music.yaml or map.yaml, or keep track empty for playing a random song.")] public void PlayMusic(string track = null, LuaFunction func = null) { if (!playlist.IsMusicAvailable) return; - var musicInfo = !string.IsNullOrEmpty(track) ? world.Map.Rules.Music[track] - : playlist.GetNextSong(); + MusicInfo musicInfo; + if (string.IsNullOrEmpty(track)) + musicInfo = playlist.GetNextSong(); + else if (world.Map.Rules.Music.ContainsKey(track)) + musicInfo = world.Map.Rules.Music[track]; + else + { + Log.Write("lua", "Missing music track: " + track); + return; + } if (func != null) { diff --git a/mods/ra/audio/music.yaml b/mods/ra/audio/music.yaml index 60db69296f..9bb0a7b636 100644 --- a/mods/ra/audio/music.yaml +++ b/mods/ra/audio/music.yaml @@ -44,7 +44,3 @@ float_v2: Floating grndwire: Ground Wire search: The Search wastelnd: Wasteland - -# Special effects -rain: Rain (ambient) - Hidden: true \ No newline at end of file diff --git a/mods/ra/maps/fort-lonestar/map.yaml b/mods/ra/maps/fort-lonestar/map.yaml index 5c5244cc8c..4544cc283a 100644 --- a/mods/ra/maps/fort-lonestar/map.yaml +++ b/mods/ra/maps/fort-lonestar/map.yaml @@ -20,6 +20,10 @@ Type: Minigame Videos: +Music: + rain: Rain (ambient) + Hidden: true + Options: Fog: True Shroud: True diff --git a/mods/ra/bits/rain.aud b/mods/ra/maps/fort-lonestar/rain.aud similarity index 100% rename from mods/ra/bits/rain.aud rename to mods/ra/maps/fort-lonestar/rain.aud diff --git a/mods/ra/bits/thunder-ambient.aud b/mods/ra/maps/fort-lonestar/thunder-ambient.aud similarity index 100% rename from mods/ra/bits/thunder-ambient.aud rename to mods/ra/maps/fort-lonestar/thunder-ambient.aud diff --git a/mods/ra/bits/thunder1.aud b/mods/ra/maps/fort-lonestar/thunder1.aud similarity index 100% rename from mods/ra/bits/thunder1.aud rename to mods/ra/maps/fort-lonestar/thunder1.aud diff --git a/mods/ra/bits/thunder2.aud b/mods/ra/maps/fort-lonestar/thunder2.aud similarity index 100% rename from mods/ra/bits/thunder2.aud rename to mods/ra/maps/fort-lonestar/thunder2.aud diff --git a/mods/ra/bits/thunder3.aud b/mods/ra/maps/fort-lonestar/thunder3.aud similarity index 100% rename from mods/ra/bits/thunder3.aud rename to mods/ra/maps/fort-lonestar/thunder3.aud diff --git a/mods/ra/bits/thunder4.aud b/mods/ra/maps/fort-lonestar/thunder4.aud similarity index 100% rename from mods/ra/bits/thunder4.aud rename to mods/ra/maps/fort-lonestar/thunder4.aud diff --git a/mods/ra/bits/thunder5.aud b/mods/ra/maps/fort-lonestar/thunder5.aud similarity index 100% rename from mods/ra/bits/thunder5.aud rename to mods/ra/maps/fort-lonestar/thunder5.aud