From f6180d7fa4caacfa0783ae4645a72a77ebf118f4 Mon Sep 17 00:00:00 2001 From: atlimit8 Date: Tue, 29 Sep 2015 15:41:24 -0500 Subject: [PATCH] Include add/replace playlist entries support using map.yaml --- OpenRA.Game/GameRules/RulesetCache.cs | 2 +- OpenRA.Game/Map/Map.cs | 4 ++++ .../Scripting/Global/MediaGlobal.cs | 15 ++++++++++++--- 3 files changed, 17 insertions(+), 4 deletions(-) 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 4ecf69e976..827b157c8f 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.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) {