diff --git a/OpenRA.FileFormats/Manifest.cs b/OpenRA.FileFormats/Manifest.cs index 6954bb21a7..f18af64b91 100644 --- a/OpenRA.FileFormats/Manifest.cs +++ b/OpenRA.FileFormats/Manifest.cs @@ -19,7 +19,7 @@ namespace OpenRA.FileFormats { public readonly string[] Folders, Packages, Rules, - Sequences, Chrome, Assemblies, ChromeLayout, + Sequences, Cursors, Chrome, Assemblies, ChromeLayout, Weapons, Voices, Music, Movies, TileSets; public readonly string ShellmapUid, LoadScreen; @@ -34,6 +34,7 @@ namespace OpenRA.FileFormats Packages = YamlList(yaml, "Packages"); Rules = YamlList(yaml, "Rules"); Sequences = YamlList(yaml, "Sequences"); + Cursors = YamlList(yaml, "Cursors"); Chrome = YamlList(yaml, "Chrome"); Assemblies = YamlList(yaml, "Assemblies"); ChromeLayout = YamlList(yaml, "ChromeLayout"); diff --git a/OpenRA.Game/Cursor.cs b/OpenRA.Game/Cursor.cs index 10fe06301f..0be3b2bfcb 100644 --- a/OpenRA.Game/Cursor.cs +++ b/OpenRA.Game/Cursor.cs @@ -17,7 +17,7 @@ namespace OpenRA CursorSequence sequence; public Cursor(string cursor) { - sequence = SequenceProvider.GetCursorSequence(cursor); + sequence = CursorProvider.GetCursorSequence(cursor); } public void Draw(int frame, float2 pos) diff --git a/OpenRA.Game/Graphics/CursorProvider.cs b/OpenRA.Game/Graphics/CursorProvider.cs new file mode 100644 index 0000000000..d87b1e57db --- /dev/null +++ b/OpenRA.Game/Graphics/CursorProvider.cs @@ -0,0 +1,67 @@ +#region Copyright & License Information +/* + * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see LICENSE. + */ +#endregion + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Xml; +using OpenRA.FileFormats; + +namespace OpenRA.Graphics +{ + public static class CursorProvider + { + static Dictionary cursors; + + public static void Initialize(string[] sequenceFiles) + { + cursors = new Dictionary(); + + foreach (var f in sequenceFiles) + LoadSequenceSource(f); + } + + static void LoadSequenceSource(string filename) + { + XmlDocument document = new XmlDocument(); + document.Load(FileSystem.Open(filename)); + + foreach (XmlElement eCursor in document.SelectNodes("/sequences/cursor")) + LoadSequencesForCursor(eCursor); + } + + static void LoadSequencesForCursor(XmlElement eCursor) + { + Game.modData.LoadScreen.Display(); + string cursorSrc = eCursor.GetAttribute("src"); + string palette = eCursor.GetAttribute("palette"); + + foreach (XmlElement eSequence in eCursor.SelectNodes("./sequence")) + cursors.Add(eSequence.GetAttribute("name"), new CursorSequence(cursorSrc, palette, eSequence)); + + } + + public static bool HasCursorSequence(string cursor) + { + return cursors.ContainsKey(cursor); + } + + public static CursorSequence GetCursorSequence(string cursor) + { + try { return cursors[cursor]; } + catch (KeyNotFoundException) + { + throw new InvalidOperationException( + "Cursor does not have a sequence `{0}`".F(cursor)); + } + } + } +} diff --git a/OpenRA.Game/Graphics/Sequence.cs b/OpenRA.Game/Graphics/Sequence.cs index d53863ed90..a3a81dcdcf 100644 --- a/OpenRA.Game/Graphics/Sequence.cs +++ b/OpenRA.Game/Graphics/Sequence.cs @@ -27,30 +27,30 @@ namespace OpenRA.Graphics public int Tick { get { return tick; } } string srcOverride; - public Sequence(string unit, XmlElement e) + public Sequence(string unit, string name, MiniYaml info) { - srcOverride = e.GetAttribute("src"); - Name = e.GetAttribute("name"); - + srcOverride = info.Value; + Name = name; + var d = info.NodesDict; + sprites = SpriteSheetBuilder.LoadAllSprites(string.IsNullOrEmpty(srcOverride) ? unit : srcOverride ); - start = int.Parse(e.GetAttribute("start")); + start = int.Parse(d["Start"].Value); - if (e.GetAttribute("length") == "*" || e.GetAttribute("end") == "*") - length = sprites.Length - Start; - else if (e.HasAttribute("length")) - length = int.Parse(e.GetAttribute("length")); - else if (e.HasAttribute("end")) - length = int.Parse(e.GetAttribute("end")) - int.Parse(e.GetAttribute("start")); - else + if (!d.ContainsKey("Length")) length = 1; + else if (d["Length"].Value == "*") + length = sprites.Length - Start; + else + length = int.Parse(d["Length"].Value); - if( e.HasAttribute( "facings" ) ) - facings = int.Parse( e.GetAttribute( "facings" ) ); + + if(d.ContainsKey("Facings")) + facings = int.Parse(d["Facings"].Value); else facings = 1; - if (e.HasAttribute("tick")) - tick = int.Parse(e.GetAttribute("tick")); + if(d.ContainsKey("Tick")) + tick = int.Parse(d["Tick"].Value); else tick = 40; } diff --git a/OpenRA.Game/Graphics/SequenceProvider.cs b/OpenRA.Game/Graphics/SequenceProvider.cs index f5165b837d..7cc5a5beea 100644 --- a/OpenRA.Game/Graphics/SequenceProvider.cs +++ b/OpenRA.Game/Graphics/SequenceProvider.cs @@ -20,54 +20,25 @@ namespace OpenRA.Graphics public static class SequenceProvider { static Dictionary> units; - static Dictionary cursors; public static void Initialize(string[] sequenceFiles) { units = new Dictionary>(); - cursors = new Dictionary(); - foreach (var f in sequenceFiles) - LoadSequenceSource(f); + var sequences = sequenceFiles + .Select(s => MiniYaml.FromFile(s)) + .Aggregate(MiniYaml.Merge); + + foreach (var s in sequences) + LoadSequencesForUnit(s.Key, s.Value); } - static void LoadSequenceSource(string filename) - { - XmlDocument document = new XmlDocument(); - document.Load(FileSystem.Open(filename)); - - var ret = new List(); - foreach (XmlElement eUnit in document.SelectNodes("/sequences/unit")) - LoadSequencesForUnit(eUnit, ret); - - ret.WriteToFile(filename+".yaml"); - - foreach (XmlElement eCursor in document.SelectNodes("/sequences/cursor")) - LoadSequencesForCursor(eCursor); - } - - static void LoadSequencesForCursor(XmlElement eCursor) + static void LoadSequencesForUnit(string unit, MiniYaml sequences) { Game.modData.LoadScreen.Display(); - string cursorSrc = eCursor.GetAttribute("src"); - string palette = eCursor.GetAttribute("palette"); - - foreach (XmlElement eSequence in eCursor.SelectNodes("./sequence")) - cursors.Add(eSequence.GetAttribute("name"), new CursorSequence(cursorSrc, palette, eSequence)); - - } - - static void LoadSequencesForUnit(XmlElement eUnit, List converted) - { - Game.modData.LoadScreen.Display(); - string unitName = eUnit.GetAttribute("name"); try { - var sequences = eUnit.SelectNodes("./sequence").OfType() - .Select(e => new Sequence(unitName, e)) - .ToDictionary(s => s.Name); - - units.Add(unitName, sequences); - converted.Add(new MiniYamlNode(unitName, SaveSequencesForUnit(unitName))); + var seq = sequences.NodesDict.ToDictionary(x => x.Key, x => new Sequence(unit,x.Key,x.Value)); + units.Add(unit, seq); } catch (FileNotFoundException) {} // Do nothing; we can crash later if we actually wanted art } @@ -94,20 +65,5 @@ namespace OpenRA.Graphics { return units[unit].ContainsKey(seq); } - - public static bool HasCursorSequence(string cursor) - { - return cursors.ContainsKey(cursor); - } - - public static CursorSequence GetCursorSequence(string cursor) - { - try { return cursors[cursor]; } - catch (KeyNotFoundException) - { - throw new InvalidOperationException( - "Cursor does not have a sequence `{0}`".F(cursor)); - } - } } } diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index 4282360fa2..406d74aaed 100755 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -66,6 +66,7 @@ namespace OpenRA { SpriteSheetBuilder.Initialize( Rules.TileSets[map.Tileset] ); SequenceProvider.Initialize(Manifest.Sequences); + CursorProvider.Initialize(Manifest.Cursors); cachedTheatre = map.Theater; } return map; diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 93f6dcda84..512a8b1784 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -226,6 +226,7 @@ + diff --git a/OpenRA.Mods.RA/Widgets/RadarBinWidget.cs b/OpenRA.Mods.RA/Widgets/RadarBinWidget.cs index f8eeac65c8..dc7ded73c9 100755 --- a/OpenRA.Mods.RA/Widgets/RadarBinWidget.cs +++ b/OpenRA.Mods.RA/Widgets/RadarBinWidget.cs @@ -79,7 +79,7 @@ namespace OpenRA.Mods.RA.Widgets if (cursor == null) return "default"; - return SequenceProvider.HasCursorSequence(cursor+"-minimap") ? cursor+"-minimap" : cursor; + return CursorProvider.HasCursorSequence(cursor+"-minimap") ? cursor+"-minimap" : cursor; } public override bool HandleInputInner(MouseInput mi) diff --git a/mods/cnc/cursors.xml b/mods/cnc/cursors.xml new file mode 100644 index 0000000000..6ff8a358ca --- /dev/null +++ b/mods/cnc/cursors.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml index 53b8203c3b..5259442f1d 100644 --- a/mods/cnc/mod.yaml +++ b/mods/cnc/mod.yaml @@ -28,11 +28,14 @@ Rules: mods/cnc/civilian.yaml: Civilian structures and bridges Sequences: - mods/cnc/sequences-structures.xml: - mods/cnc/sequences-vehicles.xml: - mods/cnc/sequences-infantry.xml: - mods/cnc/sequences-map.xml: Trees etc - mods/cnc/sequences.xml: Obsolete; will disappear once done converting + mods/cnc/sequences-structures.yaml: + mods/cnc/sequences-vehicles.yaml: + mods/cnc/sequences-infantry.yaml: + mods/cnc/sequences-map.yaml: Trees etc + mods/cnc/sequences.yaml: Obsolete; will disappear once done converting + +Cursors: + mods/cnc/cursors.xml: Chrome: mods/cnc/chrome.xml: diff --git a/mods/cnc/sequences-funpark.xml b/mods/cnc/sequences-funpark.xml deleted file mode 100644 index c434f0a4ae..0000000000 --- a/mods/cnc/sequences-funpark.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/mods/cnc/sequences-infantry.xml b/mods/cnc/sequences-infantry.xml deleted file mode 100644 index ae0afa1470..0000000000 --- a/mods/cnc/sequences-infantry.xml +++ /dev/null @@ -1,229 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/mods/cnc/sequences-map.xml b/mods/cnc/sequences-map.xml deleted file mode 100644 index 1d48c67c83..0000000000 --- a/mods/cnc/sequences-map.xml +++ /dev/null @@ -1,319 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/mods/cnc/sequences-structures.xml b/mods/cnc/sequences-structures.xml deleted file mode 100644 index 9e8ab4cfde..0000000000 --- a/mods/cnc/sequences-structures.xml +++ /dev/null @@ -1,185 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/mods/cnc/sequences-vehicles.xml b/mods/cnc/sequences-vehicles.xml deleted file mode 100644 index 253b8c5e90..0000000000 --- a/mods/cnc/sequences-vehicles.xml +++ /dev/null @@ -1,127 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/mods/cnc/sequences.xml b/mods/cnc/sequences.xml deleted file mode 100644 index 1ed1f2b0fd..0000000000 --- a/mods/cnc/sequences.xml +++ /dev/null @@ -1,168 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/mods/ra/cursors.xml b/mods/ra/cursors.xml new file mode 100644 index 0000000000..c0f1f3b871 --- /dev/null +++ b/mods/ra/cursors.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index 82f9c42625..90ca664e9f 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -33,7 +33,10 @@ Rules: mods/ra/trees.yaml Sequences: - mods/ra/sequences.xml: Original animation sequences + mods/ra/sequences.yaml: Original animation sequences + +Cursors: + mods/ra/cursors.xml: Chrome: mods/ra/chrome.xml: diff --git a/mods/ra/sequences.xml b/mods/ra/sequences.xml deleted file mode 100644 index 911b3c8916..0000000000 --- a/mods/ra/sequences.xml +++ /dev/null @@ -1,988 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file