From e6d1f30cf08d2ac2c44710b659e75ec0b8270cf6 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 18 May 2014 13:36:44 +1200 Subject: [PATCH] Use an IReadOnlyDictionary for package definitions. --- OpenRA.Game/Manifest.cs | 13 +++++++++++-- mods/modchooser/mod.yaml | 1 - 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/OpenRA.Game/Manifest.cs b/OpenRA.Game/Manifest.cs index 6f2b45007d..db586dc4e0 100644 --- a/OpenRA.Game/Manifest.cs +++ b/OpenRA.Game/Manifest.cs @@ -26,7 +26,7 @@ namespace OpenRA Weapons, Voices, Notifications, Music, Movies, Translations, TileSets, ChromeMetrics, PackageContents, LuaScripts, MapCompatibility, Missions; - public readonly Dictionary Packages; + public readonly IReadOnlyDictionary Packages; public readonly MiniYaml LoadScreen; public readonly MiniYaml LobbyDefaults; public readonly Dictionary> Fonts; @@ -44,7 +44,7 @@ namespace OpenRA // TODO: Use fieldloader Folders = YamlList(yaml, "Folders"); MapFolders = YamlList(yaml, "MapFolders"); - Packages = yaml["Packages"].NodesDict.ToDictionary(x => x.Key, x => x.Value.Value); + Packages = YamlDictionary(yaml, "Packages"); Rules = YamlList(yaml, "Rules"); ServerTraits = YamlList(yaml, "ServerTraits"); Sequences = YamlList(yaml, "Sequences"); @@ -95,5 +95,14 @@ namespace OpenRA return yaml[key].NodesDict.Keys.ToArray(); } + + static IReadOnlyDictionary YamlDictionary(Dictionary yaml, string key) + { + if (!yaml.ContainsKey(key)) + return new ReadOnlyDictionary(); + + var inner = yaml[key].NodesDict.ToDictionary(x => x.Key, x => x.Value.Value); + return new ReadOnlyDictionary(inner); + } } } diff --git a/mods/modchooser/mod.yaml b/mods/modchooser/mod.yaml index f397b519c8..4a290c6bac 100644 --- a/mods/modchooser/mod.yaml +++ b/mods/modchooser/mod.yaml @@ -47,5 +47,4 @@ Fonts: TinyBold: Font:FreeSansBold.ttf Size:10 -Packages: LobbyDefaults: \ No newline at end of file