diff --git a/OpenRA.Game/GameRules/Ruleset.cs b/OpenRA.Game/GameRules/Ruleset.cs index 26d566aaa2..4e3982c740 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 Dictionary(yamlNodes.ToDictionaryWithConflictLog(k => k.Key.ToLowerInvariant(), makeObject, "LoadFromManifest<" + name + ">")); + return yamlNodes.ToDictionaryWithConflictLog(k => k.Key.ToLowerInvariant(), makeObject, "LoadFromManifest<" + name + ">"); } public static Ruleset LoadDefaults(ModData modData) diff --git a/OpenRA.Game/Graphics/HardwarePalette.cs b/OpenRA.Game/Graphics/HardwarePalette.cs index 50f4104065..b5181e0b3c 100644 --- a/OpenRA.Game/Graphics/HardwarePalette.cs +++ b/OpenRA.Game/Graphics/HardwarePalette.cs @@ -21,14 +21,12 @@ namespace OpenRA.Graphics public int Height { get; private set; } readonly Dictionary palettes = new Dictionary(); readonly Dictionary modifiablePalettes = new Dictionary(); - readonly IReadOnlyDictionary readOnlyModifiablePalettes; readonly Dictionary indices = new Dictionary(); byte[] buffer = new byte[0]; public HardwarePalette() { Texture = Game.Renderer.Context.CreateTexture(); - readOnlyModifiablePalettes = modifiablePalettes; } public bool Contains(string name) @@ -109,7 +107,7 @@ namespace OpenRA.Graphics public void ApplyModifiers(IEnumerable paletteMods) { foreach (var mod in paletteMods) - mod.AdjustPalette(readOnlyModifiablePalettes); + mod.AdjustPalette(modifiablePalettes); // Update our texture with the changes. CopyModifiablePalettesToBuffer(); diff --git a/OpenRA.Game/Manifest.cs b/OpenRA.Game/Manifest.cs index 769b50b597..c247281500 100644 --- a/OpenRA.Game/Manifest.cs +++ b/OpenRA.Game/Manifest.cs @@ -216,8 +216,7 @@ namespace OpenRA if (!yaml.ContainsKey(key)) return new Dictionary(); - var inner = yaml[key].ToDictionary(my => my.Value); - return inner; + return yaml[key].ToDictionary(my => my.Value); } public bool Contains() where T : IGlobalModData diff --git a/OpenRA.Game/Network/OrderManager.cs b/OpenRA.Game/Network/OrderManager.cs index 11f47c1e59..91282941b4 100644 --- a/OpenRA.Game/Network/OrderManager.cs +++ b/OpenRA.Game/Network/OrderManager.cs @@ -52,7 +52,7 @@ namespace OpenRA.Network readonly List chatCache = new List(); - public readonly ReadOnlyList ChatCache; + public IReadOnlyList ChatCache => chatCache; bool disposed; bool generateSyncReport = false; @@ -85,7 +85,6 @@ namespace OpenRA.Network Password = password; Connection = conn; syncReport = new SyncReport(this); - ChatCache = new ReadOnlyList(chatCache); AddChatLine += CacheChatLine; } diff --git a/OpenRA.Game/Primitives/ReadOnlyList.cs b/OpenRA.Game/Primitives/ReadOnlyList.cs deleted file mode 100644 index 9f32c07b32..0000000000 --- a/OpenRA.Game/Primitives/ReadOnlyList.cs +++ /dev/null @@ -1,81 +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 list 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 IReadOnlyList : IEnumerable - { - int Count { get; } - T this[int index] { get; } - } - - public static class ReadOnlyList - { - public static IReadOnlyList AsReadOnly(this IList list) - { - return list as IReadOnlyList ?? new ReadOnlyList(list); - } - } - - /// - /// A minimal read only list for .NET 4 implemented as a wrapper - /// around an IList. - /// - public class ReadOnlyList : IReadOnlyList - { - private readonly IList list; - - public ReadOnlyList() - : this(new List()) - { - } - - public ReadOnlyList(IList list) - { - if (list == null) - throw new ArgumentNullException(nameof(list)); - - this.list = list; - } - - #region IEnumerable implementation - public IEnumerator GetEnumerator() - { - return list.GetEnumerator(); - } - #endregion - - #region IEnumerable implementation - System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() - { - return list.GetEnumerator(); - } - #endregion - - #region IReadOnlyList implementation - public int Count => list.Count; - - public T this[int index] => list[index]; - - #endregion - } -} diff --git a/OpenRA.Mods.Cnc/SpriteLoaders/ShpRemasteredLoader.cs b/OpenRA.Mods.Cnc/SpriteLoaders/ShpRemasteredLoader.cs index a63bb02bb4..7f29925856 100644 --- a/OpenRA.Mods.Cnc/SpriteLoaders/ShpRemasteredLoader.cs +++ b/OpenRA.Mods.Cnc/SpriteLoaders/ShpRemasteredLoader.cs @@ -10,6 +10,7 @@ #endregion using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; @@ -111,7 +112,7 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders } } - Frames = frames.AsReadOnly(); + Frames = frames; } } } diff --git a/OpenRA.Mods.Cnc/SpriteLoaders/ShpTDLoader.cs b/OpenRA.Mods.Cnc/SpriteLoaders/ShpTDLoader.cs index 2aae542308..3075ccc5ff 100644 --- a/OpenRA.Mods.Cnc/SpriteLoaders/ShpTDLoader.cs +++ b/OpenRA.Mods.Cnc/SpriteLoaders/ShpTDLoader.cs @@ -134,7 +134,6 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders stream.Position += 4; var headers = new ImageHeader[imageCount]; - Frames = headers.AsReadOnly(); for (var i = 0; i < headers.Length; i++) headers[i] = new ImageHeader(stream, this); @@ -156,6 +155,8 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders foreach (var h in headers) Decompress(h); + + Frames = headers; } void Decompress(ImageHeader h) diff --git a/OpenRA.Mods.Cnc/Traits/TDGunboat.cs b/OpenRA.Mods.Cnc/Traits/TDGunboat.cs index 671c275253..e9bd6e935a 100644 --- a/OpenRA.Mods.Cnc/Traits/TDGunboat.cs +++ b/OpenRA.Mods.Cnc/Traits/TDGunboat.cs @@ -42,8 +42,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 occupied; + return new Dictionary() { { location, SubCell.FullCell } }; } bool IOccupySpaceInfo.SharesCell => false; diff --git a/OpenRA.Mods.Common/SpriteLoaders/DdsLoader.cs b/OpenRA.Mods.Common/SpriteLoaders/DdsLoader.cs index 463f5f882e..67023ff6d3 100644 --- a/OpenRA.Mods.Common/SpriteLoaders/DdsLoader.cs +++ b/OpenRA.Mods.Common/SpriteLoaders/DdsLoader.cs @@ -9,6 +9,7 @@ */ #endregion +using System.Collections.Generic; using System.IO; using System.Linq; using OpenRA.Graphics; @@ -74,7 +75,7 @@ namespace OpenRA.Mods.Common.SpriteLoaders public DdsSprite(Stream stream) { - Frames = new ISpriteFrame[] { new DdsFrame(stream) }.AsReadOnly(); + Frames = new ISpriteFrame[] { new DdsFrame(stream) }; } } } diff --git a/OpenRA.Mods.Common/SpriteLoaders/TgaLoader.cs b/OpenRA.Mods.Common/SpriteLoaders/TgaLoader.cs index ae40e6a728..dd9a72e306 100644 --- a/OpenRA.Mods.Common/SpriteLoaders/TgaLoader.cs +++ b/OpenRA.Mods.Common/SpriteLoaders/TgaLoader.cs @@ -9,6 +9,7 @@ */ #endregion +using System.Collections.Generic; using System.IO; using System.Linq; using OpenRA.Graphics; @@ -108,7 +109,7 @@ namespace OpenRA.Mods.Common.SpriteLoaders public TgaSprite(Stream stream) { - Frames = new ISpriteFrame[] { new TgaFrame(stream) }.AsReadOnly(); + Frames = new ISpriteFrame[] { new TgaFrame(stream) }; } } } diff --git a/OpenRA.Mods.Common/Traits/Buildings/Building.cs b/OpenRA.Mods.Common/Traits/Buildings/Building.cs index 8cca1e1562..f313c3e8ab 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/Building.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/Building.cs @@ -239,10 +239,8 @@ namespace OpenRA.Mods.Common.Traits public IReadOnlyDictionary OccupiedCells(ActorInfo info, CPos topLeft, SubCell subCell = SubCell.Any) { - var occupied = OccupiedTiles(topLeft) + return OccupiedTiles(topLeft) .ToDictionary(c => c, c => SubCell.FullCell); - - 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 0221d1091e..e5bbf41076 100644 --- a/OpenRA.Mods.Common/Traits/Crates/Crate.cs +++ b/OpenRA.Mods.Common/Traits/Crates/Crate.cs @@ -34,8 +34,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 occupied; + return new Dictionary() { { location, SubCell.FullCell } }; } bool IOccupySpaceInfo.SharesCell => false; diff --git a/OpenRA.Mods.Common/Traits/Husk.cs b/OpenRA.Mods.Common/Traits/Husk.cs index 8ff89e313c..32df5d169e 100644 --- a/OpenRA.Mods.Common/Traits/Husk.cs +++ b/OpenRA.Mods.Common/Traits/Husk.cs @@ -37,8 +37,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 occupied; + return new Dictionary() { { location, SubCell.FullCell } }; } bool IOccupySpaceInfo.SharesCell => false; diff --git a/OpenRA.Mods.Common/Traits/Immobile.cs b/OpenRA.Mods.Common/Traits/Immobile.cs index c3b2eb27aa..2d43778387 100644 --- a/OpenRA.Mods.Common/Traits/Immobile.cs +++ b/OpenRA.Mods.Common/Traits/Immobile.cs @@ -21,10 +21,8 @@ namespace OpenRA.Mods.Common.Traits public IReadOnlyDictionary OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any) { - var occupied = OccupiesSpace ? new Dictionary() { { location, SubCell.FullCell } } : + return OccupiesSpace ? new Dictionary() { { location, SubCell.FullCell } } : new Dictionary(); - - return occupied; } bool IOccupySpaceInfo.SharesCell => false; diff --git a/OpenRA.Mods.Common/Traits/Player/MissionObjectives.cs b/OpenRA.Mods.Common/Traits/Player/MissionObjectives.cs index 2e126c2d06..4174354ee1 100644 --- a/OpenRA.Mods.Common/Traits/Player/MissionObjectives.cs +++ b/OpenRA.Mods.Common/Traits/Player/MissionObjectives.cs @@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.Traits public readonly MissionObjectivesInfo Info; readonly List objectives = new List(); readonly Player player; - public ReadOnlyList Objectives; + public IReadOnlyList Objectives => objectives; Player[] enemies; Player[] allies; @@ -92,7 +92,6 @@ namespace OpenRA.Mods.Common.Traits { Info = info; this.player = player; - Objectives = new ReadOnlyList(objectives); } void IWorldLoaded.WorldLoaded(World w, WorldRenderer wr) diff --git a/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs b/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs index 01cb252b8c..4d39d52a37 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs @@ -77,12 +77,7 @@ namespace OpenRA.Mods.Common.Traits var radarColorInfo = Info.TraitInfoOrDefault(); RadarColor = radarColorInfo == null ? owner.Color : radarColorInfo.GetColorFromTerrain(world); - if (ios != null) - Footprint = ios.OccupiedCells(Info, location, subCell); - else - { - Footprint = new Dictionary() { { location, SubCell.FullCell } }; - } + Footprint = ios?.OccupiedCells(Info, location, subCell) ?? new Dictionary() { { location, SubCell.FullCell } }; tooltip = Info.TraitInfos().FirstOrDefault(info => info.EnabledByDefault) as TooltipInfoBase ?? Info.TraitInfos().FirstOrDefault(info => info.EnabledByDefault); diff --git a/OpenRA.Mods.Common/Traits/World/MapOptions.cs b/OpenRA.Mods.Common/Traits/World/MapOptions.cs index 388ff007e3..7116c7eb7f 100644 --- a/OpenRA.Mods.Common/Traits/World/MapOptions.cs +++ b/OpenRA.Mods.Common/Traits/World/MapOptions.cs @@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Traits if (techLevels.Any()) yield return new LobbyOption("techlevel", TechLevelDropdownLabel, TechLevelDropdownDescription, TechLevelDropdownVisible, TechLevelDropdownDisplayOrder, - techLevels, TechLevel, TechLevelDropdownLocked); + techLevels, TechLevel, TechLevelDropdownLocked); var gameSpeeds = Game.ModData.Manifest.Get().Speeds .ToDictionary(s => s.Key, s => s.Value.Name);