diff --git a/OpenRA.Game/Graphics/ChromeProvider.cs b/OpenRA.Game/Graphics/ChromeProvider.cs index 26a8fe1a2e..767529eac8 100644 --- a/OpenRA.Game/Graphics/ChromeProvider.cs +++ b/OpenRA.Game/Graphics/ChromeProvider.cs @@ -11,12 +11,10 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Xml; using OpenRA.FileFormats; namespace OpenRA.Graphics { - public static class ChromeProvider { struct Collection @@ -34,11 +32,14 @@ namespace OpenRA.Graphics collections = new Dictionary(); cachedSheets = new Dictionary(); cachedSprites = new Dictionary>(); - - foreach (var f in chromeFiles) - LoadChromeSource(f); - Save("foo.yaml"); + if (chromeFiles.Length == 0) + return; + + var chrome = chromeFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.Merge); + + foreach (var c in chrome) + LoadCollection(c.Key, c.Value); } public static void Save(string file) @@ -59,24 +60,16 @@ namespace OpenRA.Graphics return new MiniYaml(collection.src, root); } - static void LoadChromeSource(string filename) + static void LoadCollection(string name, MiniYaml yaml) { - XmlDocument document = new XmlDocument(); - document.Load(FileSystem.Open(filename)); - foreach (XmlElement eCollection in document.SelectNodes("/chrome/collection")) - LoadChromeForCollection(eCollection); - } - - static void LoadChromeForCollection(XmlElement eCollection) - { - string elementName = eCollection.GetAttribute("name"); - string defaultSrc = (eCollection.HasAttribute("src") ? eCollection.GetAttribute("src") : null); - - var images = eCollection.SelectNodes("./image").OfType() - .Select(e => new MappedImage(defaultSrc, e)) - .ToDictionary(s => s.Name); + Game.modData.LoadScreen.Display(); + var collection = new Collection() + { + src = yaml.Value, + regions = yaml.Nodes.ToDictionary(n => n.Key, n => new MappedImage(yaml.Value, n.Value)) + }; - collections.Add(elementName, new Collection() {src = defaultSrc, regions = images}); + collections.Add(name, collection); } public static Sprite GetImage(string collection, string image) @@ -92,15 +85,15 @@ namespace OpenRA.Graphics throw new InvalidOperationException( "Collection `{0}` does not have an image `{1}`".F(collection, image)); } - + // Cached sheet Sheet sheet; - if (cachedSheets.ContainsKey(mi.Src)) - sheet = cachedSheets[mi.Src]; + if (cachedSheets.ContainsKey(mi.src)) + sheet = cachedSheets[mi.src]; else { - sheet = new Sheet(mi.Src); - cachedSheets.Add(mi.Src, sheet); + sheet = new Sheet(mi.src); + cachedSheets.Add(mi.src, sheet); } // Cache the sprite diff --git a/OpenRA.Game/Graphics/MappedImage.cs b/OpenRA.Game/Graphics/MappedImage.cs index b96c52c4e1..b956c718b2 100644 --- a/OpenRA.Game/Graphics/MappedImage.cs +++ b/OpenRA.Game/Graphics/MappedImage.cs @@ -18,27 +18,15 @@ namespace OpenRA.Graphics { class MappedImage { - public readonly Rectangle rect; - public readonly string Src; - public readonly string Name; + public readonly Rectangle rect = Rectangle.Empty; + public readonly string src; - public MappedImage(string defaultSrc, XmlElement e) - { - Src = (e.HasAttribute("src")) ? e.GetAttribute("src") : defaultSrc; - Name = e.GetAttribute("name"); - if (Src == null) - throw new InvalidDataException("Image src missing"); - - rect = new Rectangle(int.Parse(e.GetAttribute("x")), - int.Parse(e.GetAttribute("y")), - int.Parse(e.GetAttribute("width")), - int.Parse(e.GetAttribute("height"))); - } - public MappedImage(string defaultSrc, MiniYaml info) { - Src = defaultSrc; + FieldLoader.LoadField(this, "rect", info.Value); FieldLoader.Load(this, info); + if (src == null) + src = defaultSrc; } public Sprite GetImage(Sheet s) @@ -49,8 +37,8 @@ namespace OpenRA.Graphics public MiniYaml Save(string defaultSrc) { var root = new List(); - if (defaultSrc != Src) - root.Add(new MiniYamlNode("src", Src)); + if (defaultSrc != src) + root.Add(new MiniYamlNode("src", src)); return new MiniYaml(FieldSaver.FormatValue( this, this.GetType().GetField("rect") ), root); } diff --git a/mods/cnc/chrome.xml b/mods/cnc/chrome.xml deleted file mode 100644 index 66086c8446..0000000000 --- a/mods/cnc/chrome.xml +++ /dev/null @@ -1,220 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index b44b8dbd3c..db2be992d7 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -49,7 +49,7 @@ Cursors: mods/cnc/cursors.yaml Chrome: - mods/cnc/chrome.xml + mods/cnc/chrome.yaml Assemblies: mods/ra/OpenRA.Mods.RA.dll diff --git a/mods/ra/chrome.xml b/mods/ra/chrome.xml deleted file mode 100644 index 98aac6e173..0000000000 --- a/mods/ra/chrome.xml +++ /dev/null @@ -1,220 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index ca23fe1d7f..dbed326fb8 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -45,7 +45,7 @@ Cursors: mods/ra/cursors.yaml Chrome: - mods/ra/chrome.xml + mods/ra/chrome.yaml Assemblies: mods/ra/OpenRA.Mods.RA.dll