From e12ff2c59d28ff0bee2b6b59f8c61636aa90be4b Mon Sep 17 00:00:00 2001 From: teinarss Date: Tue, 16 Mar 2021 20:03:38 +0100 Subject: [PATCH] Remove our own ReadOnlyDictionary and update usages --- OpenRA.Game/Actor.cs | 1 + OpenRA.Game/ExternalMods.cs | 5 + OpenRA.Game/GameRules/Ruleset.cs | 2 +- OpenRA.Game/Graphics/ChromeProvider.cs | 4 +- OpenRA.Game/Graphics/CursorProvider.cs | 5 +- OpenRA.Game/Graphics/HardwarePalette.cs | 2 +- OpenRA.Game/Graphics/Model.cs | 1 + OpenRA.Game/Graphics/SequenceProvider.cs | 2 +- OpenRA.Game/InstalledMods.cs | 5 +- OpenRA.Game/Manifest.cs | 7 +- OpenRA.Game/Map/MapCache.cs | 4 +- OpenRA.Game/ModData.cs | 1 + OpenRA.Game/Primitives/Cache.cs | 5 + OpenRA.Game/Primitives/ConcurrentCache.cs | 6 +- OpenRA.Game/Primitives/PlayerDictionary.cs | 7 +- OpenRA.Game/Primitives/ReadOnlyDictionary.cs | 100 ------------------ OpenRA.Game/Renderer.cs | 2 +- OpenRA.Game/Support/VariableExpression.cs | 1 + OpenRA.Game/Traits/TraitsInterfaces.cs | 1 + OpenRA.Mods.Cnc/FileSystem/MixFile.cs | 1 + .../ChronoshiftPaletteEffect.cs | 1 + OpenRA.Mods.Cnc/Traits/TDGunboat.cs | 3 +- .../InstallShieldCABCompression.cs | 1 + .../FileSystem/InstallShieldPackage.cs | 1 + .../Graphics/DefaultSpriteSequence.cs | 1 + .../Lint/CheckActorReferences.cs | 1 + .../SpriteLoaders/PngSheetLoader.cs | 1 + OpenRA.Mods.Common/Terrain/DefaultTerrain.cs | 2 +- OpenRA.Mods.Common/Terrain/TerrainInfo.cs | 2 + OpenRA.Mods.Common/Traits/Air/Aircraft.cs | 3 +- .../Traits/Buildings/Building.cs | 3 +- OpenRA.Mods.Common/Traits/Crates/Crate.cs | 2 +- OpenRA.Mods.Common/Traits/Harvester.cs | 1 + OpenRA.Mods.Common/Traits/Husk.cs | 3 +- OpenRA.Mods.Common/Traits/Immobile.cs | 3 +- OpenRA.Mods.Common/Traits/Mobile.cs | 3 +- .../PaletteEffects/CloakPaletteEffect.cs | 1 + .../Traits/Player/PlayerResources.cs | 2 +- .../Traits/Player/TimeLimitManager.cs | 2 +- .../Traits/World/EditorActorPreview.cs | 4 +- OpenRA.Mods.Common/Traits/World/MapOptions.cs | 4 +- .../Traits/World/ScriptLobbyDropdown.cs | 2 +- .../Traits/World/SpawnStartingUnits.cs | 2 +- .../OpenRA.Game/VariableExpressionTest.cs | 5 +- 44 files changed, 73 insertions(+), 142 deletions(-) delete mode 100644 OpenRA.Game/Primitives/ReadOnlyDictionary.cs diff --git a/OpenRA.Game/Actor.cs b/OpenRA.Game/Actor.cs index c795758372..19b842cd39 100644 --- a/OpenRA.Game/Actor.cs +++ b/OpenRA.Game/Actor.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.IO; using System.Linq; using Eluant; diff --git a/OpenRA.Game/ExternalMods.cs b/OpenRA.Game/ExternalMods.cs index aca8037892..a6f8ee43f4 100644 --- a/OpenRA.Game/ExternalMods.cs +++ b/OpenRA.Game/ExternalMods.cs @@ -294,6 +294,11 @@ namespace OpenRA public int Count => mods.Count; public ICollection Keys => mods.Keys; public ICollection Values => mods.Values; + + IEnumerable IReadOnlyDictionary.Keys => ((IReadOnlyDictionary)mods).Keys; + + IEnumerable IReadOnlyDictionary.Values => ((IReadOnlyDictionary)mods).Values; + public bool ContainsKey(string key) { return mods.ContainsKey(key); } public IEnumerator> GetEnumerator() { return mods.GetEnumerator(); } public bool TryGetValue(string key, out ExternalMod value) { return mods.TryGetValue(key, out value); } diff --git a/OpenRA.Game/GameRules/Ruleset.cs b/OpenRA.Game/GameRules/Ruleset.cs index 0035496c71..26d566aaa2 100644 --- a/OpenRA.Game/GameRules/Ruleset.cs +++ b/OpenRA.Game/GameRules/Ruleset.cs @@ -115,7 +115,7 @@ namespace OpenRA if (filterNode != null) yamlNodes = yamlNodes.Where(k => !filterNode(k)); - return new ReadOnlyDictionary(yamlNodes.ToDictionaryWithConflictLog(k => k.Key.ToLowerInvariant(), makeObject, "LoadFromManifest<" + name + ">")); + return new Dictionary(yamlNodes.ToDictionaryWithConflictLog(k => k.Key.ToLowerInvariant(), makeObject, "LoadFromManifest<" + name + ">")); } public static Ruleset LoadDefaults(ModData modData) diff --git a/OpenRA.Game/Graphics/ChromeProvider.cs b/OpenRA.Game/Graphics/ChromeProvider.cs index 342ebbf8cc..1b4d1fc87a 100644 --- a/OpenRA.Game/Graphics/ChromeProvider.cs +++ b/OpenRA.Game/Graphics/ChromeProvider.cs @@ -52,7 +52,7 @@ namespace OpenRA.Graphics public readonly Dictionary Regions = new Dictionary(); } - public static IReadOnlyDictionary Collections { get; private set; } + public static IReadOnlyDictionary Collections => collections; static Dictionary collections; static Dictionary cachedSheets; static Dictionary> cachedSprites; @@ -77,8 +77,6 @@ namespace OpenRA.Graphics cachedPanelSprites = new Dictionary(); cachedCollectionSheets = new Dictionary(); - Collections = new ReadOnlyDictionary(collections); - var chrome = MiniYaml.Merge(modData.Manifest.Chrome .Select(s => MiniYaml.FromStream(fileSystem.Open(s), s))); diff --git a/OpenRA.Game/Graphics/CursorProvider.cs b/OpenRA.Game/Graphics/CursorProvider.cs index c03bd605b4..13edc2f045 100644 --- a/OpenRA.Game/Graphics/CursorProvider.cs +++ b/OpenRA.Game/Graphics/CursorProvider.cs @@ -38,8 +38,7 @@ namespace OpenRA.Graphics Palettes = nodesDict["Cursors"].Nodes.Select(n => n.Value.Value) .Where(p => p != null) .Distinct() - .ToDictionary(p => p, p => pals[p].ReadPalette(modData.DefaultFileSystem)) - .AsReadOnly(); + .ToDictionary(p => p, p => pals[p].ReadPalette(modData.DefaultFileSystem)); var frameCache = new FrameCache(fileSystem, modData.SpriteLoaders); var cursors = new Dictionary(); @@ -47,7 +46,7 @@ namespace OpenRA.Graphics foreach (var sequence in s.Value.Nodes) cursors.Add(sequence.Key, new CursorSequence(frameCache, sequence.Key, s.Key, s.Value.Value, sequence.Value)); - Cursors = cursors.AsReadOnly(); + Cursors = cursors; } public bool HasCursorSequence(string cursor) diff --git a/OpenRA.Game/Graphics/HardwarePalette.cs b/OpenRA.Game/Graphics/HardwarePalette.cs index 60d050ea51..50f4104065 100644 --- a/OpenRA.Game/Graphics/HardwarePalette.cs +++ b/OpenRA.Game/Graphics/HardwarePalette.cs @@ -28,7 +28,7 @@ namespace OpenRA.Graphics public HardwarePalette() { Texture = Game.Renderer.Context.CreateTexture(); - readOnlyModifiablePalettes = modifiablePalettes.AsReadOnly(); + readOnlyModifiablePalettes = modifiablePalettes; } public bool Contains(string name) diff --git a/OpenRA.Game/Graphics/Model.cs b/OpenRA.Game/Graphics/Model.cs index b724c0428e..af725e8aa3 100644 --- a/OpenRA.Game/Graphics/Model.cs +++ b/OpenRA.Game/Graphics/Model.cs @@ -10,6 +10,7 @@ #endregion using System; +using System.Collections.Generic; using OpenRA.FileSystem; using OpenRA.Primitives; diff --git a/OpenRA.Game/Graphics/SequenceProvider.cs b/OpenRA.Game/Graphics/SequenceProvider.cs index 2324c72d5a..ce258ed8f0 100644 --- a/OpenRA.Game/Graphics/SequenceProvider.cs +++ b/OpenRA.Game/Graphics/SequenceProvider.cs @@ -125,7 +125,7 @@ namespace OpenRA.Graphics } } - return new ReadOnlyDictionary(items); + return items; } public void Preload() diff --git a/OpenRA.Game/InstalledMods.cs b/OpenRA.Game/InstalledMods.cs index 14ae4157ef..e157bb206a 100644 --- a/OpenRA.Game/InstalledMods.cs +++ b/OpenRA.Game/InstalledMods.cs @@ -16,7 +16,6 @@ using System.IO; using System.Linq; using OpenRA.FileSystem; using OpenRA.Graphics; -using OpenRA.Primitives; namespace OpenRA { @@ -100,9 +99,9 @@ namespace OpenRA } public Manifest this[string key] => mods[key]; + public IEnumerable Keys => mods.Keys; + public IEnumerable Values => mods.Values; public int Count => mods.Count; - public ICollection Keys => mods.Keys; - public ICollection Values => mods.Values; public bool ContainsKey(string key) { return mods.ContainsKey(key); } public IEnumerator> GetEnumerator() { return mods.GetEnumerator(); } public bool TryGetValue(string key, out Manifest value) { return mods.TryGetValue(key, out value); } diff --git a/OpenRA.Game/Manifest.cs b/OpenRA.Game/Manifest.cs index 25564bfaca..769b50b597 100644 --- a/OpenRA.Game/Manifest.cs +++ b/OpenRA.Game/Manifest.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.IO; using System.Linq; using OpenRA.FileSystem; @@ -127,7 +128,7 @@ namespace OpenRA MapFolders = YamlDictionary(yaml, "MapFolders"); if (yaml.TryGetValue("Packages", out var packages)) - Packages = packages.ToDictionary(x => x.Value).AsReadOnly(); + Packages = packages.ToDictionary(x => x.Value); Rules = YamlList(yaml, "Rules"); Sequences = YamlList(yaml, "Sequences"); @@ -213,10 +214,10 @@ namespace OpenRA static IReadOnlyDictionary YamlDictionary(Dictionary yaml, string key) { if (!yaml.ContainsKey(key)) - return new ReadOnlyDictionary(); + return new Dictionary(); var inner = yaml[key].ToDictionary(my => my.Value); - return new ReadOnlyDictionary(inner); + return inner; } public bool Contains() where T : IGlobalModData diff --git a/OpenRA.Game/Map/MapCache.cs b/OpenRA.Game/Map/MapCache.cs index 1cf099d506..0fe2b7fe3c 100644 --- a/OpenRA.Game/Map/MapCache.cs +++ b/OpenRA.Game/Map/MapCache.cs @@ -26,7 +26,7 @@ namespace OpenRA public sealed class MapCache : IEnumerable, IDisposable { public static readonly MapPreview UnknownMap = new MapPreview(null, null, MapGridType.Rectangular, null); - public readonly IReadOnlyDictionary MapLocations; + public IReadOnlyDictionary MapLocations => mapLocations; readonly Dictionary mapLocations = new Dictionary(); readonly Cache previews; @@ -46,8 +46,6 @@ namespace OpenRA var gridType = Exts.Lazy(() => modData.Manifest.Get().Type); previews = new Cache(uid => new MapPreview(modData, uid, gridType.Value, this)); sheetBuilder = new SheetBuilder(SheetType.BGRA); - - MapLocations = new ReadOnlyDictionary(mapLocations); } public void LoadMaps() diff --git a/OpenRA.Game/ModData.cs b/OpenRA.Game/ModData.cs index 3228811b53..4449bb3acb 100644 --- a/OpenRA.Game/ModData.cs +++ b/OpenRA.Game/ModData.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.IO; using System.Linq; using OpenRA.FileSystem; diff --git a/OpenRA.Game/Primitives/Cache.cs b/OpenRA.Game/Primitives/Cache.cs index 75cea420f3..ea36b06ba3 100644 --- a/OpenRA.Game/Primitives/Cache.cs +++ b/OpenRA.Game/Primitives/Cache.cs @@ -40,6 +40,11 @@ namespace OpenRA.Primitives public ICollection Keys => cache.Keys; public ICollection Values => cache.Values; + + IEnumerable IReadOnlyDictionary.Keys => cache.Keys; + + IEnumerable IReadOnlyDictionary.Values => cache.Values; + public IEnumerator> GetEnumerator() { return cache.GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } } diff --git a/OpenRA.Game/Primitives/ConcurrentCache.cs b/OpenRA.Game/Primitives/ConcurrentCache.cs index 367aea0ab1..43e3f332bf 100644 --- a/OpenRA.Game/Primitives/ConcurrentCache.cs +++ b/OpenRA.Game/Primitives/ConcurrentCache.cs @@ -12,6 +12,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Linq; namespace OpenRA.Primitives { @@ -33,12 +34,13 @@ namespace OpenRA.Primitives : this(loader, EqualityComparer.Default) { } public U this[T key] => cache.GetOrAdd(key, loader); + public IEnumerable Keys => cache.Keys; + + public IEnumerable Values => cache.Values; public bool ContainsKey(T key) { return cache.ContainsKey(key); } public bool TryGetValue(T key, out U value) { return cache.TryGetValue(key, out value); } public int Count => cache.Count; - public ICollection Keys => cache.Keys; - public ICollection Values => cache.Values; public IEnumerator> GetEnumerator() { return cache.GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } } diff --git a/OpenRA.Game/Primitives/PlayerDictionary.cs b/OpenRA.Game/Primitives/PlayerDictionary.cs index d032ead5f0..a4db57db8a 100644 --- a/OpenRA.Game/Primitives/PlayerDictionary.cs +++ b/OpenRA.Game/Primitives/PlayerDictionary.cs @@ -52,10 +52,13 @@ namespace OpenRA.Primitives public T this[int playerIndex] => valueByPlayerIndex[playerIndex]; public int Count => valueByPlayerIndex.Length; + + public IEnumerable Keys => ((IReadOnlyDictionary)valueByPlayer).Keys; + + public IEnumerable Values => ((IReadOnlyDictionary)valueByPlayer).Values; + public IEnumerator GetEnumerator() { return ((IEnumerable)valueByPlayerIndex).GetEnumerator(); } - ICollection IReadOnlyDictionary.Keys => valueByPlayer.Keys; - ICollection IReadOnlyDictionary.Values => valueByPlayer.Values; bool IReadOnlyDictionary.ContainsKey(Player key) { return valueByPlayer.ContainsKey(key); } bool IReadOnlyDictionary.TryGetValue(Player key, out T value) { return valueByPlayer.TryGetValue(key, out value); } IEnumerator> IEnumerable>.GetEnumerator() { return valueByPlayer.GetEnumerator(); } diff --git a/OpenRA.Game/Primitives/ReadOnlyDictionary.cs b/OpenRA.Game/Primitives/ReadOnlyDictionary.cs deleted file mode 100644 index ab03b63d4b..0000000000 --- a/OpenRA.Game/Primitives/ReadOnlyDictionary.cs +++ /dev/null @@ -1,100 +0,0 @@ -#region Copyright & License Information -/* - * Copyright 2007-2020 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, either version 3 of - * the License, or (at your option) any later version. For more - * information, see COPYING. - */ -#endregion - -using System; -using System.Collections.Generic; - -namespace OpenRA -{ - /// - /// A minimal read only dictionary interface for .NET 4 - /// - /// - /// .NET 4.5 has an implementation built-in, this code is not meant to - /// duplicate it but provide a compatible interface that can be replaced - /// when we switch to .NET 4.5 or higher. - /// - public interface IReadOnlyDictionary : IEnumerable> - { - int Count { get; } - TValue this[TKey key] { get; } - ICollection Keys { get; } - ICollection Values { get; } - - bool ContainsKey(TKey key); - bool TryGetValue(TKey key, out TValue value); - } - - public static class ReadOnlyDictionary - { - public static IReadOnlyDictionary AsReadOnly(this IDictionary dict) - { - return dict as IReadOnlyDictionary ?? new ReadOnlyDictionary(dict); - } - } - - /// - /// A minimal read only dictionary for .NET 4 implemented as a wrapper - /// around an IDictionary. - /// - public class ReadOnlyDictionary : IReadOnlyDictionary - { - private readonly IDictionary dict; - - public ReadOnlyDictionary() - : this(new Dictionary()) - { - } - - public ReadOnlyDictionary(IDictionary dict) - { - if (dict == null) - throw new ArgumentNullException(nameof(dict)); - - this.dict = dict; - } - - #region IReadOnlyDictionary implementation - public bool ContainsKey(TKey key) - { - return dict.ContainsKey(key); - } - - public bool TryGetValue(TKey key, out TValue value) - { - return dict.TryGetValue(key, out value); - } - - public int Count => dict.Count; - - public TValue this[TKey key] => dict[key]; - - public ICollection Keys => dict.Keys; - - public ICollection Values => dict.Values; - - #endregion - - #region IEnumerable implementation - public IEnumerator> GetEnumerator() - { - return dict.GetEnumerator(); - } - #endregion - - #region IEnumerable implementation - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() - { - return dict.GetEnumerator(); - } - #endregion - } -} diff --git a/OpenRA.Game/Renderer.cs b/OpenRA.Game/Renderer.cs index 1101dc7fb6..6503d466b8 100644 --- a/OpenRA.Game/Renderer.cs +++ b/OpenRA.Game/Renderer.cs @@ -113,7 +113,7 @@ namespace OpenRA fontSheetBuilder = new SheetBuilder(SheetType.BGRA, 512); Fonts = modData.Manifest.Get().FontList.ToDictionary(x => x.Key, x => new SpriteFont(x.Value.Font, modData.DefaultFileSystem.Open(x.Value.Font).ReadAllBytes(), - x.Value.Size, x.Value.Ascender, Window.EffectiveWindowScale, fontSheetBuilder)).AsReadOnly(); + x.Value.Size, x.Value.Ascender, Window.EffectiveWindowScale, fontSheetBuilder)); } Window.OnWindowScaleChanged += (oldNative, oldEffective, newNative, newEffective) => diff --git a/OpenRA.Game/Support/VariableExpression.cs b/OpenRA.Game/Support/VariableExpression.cs index 09a745dc09..ac7153e14f 100644 --- a/OpenRA.Game/Support/VariableExpression.cs +++ b/OpenRA.Game/Support/VariableExpression.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.IO; using System.Linq; using System.Linq.Expressions; diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index f8b2ca38c7..9c4b2cba25 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Diagnostics.CodeAnalysis; using OpenRA.Activities; using OpenRA.FileSystem; diff --git a/OpenRA.Mods.Cnc/FileSystem/MixFile.cs b/OpenRA.Mods.Cnc/FileSystem/MixFile.cs index 766e95ff00..f13270f3a4 100644 --- a/OpenRA.Mods.Cnc/FileSystem/MixFile.cs +++ b/OpenRA.Mods.Cnc/FileSystem/MixFile.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.IO; using System.Linq; using OpenRA.FileSystem; diff --git a/OpenRA.Mods.Cnc/Traits/PaletteEffects/ChronoshiftPaletteEffect.cs b/OpenRA.Mods.Cnc/Traits/PaletteEffects/ChronoshiftPaletteEffect.cs index 3c5452a1e2..07cccf4d4f 100644 --- a/OpenRA.Mods.Cnc/Traits/PaletteEffects/ChronoshiftPaletteEffect.cs +++ b/OpenRA.Mods.Cnc/Traits/PaletteEffects/ChronoshiftPaletteEffect.cs @@ -9,6 +9,7 @@ */ #endregion +using System.Collections.Generic; using OpenRA.Graphics; using OpenRA.Primitives; using OpenRA.Traits; diff --git a/OpenRA.Mods.Cnc/Traits/TDGunboat.cs b/OpenRA.Mods.Cnc/Traits/TDGunboat.cs index a7d5dcc887..671c275253 100644 --- a/OpenRA.Mods.Cnc/Traits/TDGunboat.cs +++ b/OpenRA.Mods.Cnc/Traits/TDGunboat.cs @@ -10,6 +10,7 @@ #endregion using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using OpenRA.Activities; using OpenRA.Mods.Common; @@ -42,7 +43,7 @@ namespace OpenRA.Mods.Cnc.Traits public IReadOnlyDictionary OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any) { var occupied = new Dictionary() { { location, SubCell.FullCell } }; - return new ReadOnlyDictionary(occupied); + return occupied; } bool IOccupySpaceInfo.SharesCell => false; diff --git a/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs b/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs index 6a447e75d9..329f4ec18b 100644 --- a/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs +++ b/OpenRA.Mods.Common/FileFormats/InstallShieldCABCompression.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.IO; using System.Linq; using ICSharpCode.SharpZipLib.Zip.Compression; diff --git a/OpenRA.Mods.Common/FileSystem/InstallShieldPackage.cs b/OpenRA.Mods.Common/FileSystem/InstallShieldPackage.cs index cb75e20e84..1a8bb13525 100644 --- a/OpenRA.Mods.Common/FileSystem/InstallShieldPackage.cs +++ b/OpenRA.Mods.Common/FileSystem/InstallShieldPackage.cs @@ -10,6 +10,7 @@ #endregion using System.Collections.Generic; +using System.Collections.ObjectModel; using System.IO; using OpenRA.FileSystem; using OpenRA.Mods.Common.FileFormats; diff --git a/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs b/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs index 3c51be8132..6a4a20b715 100644 --- a/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs +++ b/OpenRA.Mods.Common/Graphics/DefaultSpriteSequence.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.IO; using System.Linq; using OpenRA.Graphics; diff --git a/OpenRA.Mods.Common/Lint/CheckActorReferences.cs b/OpenRA.Mods.Common/Lint/CheckActorReferences.cs index 22639487c8..f6f4b0ddb6 100644 --- a/OpenRA.Mods.Common/Lint/CheckActorReferences.cs +++ b/OpenRA.Mods.Common/Lint/CheckActorReferences.cs @@ -10,6 +10,7 @@ #endregion using System; +using System.Collections.Generic; using System.Linq; using System.Reflection; using OpenRA.GameRules; diff --git a/OpenRA.Mods.Common/SpriteLoaders/PngSheetLoader.cs b/OpenRA.Mods.Common/SpriteLoaders/PngSheetLoader.cs index e7fe045553..2dc5bd9151 100644 --- a/OpenRA.Mods.Common/SpriteLoaders/PngSheetLoader.cs +++ b/OpenRA.Mods.Common/SpriteLoaders/PngSheetLoader.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.IO; using System.Linq; using OpenRA.FileFormats; diff --git a/OpenRA.Mods.Common/Terrain/DefaultTerrain.cs b/OpenRA.Mods.Common/Terrain/DefaultTerrain.cs index f2e48d1ebd..f033a19e4d 100644 --- a/OpenRA.Mods.Common/Terrain/DefaultTerrain.cs +++ b/OpenRA.Mods.Common/Terrain/DefaultTerrain.cs @@ -115,7 +115,7 @@ namespace OpenRA.Mods.Common.Terrain // Templates Templates = yaml["Templates"].ToDictionary().Values - .Select(y => (TerrainTemplateInfo)new DefaultTerrainTemplateInfo(this, y)).ToDictionary(t => t.Id).AsReadOnly(); + .Select(y => (TerrainTemplateInfo)new DefaultTerrainTemplateInfo(this, y)).ToDictionary(t => t.Id); } public TerrainTypeInfo this[byte index] => TerrainInfo[index]; diff --git a/OpenRA.Mods.Common/Terrain/TerrainInfo.cs b/OpenRA.Mods.Common/Terrain/TerrainInfo.cs index 539c650213..8d0f304482 100644 --- a/OpenRA.Mods.Common/Terrain/TerrainInfo.cs +++ b/OpenRA.Mods.Common/Terrain/TerrainInfo.cs @@ -9,6 +9,8 @@ */ #endregion +using System.Collections.Generic; + namespace OpenRA.Mods.Common.Terrain { public interface ITemplatedTerrainInfo : ITerrainInfo diff --git a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs index 15a149e9bd..1363bf7e67 100644 --- a/OpenRA.Mods.Common/Traits/Air/Aircraft.cs +++ b/OpenRA.Mods.Common/Traits/Air/Aircraft.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using OpenRA.Activities; using OpenRA.Mods.Common.Activities; @@ -179,7 +180,7 @@ namespace OpenRA.Mods.Common.Traits yield return new FacingInit(PreviewFacing); } - public IReadOnlyDictionary OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any) { return new ReadOnlyDictionary(); } + public IReadOnlyDictionary OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any) { return new Dictionary(); } bool IOccupySpaceInfo.SharesCell => false; diff --git a/OpenRA.Mods.Common/Traits/Buildings/Building.cs b/OpenRA.Mods.Common/Traits/Buildings/Building.cs index e2f7965159..8cca1e1562 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Building.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Building.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using OpenRA.Graphics; using OpenRA.Traits; @@ -241,7 +242,7 @@ namespace OpenRA.Mods.Common.Traits var occupied = OccupiedTiles(topLeft) .ToDictionary(c => c, c => SubCell.FullCell); - return new ReadOnlyDictionary(occupied); + return occupied; } bool IOccupySpaceInfo.SharesCell => false; diff --git a/OpenRA.Mods.Common/Traits/Crates/Crate.cs b/OpenRA.Mods.Common/Traits/Crates/Crate.cs index d48bb68399..0221d1091e 100644 --- a/OpenRA.Mods.Common/Traits/Crates/Crate.cs +++ b/OpenRA.Mods.Common/Traits/Crates/Crate.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.Traits public IReadOnlyDictionary OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any) { var occupied = new Dictionary() { { location, SubCell.FullCell } }; - return new ReadOnlyDictionary(occupied); + return occupied; } bool IOccupySpaceInfo.SharesCell => false; diff --git a/OpenRA.Mods.Common/Traits/Harvester.cs b/OpenRA.Mods.Common/Traits/Harvester.cs index cd6ea2e552..8a57192c18 100644 --- a/OpenRA.Mods.Common/Traits/Harvester.cs +++ b/OpenRA.Mods.Common/Traits/Harvester.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using OpenRA.Activities; using OpenRA.Mods.Common.Activities; diff --git a/OpenRA.Mods.Common/Traits/Husk.cs b/OpenRA.Mods.Common/Traits/Husk.cs index b609300298..8ff89e313c 100644 --- a/OpenRA.Mods.Common/Traits/Husk.cs +++ b/OpenRA.Mods.Common/Traits/Husk.cs @@ -10,6 +10,7 @@ #endregion using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using OpenRA.Mods.Common.Activities; using OpenRA.Primitives; @@ -37,7 +38,7 @@ namespace OpenRA.Mods.Common.Traits public IReadOnlyDictionary OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any) { var occupied = new Dictionary() { { location, SubCell.FullCell } }; - return new ReadOnlyDictionary(occupied); + return occupied; } bool IOccupySpaceInfo.SharesCell => false; diff --git a/OpenRA.Mods.Common/Traits/Immobile.cs b/OpenRA.Mods.Common/Traits/Immobile.cs index e30f43123a..c3b2eb27aa 100644 --- a/OpenRA.Mods.Common/Traits/Immobile.cs +++ b/OpenRA.Mods.Common/Traits/Immobile.cs @@ -10,7 +10,6 @@ #endregion using System.Collections.Generic; -using OpenRA.Primitives; using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits @@ -25,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits var occupied = OccupiesSpace ? new Dictionary() { { location, SubCell.FullCell } } : new Dictionary(); - return new ReadOnlyDictionary(occupied); + return occupied; } bool IOccupySpaceInfo.SharesCell => false; diff --git a/OpenRA.Mods.Common/Traits/Mobile.cs b/OpenRA.Mods.Common/Traits/Mobile.cs index 6f6071251d..ff52f4b501 100644 --- a/OpenRA.Mods.Common/Traits/Mobile.cs +++ b/OpenRA.Mods.Common/Traits/Mobile.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using OpenRA.Activities; using OpenRA.Mods.Common.Activities; @@ -130,7 +131,7 @@ namespace OpenRA.Mods.Common.Traits public IReadOnlyDictionary OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any) { - return new ReadOnlyDictionary(new Dictionary() { { location, subCell } }); + return new Dictionary() { { location, subCell } }; } bool IOccupySpaceInfo.SharesCell => LocomotorInfo.SharesCell; diff --git a/OpenRA.Mods.Common/Traits/PaletteEffects/CloakPaletteEffect.cs b/OpenRA.Mods.Common/Traits/PaletteEffects/CloakPaletteEffect.cs index deef3cfd3c..ae8b29741c 100644 --- a/OpenRA.Mods.Common/Traits/PaletteEffects/CloakPaletteEffect.cs +++ b/OpenRA.Mods.Common/Traits/PaletteEffects/CloakPaletteEffect.cs @@ -9,6 +9,7 @@ */ #endregion +using System.Collections.Generic; using OpenRA.Graphics; using OpenRA.Primitives; using OpenRA.Traits; diff --git a/OpenRA.Mods.Common/Traits/Player/PlayerResources.cs b/OpenRA.Mods.Common/Traits/Player/PlayerResources.cs index aa15b8b894..17f897cd63 100644 --- a/OpenRA.Mods.Common/Traits/Player/PlayerResources.cs +++ b/OpenRA.Mods.Common/Traits/Player/PlayerResources.cs @@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Traits if (startingCash.Any()) yield return new LobbyOption("startingcash", DefaultCashDropdownLabel, DefaultCashDropdownDescription, DefaultCashDropdownVisible, DefaultCashDropdownDisplayOrder, - new ReadOnlyDictionary(startingCash), DefaultCash.ToString(), DefaultCashDropdownLocked); + startingCash, DefaultCash.ToString(), DefaultCashDropdownLocked); } public override object Create(ActorInitializer init) { return new PlayerResources(init.Self, this); } diff --git a/OpenRA.Mods.Common/Traits/Player/TimeLimitManager.cs b/OpenRA.Mods.Common/Traits/Player/TimeLimitManager.cs index 966dfd8138..e9c5096540 100644 --- a/OpenRA.Mods.Common/Traits/Player/TimeLimitManager.cs +++ b/OpenRA.Mods.Common/Traits/Player/TimeLimitManager.cs @@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Traits }); yield return new LobbyOption("timelimit", TimeLimitLabel, TimeLimitDescription, TimeLimitDropdownVisible, TimeLimitDisplayOrder, - new ReadOnlyDictionary(timelimits), TimeLimitDefault.ToString(), TimeLimitLocked); + timelimits, TimeLimitDefault.ToString(), TimeLimitLocked); } public override object Create(ActorInitializer init) { return new TimeLimitManager(init.Self, this); } diff --git a/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs b/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs index ba844cd03e..01cb252b8c 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.IO; using System.Linq; using OpenRA.Graphics; @@ -80,8 +81,7 @@ namespace OpenRA.Mods.Common.Traits Footprint = ios.OccupiedCells(Info, location, subCell); else { - var footprint = new Dictionary() { { location, SubCell.FullCell } }; - Footprint = new ReadOnlyDictionary(footprint); + Footprint = new Dictionary() { { location, SubCell.FullCell } }; } tooltip = Info.TraitInfos().FirstOrDefault(info => info.EnabledByDefault) as TooltipInfoBase diff --git a/OpenRA.Mods.Common/Traits/World/MapOptions.cs b/OpenRA.Mods.Common/Traits/World/MapOptions.cs index f30a28c7f5..388ff007e3 100644 --- a/OpenRA.Mods.Common/Traits/World/MapOptions.cs +++ b/OpenRA.Mods.Common/Traits/World/MapOptions.cs @@ -82,14 +82,14 @@ namespace OpenRA.Mods.Common.Traits if (techLevels.Any()) yield return new LobbyOption("techlevel", TechLevelDropdownLabel, TechLevelDropdownDescription, TechLevelDropdownVisible, TechLevelDropdownDisplayOrder, - new ReadOnlyDictionary(techLevels), TechLevel, TechLevelDropdownLocked); + techLevels, TechLevel, TechLevelDropdownLocked); var gameSpeeds = Game.ModData.Manifest.Get().Speeds .ToDictionary(s => s.Key, s => s.Value.Name); // NOTE: The server hardcodes special-case logic for this option id yield return new LobbyOption("gamespeed", GameSpeedDropdownLabel, GameSpeedDropdownDescription, GameSpeedDropdownVisible, GameSpeedDropdownDisplayOrder, - new ReadOnlyDictionary(gameSpeeds), GameSpeed, GameSpeedDropdownLocked); + gameSpeeds, GameSpeed, GameSpeedDropdownLocked); } void IRulesetLoaded.RulesetLoaded(Ruleset rules, ActorInfo info) diff --git a/OpenRA.Mods.Common/Traits/World/ScriptLobbyDropdown.cs b/OpenRA.Mods.Common/Traits/World/ScriptLobbyDropdown.cs index 6f353f40a1..44fd6813e8 100644 --- a/OpenRA.Mods.Common/Traits/World/ScriptLobbyDropdown.cs +++ b/OpenRA.Mods.Common/Traits/World/ScriptLobbyDropdown.cs @@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Traits IEnumerable ILobbyOptions.LobbyOptions(Ruleset rules) { yield return new LobbyOption(ID, Label, Description, Visible, DisplayOrder, - new ReadOnlyDictionary(Values), Default, Locked); + Values, Default, Locked); } public override object Create(ActorInitializer init) { return new ScriptLobbyDropdown(this); } diff --git a/OpenRA.Mods.Common/Traits/World/SpawnStartingUnits.cs b/OpenRA.Mods.Common/Traits/World/SpawnStartingUnits.cs index 37993e91e4..e64ded166f 100644 --- a/OpenRA.Mods.Common/Traits/World/SpawnStartingUnits.cs +++ b/OpenRA.Mods.Common/Traits/World/SpawnStartingUnits.cs @@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Traits if (startingUnits.Any()) yield return new LobbyOption("startingunits", DropdownLabel, DropdownDescription, DropdownVisible, DropdownDisplayOrder, - new ReadOnlyDictionary(startingUnits), StartingUnitsClass, DropdownLocked); + startingUnits, StartingUnitsClass, DropdownLocked); } public override object Create(ActorInitializer init) { return new SpawnStartingUnits(this); } diff --git a/OpenRA.Test/OpenRA.Game/VariableExpressionTest.cs b/OpenRA.Test/OpenRA.Game/VariableExpressionTest.cs index f52f9af64b..25f10e4354 100644 --- a/OpenRA.Test/OpenRA.Game/VariableExpressionTest.cs +++ b/OpenRA.Test/OpenRA.Game/VariableExpressionTest.cs @@ -10,6 +10,7 @@ #endregion using System.Collections.Generic; +using System.Collections.ObjectModel; using System.IO; using NUnit.Framework; using OpenRA.Support; @@ -19,13 +20,13 @@ namespace OpenRA.Test [TestFixture] public class VariableExpressionTest { - IReadOnlyDictionary testValues = new ReadOnlyDictionary(new Dictionary() + IReadOnlyDictionary testValues = new Dictionary { { "t", 5 }, { "t-1", 7 }, { "one", 1 }, { "five", 5 } - }); + }; void AssertFalse(string expression) {