diff --git a/OpenRA.FileFormats/Manifest.cs b/OpenRA.FileFormats/Manifest.cs index 01866720e9..1cf9c90537 100644 --- a/OpenRA.FileFormats/Manifest.cs +++ b/OpenRA.FileFormats/Manifest.cs @@ -29,7 +29,7 @@ namespace OpenRA.FileFormats Mods = mods; var yaml = mods .Select(m => MiniYaml.FromFile("mods/" + m + "/mod.yaml")) - .Aggregate(MiniYaml.Merge); + .Aggregate(MiniYaml.MergeLiberal); // Todo: Use fieldloader Folders = YamlList(yaml, "Folders"); diff --git a/OpenRA.FileFormats/MiniYaml.cs b/OpenRA.FileFormats/MiniYaml.cs index fdd207d570..cb3d6b948e 100755 --- a/OpenRA.FileFormats/MiniYaml.cs +++ b/OpenRA.FileFormats/MiniYaml.cs @@ -164,7 +164,17 @@ namespace OpenRA.FileFormats return FromLines(text.Split(new[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries), ""); } - public static List Merge( List a, List b ) + public static List MergeLiberal(List a, List b) + { + return Merge(a, b, false); + } + + public static List MergeStrict(List a, List b) + { + return Merge(a, b, true); + } + + static List Merge( List a, List b, bool throwErrors ) { if( a.Count == 0 ) return b; @@ -188,18 +198,21 @@ namespace OpenRA.FileFormats if( noInherit.ContainsKey( key ) ) { - // if( aa != null ) - // ret.Add( aa ); + if (!throwErrors) + if (aa != null) + ret.Add(aa); + noInherit[key] = true; } else { var loc = aa == null ? default( MiniYamlNode.SourceLocation ) : aa.Location; - var merged = ( aa == null || bb == null ) ? aa ?? bb : new MiniYamlNode( key, Merge( aa.Value, bb.Value ), loc ); + var merged = ( aa == null || bb == null ) ? aa ?? bb : new MiniYamlNode( key, Merge( aa.Value, bb.Value, throwErrors ), loc ); ret.Add( merged ); } } + if (throwErrors) if (noInherit.ContainsValue(false)) throw new YamlException("Bogus yaml removals: {0}".F( string.Join(", ", noInherit.Where(x => !x.Value).Select(x => x.Key).ToArray()))); @@ -207,14 +220,24 @@ namespace OpenRA.FileFormats return ret; } - public static MiniYaml Merge( MiniYaml a, MiniYaml b ) + public static MiniYaml MergeLiberal(MiniYaml a, MiniYaml b) + { + return Merge(a, b, false); + } + + public static MiniYaml MergeStrict(MiniYaml a, MiniYaml b) + { + return Merge(a, b, true); + } + + static MiniYaml Merge( MiniYaml a, MiniYaml b, bool throwErrors ) { if( a == null ) return b; if( b == null ) return a; - return new MiniYaml( a.Value ?? b.Value, Merge( a.Nodes, b.Nodes ) ); + return new MiniYaml( a.Value ?? b.Value, Merge( a.Nodes, b.Nodes, throwErrors ) ); } public IEnumerable ToLines(string name) diff --git a/OpenRA.Game/GameRules/ActorInfo.cs b/OpenRA.Game/GameRules/ActorInfo.cs index ec3b8c358d..51129ec768 100644 --- a/OpenRA.Game/GameRules/ActorInfo.cs +++ b/OpenRA.Game/GameRules/ActorInfo.cs @@ -68,7 +68,7 @@ namespace OpenRA var parent = GetParent( node, allUnits ); if (parent != null) { - var result = MiniYaml.Merge(node, MergeWithParent(parent, allUnits)); + var result = MiniYaml.MergeStrict(node, MergeWithParent(parent, allUnits)); // strip the '-' result.Nodes.RemoveAll(a => a.Key.StartsWith("-")); diff --git a/OpenRA.Game/GameRules/Rules.cs b/OpenRA.Game/GameRules/Rules.cs index 390284ba11..4fca88b6b2 100755 --- a/OpenRA.Game/GameRules/Rules.cs +++ b/OpenRA.Game/GameRules/Rules.cs @@ -44,7 +44,7 @@ namespace OpenRA static Dictionary LoadYamlRules(string[] files, List dict, Func, T> f) { - var y = files.Select(a => MiniYaml.FromFile(a)).Aggregate(dict,MiniYaml.Merge); + var y = files.Select(a => MiniYaml.FromFile(a)).Aggregate(dict,MiniYaml.MergeLiberal); var yy = y.ToDictionary( x => x.Key, x => x.Value ); return y.ToDictionary(kv => kv.Key.ToLowerInvariant(), kv => f(kv, yy)); } diff --git a/OpenRA.Game/Graphics/ChromeProvider.cs b/OpenRA.Game/Graphics/ChromeProvider.cs index 767529eac8..0510a8eed2 100644 --- a/OpenRA.Game/Graphics/ChromeProvider.cs +++ b/OpenRA.Game/Graphics/ChromeProvider.cs @@ -36,7 +36,7 @@ namespace OpenRA.Graphics if (chromeFiles.Length == 0) return; - var chrome = chromeFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.Merge); + var chrome = chromeFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.MergeLiberal); 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 bab1d93617..a44c1650f4 100644 --- a/OpenRA.Game/Graphics/CursorProvider.cs +++ b/OpenRA.Game/Graphics/CursorProvider.cs @@ -24,7 +24,7 @@ namespace OpenRA.Graphics public static void Initialize(string[] sequenceFiles) { cursors = new Dictionary(); - var sequences = new MiniYaml(null, sequenceFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.Merge)); + var sequences = new MiniYaml(null, sequenceFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.MergeLiberal)); foreach (var s in sequences.NodesDict["Palettes"].Nodes) Game.modData.Palette.AddPalette(s.Key, new Palette(FileSystem.Open(s.Value.Value), false)); diff --git a/OpenRA.Game/Graphics/SequenceProvider.cs b/OpenRA.Game/Graphics/SequenceProvider.cs index 679fcacc1f..1fbcfde2e5 100644 --- a/OpenRA.Game/Graphics/SequenceProvider.cs +++ b/OpenRA.Game/Graphics/SequenceProvider.cs @@ -26,7 +26,7 @@ namespace OpenRA.Graphics if (sequenceFiles.Length == 0) return; - var sequences = sequenceFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(sequenceNodes, MiniYaml.Merge); + var sequences = sequenceFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(sequenceNodes, MiniYaml.MergeLiberal); foreach (var s in sequences) LoadSequencesForUnit(s.Key, s.Value);