From b4d1517d0d4fb2d0e1ccd4a894311c9df19964a6 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 4 Jun 2016 15:18:47 +0100 Subject: [PATCH] Set yaml filename when loading from FileSystem. --- OpenRA.Game/GameRules/Ruleset.cs | 2 +- OpenRA.Game/Graphics/ChromeProvider.cs | 2 +- OpenRA.Game/Graphics/CursorProvider.cs | 2 +- OpenRA.Game/Manifest.cs | 2 +- OpenRA.Game/Map/TileSet.cs | 2 +- OpenRA.Game/MiniYaml.cs | 6 +++--- OpenRA.Game/ModMetadata.cs | 2 +- OpenRA.Game/Widgets/ChromeMetrics.cs | 2 +- OpenRA.Game/Widgets/WidgetLoader.cs | 2 +- OpenRA.Mods.Common/Lint/CheckChromeLogic.cs | 2 +- OpenRA.Mods.Common/UtilityCommands/CheckSequenceSprites.cs | 2 +- OpenRA.Mods.Common/UtilityCommands/ExtractMapRules.cs | 2 +- OpenRA.Mods.Common/UtilityCommands/UpgradeMapCommand.cs | 2 +- OpenRA.Mods.Common/UtilityCommands/UpgradeModCommand.cs | 2 +- OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs | 2 +- 15 files changed, 17 insertions(+), 17 deletions(-) diff --git a/OpenRA.Game/GameRules/Ruleset.cs b/OpenRA.Game/GameRules/Ruleset.cs index db26035a65..b86cc62db3 100644 --- a/OpenRA.Game/GameRules/Ruleset.cs +++ b/OpenRA.Game/GameRules/Ruleset.cs @@ -243,7 +243,7 @@ namespace OpenRA { var mapFiles = FieldLoader.GetValue("value", mapRules.Value); foreach (var f in mapFiles) - if (AnyFlaggedTraits(modData, MiniYaml.FromStream(fileSystem.Open(f)))) + if (AnyFlaggedTraits(modData, MiniYaml.FromStream(fileSystem.Open(f), f))) return true; } } diff --git a/OpenRA.Game/Graphics/ChromeProvider.cs b/OpenRA.Game/Graphics/ChromeProvider.cs index 47f57cacb1..2bd4c815a1 100644 --- a/OpenRA.Game/Graphics/ChromeProvider.cs +++ b/OpenRA.Game/Graphics/ChromeProvider.cs @@ -38,7 +38,7 @@ namespace OpenRA.Graphics cachedSprites = new Dictionary>(); var chrome = MiniYaml.Merge(modData.Manifest.Chrome - .Select(s => MiniYaml.FromStream(fileSystem.Open(s)))); + .Select(s => MiniYaml.FromStream(fileSystem.Open(s), s))); foreach (var c in chrome) LoadCollection(c.Key, c.Value); diff --git a/OpenRA.Game/Graphics/CursorProvider.cs b/OpenRA.Game/Graphics/CursorProvider.cs index 0564634499..1c7155b344 100644 --- a/OpenRA.Game/Graphics/CursorProvider.cs +++ b/OpenRA.Game/Graphics/CursorProvider.cs @@ -24,7 +24,7 @@ namespace OpenRA.Graphics { var fileSystem = modData.DefaultFileSystem; var sequenceYaml = MiniYaml.Merge(modData.Manifest.Cursors.Select( - s => MiniYaml.FromStream(fileSystem.Open(s)))); + s => MiniYaml.FromStream(fileSystem.Open(s), s))); var shadowIndex = new int[] { }; diff --git a/OpenRA.Game/Manifest.cs b/OpenRA.Game/Manifest.cs index 1878bae660..7544a364fc 100644 --- a/OpenRA.Game/Manifest.cs +++ b/OpenRA.Game/Manifest.cs @@ -64,7 +64,7 @@ namespace OpenRA { var package = ModMetadata.AllMods[modId].Package; - yaml = new MiniYaml(null, MiniYaml.FromStream(package.GetStream("mod.yaml"))).ToDictionary(); + yaml = new MiniYaml(null, MiniYaml.FromStream(package.GetStream("mod.yaml"), "mod.yaml")).ToDictionary(); Mod = FieldLoader.Load(yaml["Metadata"]); Mod.Id = modId; diff --git a/OpenRA.Game/Map/TileSet.cs b/OpenRA.Game/Map/TileSet.cs index b17f1e0513..f5202d00c5 100644 --- a/OpenRA.Game/Map/TileSet.cs +++ b/OpenRA.Game/Map/TileSet.cs @@ -204,7 +204,7 @@ namespace OpenRA public TileSet(IReadOnlyFileSystem fileSystem, string filepath) { - var yaml = MiniYaml.DictFromStream(fileSystem.Open(filepath)); + var yaml = MiniYaml.DictFromStream(fileSystem.Open(filepath), filepath); // General info FieldLoader.Load(this, yaml["General"]); diff --git a/OpenRA.Game/MiniYaml.cs b/OpenRA.Game/MiniYaml.cs index bcc4fe5e60..efca3cff66 100644 --- a/OpenRA.Game/MiniYaml.cs +++ b/OpenRA.Game/MiniYaml.cs @@ -236,9 +236,9 @@ namespace OpenRA return FromFile(path).ToDictionary(x => x.Key, x => x.Value); } - public static Dictionary DictFromStream(Stream stream) + public static Dictionary DictFromStream(Stream stream, string fileName = "") { - return FromStream(stream).ToDictionary(x => x.Key, x => x.Value); + return FromStream(stream, fileName).ToDictionary(x => x.Key, x => x.Value); } public static List FromFile(string path) @@ -385,7 +385,7 @@ namespace OpenRA files = files.Append(mapFiles); } - var yaml = files.Select(s => MiniYaml.FromStream(fileSystem.Open(s))); + var yaml = files.Select(s => MiniYaml.FromStream(fileSystem.Open(s), s)); if (mapRules != null && mapRules.Nodes.Any()) yaml = yaml.Append(mapRules.Nodes); diff --git a/OpenRA.Game/ModMetadata.cs b/OpenRA.Game/ModMetadata.cs index 30a7fe1134..f0f271e098 100644 --- a/OpenRA.Game/ModMetadata.cs +++ b/OpenRA.Game/ModMetadata.cs @@ -61,7 +61,7 @@ namespace OpenRA continue; } - var yaml = new MiniYaml(null, MiniYaml.FromStream(package.GetStream("mod.yaml"))); + var yaml = new MiniYaml(null, MiniYaml.FromStream(package.GetStream("mod.yaml"), "mod.yaml")); var nd = yaml.ToDictionary(); if (!nd.ContainsKey("Metadata")) { diff --git a/OpenRA.Game/Widgets/ChromeMetrics.cs b/OpenRA.Game/Widgets/ChromeMetrics.cs index f86206c587..b16ea63e32 100644 --- a/OpenRA.Game/Widgets/ChromeMetrics.cs +++ b/OpenRA.Game/Widgets/ChromeMetrics.cs @@ -22,7 +22,7 @@ namespace OpenRA.Widgets { data = new Dictionary(); var metrics = MiniYaml.Merge(modData.Manifest.ChromeMetrics.Select( - y => MiniYaml.FromStream(modData.DefaultFileSystem.Open(y)))); + y => MiniYaml.FromStream(modData.DefaultFileSystem.Open(y), y))); foreach (var m in metrics) foreach (var n in m.Value.Nodes) data[n.Key] = n.Value.Value; diff --git a/OpenRA.Game/Widgets/WidgetLoader.cs b/OpenRA.Game/Widgets/WidgetLoader.cs index 73e883515a..da40e48c50 100644 --- a/OpenRA.Game/Widgets/WidgetLoader.cs +++ b/OpenRA.Game/Widgets/WidgetLoader.cs @@ -25,7 +25,7 @@ namespace OpenRA { this.modData = modData; - foreach (var file in modData.Manifest.ChromeLayout.Select(a => MiniYaml.FromStream(modData.DefaultFileSystem.Open(a)))) + foreach (var file in modData.Manifest.ChromeLayout.Select(a => MiniYaml.FromStream(modData.DefaultFileSystem.Open(a), a))) foreach (var w in file) { var key = w.Key.Substring(w.Key.IndexOf('@') + 1); diff --git a/OpenRA.Mods.Common/Lint/CheckChromeLogic.cs b/OpenRA.Mods.Common/Lint/CheckChromeLogic.cs index 002e447ed7..29851788de 100644 --- a/OpenRA.Mods.Common/Lint/CheckChromeLogic.cs +++ b/OpenRA.Mods.Common/Lint/CheckChromeLogic.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.Common.Lint public void Run(Action emitError, Action emitWarning, ModData modData) { foreach (var filename in modData.Manifest.ChromeLayout) - CheckInner(MiniYaml.FromStream(modData.DefaultFileSystem.Open(filename)), filename, emitError); + CheckInner(MiniYaml.FromStream(modData.DefaultFileSystem.Open(filename), filename), filename, emitError); } void CheckInner(List nodes, string filename, Action emitError) diff --git a/OpenRA.Mods.Common/UtilityCommands/CheckSequenceSprites.cs b/OpenRA.Mods.Common/UtilityCommands/CheckSequenceSprites.cs index 972288716f..92dd35795e 100644 --- a/OpenRA.Mods.Common/UtilityCommands/CheckSequenceSprites.cs +++ b/OpenRA.Mods.Common/UtilityCommands/CheckSequenceSprites.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.UtilityCommands var ts = new TileSet(modData.DefaultFileSystem, t); Console.WriteLine("Tileset: " + ts.Name); var sc = new SpriteCache(modData.DefaultFileSystem, modData.SpriteLoaders, new SheetBuilder(SheetType.Indexed)); - var nodes = MiniYaml.Merge(modData.Manifest.Sequences.Select(s => MiniYaml.FromStream(modData.DefaultFileSystem.Open(s)))); + var nodes = MiniYaml.Merge(modData.Manifest.Sequences.Select(s => MiniYaml.FromStream(modData.DefaultFileSystem.Open(s), s))); foreach (var n in nodes) modData.SpriteSequenceLoader.ParseSequences(modData, ts, sc, n); } diff --git a/OpenRA.Mods.Common/UtilityCommands/ExtractMapRules.cs b/OpenRA.Mods.Common/UtilityCommands/ExtractMapRules.cs index 0830f432aa..d08f4e8aa3 100644 --- a/OpenRA.Mods.Common/UtilityCommands/ExtractMapRules.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ExtractMapRules.cs @@ -36,7 +36,7 @@ namespace OpenRA.Mods.Common.UtilityCommands { include |= map.Package.Contains(f); if (include) - nodes.AddRange(MiniYaml.FromStream(map.Open(f))); + nodes.AddRange(MiniYaml.FromStream(map.Open(f), f)); else includes.Add(f); } diff --git a/OpenRA.Mods.Common/UtilityCommands/UpgradeMapCommand.cs b/OpenRA.Mods.Common/UtilityCommands/UpgradeMapCommand.cs index 6e608c58fc..a45c24e93d 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpgradeMapCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpgradeMapCommand.cs @@ -37,7 +37,7 @@ namespace OpenRA.Mods.Common.UtilityCommands var files = FieldLoader.GetValue("value", yaml.Value); foreach (var filename in files) { - var fileNodes = MiniYaml.FromStream(map.Package.GetStream(filename)); + var fileNodes = MiniYaml.FromStream(map.Package.GetStream(filename), filename); processYaml(engineDate, ref fileNodes, null, 0); ((IReadWritePackage)map.Package).Update(filename, Encoding.ASCII.GetBytes(fileNodes.WriteToString())); } diff --git a/OpenRA.Mods.Common/UtilityCommands/UpgradeModCommand.cs b/OpenRA.Mods.Common/UtilityCommands/UpgradeModCommand.cs index 407232f721..a21b0a6822 100644 --- a/OpenRA.Mods.Common/UtilityCommands/UpgradeModCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/UpgradeModCommand.cs @@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.UtilityCommands continue; } - var yaml = MiniYaml.FromStream(package.GetStream(name)); + var yaml = MiniYaml.FromStream(package.GetStream(name), name); processFile(engineDate, ref yaml, null, 0); // Generate the on-disk path diff --git a/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs index f084c991a8..dd3f540e9a 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MissionBrowserLogic.cs @@ -100,7 +100,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (modData.Manifest.Missions.Any()) { var yaml = MiniYaml.Merge(modData.Manifest.Missions.Select( - m => MiniYaml.FromStream(modData.DefaultFileSystem.Open(m)))); + m => MiniYaml.FromStream(modData.DefaultFileSystem.Open(m), m))); foreach (var kv in yaml) {