Remove our own impl of ReadOnlyList and update usages
This commit is contained in:
@@ -115,7 +115,7 @@ namespace OpenRA
|
|||||||
if (filterNode != null)
|
if (filterNode != null)
|
||||||
yamlNodes = yamlNodes.Where(k => !filterNode(k));
|
yamlNodes = yamlNodes.Where(k => !filterNode(k));
|
||||||
|
|
||||||
return new Dictionary<string, T>(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)
|
public static Ruleset LoadDefaults(ModData modData)
|
||||||
|
|||||||
@@ -21,14 +21,12 @@ namespace OpenRA.Graphics
|
|||||||
public int Height { get; private set; }
|
public int Height { get; private set; }
|
||||||
readonly Dictionary<string, ImmutablePalette> palettes = new Dictionary<string, ImmutablePalette>();
|
readonly Dictionary<string, ImmutablePalette> palettes = new Dictionary<string, ImmutablePalette>();
|
||||||
readonly Dictionary<string, MutablePalette> modifiablePalettes = new Dictionary<string, MutablePalette>();
|
readonly Dictionary<string, MutablePalette> modifiablePalettes = new Dictionary<string, MutablePalette>();
|
||||||
readonly IReadOnlyDictionary<string, MutablePalette> readOnlyModifiablePalettes;
|
|
||||||
readonly Dictionary<string, int> indices = new Dictionary<string, int>();
|
readonly Dictionary<string, int> indices = new Dictionary<string, int>();
|
||||||
byte[] buffer = new byte[0];
|
byte[] buffer = new byte[0];
|
||||||
|
|
||||||
public HardwarePalette()
|
public HardwarePalette()
|
||||||
{
|
{
|
||||||
Texture = Game.Renderer.Context.CreateTexture();
|
Texture = Game.Renderer.Context.CreateTexture();
|
||||||
readOnlyModifiablePalettes = modifiablePalettes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Contains(string name)
|
public bool Contains(string name)
|
||||||
@@ -109,7 +107,7 @@ namespace OpenRA.Graphics
|
|||||||
public void ApplyModifiers(IEnumerable<IPaletteModifier> paletteMods)
|
public void ApplyModifiers(IEnumerable<IPaletteModifier> paletteMods)
|
||||||
{
|
{
|
||||||
foreach (var mod in paletteMods)
|
foreach (var mod in paletteMods)
|
||||||
mod.AdjustPalette(readOnlyModifiablePalettes);
|
mod.AdjustPalette(modifiablePalettes);
|
||||||
|
|
||||||
// Update our texture with the changes.
|
// Update our texture with the changes.
|
||||||
CopyModifiablePalettesToBuffer();
|
CopyModifiablePalettesToBuffer();
|
||||||
|
|||||||
@@ -216,8 +216,7 @@ namespace OpenRA
|
|||||||
if (!yaml.ContainsKey(key))
|
if (!yaml.ContainsKey(key))
|
||||||
return new Dictionary<string, string>();
|
return new Dictionary<string, string>();
|
||||||
|
|
||||||
var inner = yaml[key].ToDictionary(my => my.Value);
|
return yaml[key].ToDictionary(my => my.Value);
|
||||||
return inner;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Contains<T>() where T : IGlobalModData
|
public bool Contains<T>() where T : IGlobalModData
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ namespace OpenRA.Network
|
|||||||
|
|
||||||
readonly List<ChatLine> chatCache = new List<ChatLine>();
|
readonly List<ChatLine> chatCache = new List<ChatLine>();
|
||||||
|
|
||||||
public readonly ReadOnlyList<ChatLine> ChatCache;
|
public IReadOnlyList<ChatLine> ChatCache => chatCache;
|
||||||
|
|
||||||
bool disposed;
|
bool disposed;
|
||||||
bool generateSyncReport = false;
|
bool generateSyncReport = false;
|
||||||
@@ -85,7 +85,6 @@ namespace OpenRA.Network
|
|||||||
Password = password;
|
Password = password;
|
||||||
Connection = conn;
|
Connection = conn;
|
||||||
syncReport = new SyncReport(this);
|
syncReport = new SyncReport(this);
|
||||||
ChatCache = new ReadOnlyList<ChatLine>(chatCache);
|
|
||||||
AddChatLine += CacheChatLine;
|
AddChatLine += CacheChatLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// A minimal read only list interface for .NET 4
|
|
||||||
/// </summary>
|
|
||||||
/// <remarks>
|
|
||||||
/// .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.
|
|
||||||
/// </remarks>
|
|
||||||
public interface IReadOnlyList<out T> : IEnumerable<T>
|
|
||||||
{
|
|
||||||
int Count { get; }
|
|
||||||
T this[int index] { get; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ReadOnlyList
|
|
||||||
{
|
|
||||||
public static IReadOnlyList<T> AsReadOnly<T>(this IList<T> list)
|
|
||||||
{
|
|
||||||
return list as IReadOnlyList<T> ?? new ReadOnlyList<T>(list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A minimal read only list for .NET 4 implemented as a wrapper
|
|
||||||
/// around an IList.
|
|
||||||
/// </summary>
|
|
||||||
public class ReadOnlyList<T> : IReadOnlyList<T>
|
|
||||||
{
|
|
||||||
private readonly IList<T> list;
|
|
||||||
|
|
||||||
public ReadOnlyList()
|
|
||||||
: this(new List<T>())
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public ReadOnlyList(IList<T> list)
|
|
||||||
{
|
|
||||||
if (list == null)
|
|
||||||
throw new ArgumentNullException(nameof(list));
|
|
||||||
|
|
||||||
this.list = list;
|
|
||||||
}
|
|
||||||
|
|
||||||
#region IEnumerable implementation
|
|
||||||
public IEnumerator<T> 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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
@@ -111,7 +112,7 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Frames = frames.AsReadOnly();
|
Frames = frames;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,7 +134,6 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders
|
|||||||
|
|
||||||
stream.Position += 4;
|
stream.Position += 4;
|
||||||
var headers = new ImageHeader[imageCount];
|
var headers = new ImageHeader[imageCount];
|
||||||
Frames = headers.AsReadOnly();
|
|
||||||
for (var i = 0; i < headers.Length; i++)
|
for (var i = 0; i < headers.Length; i++)
|
||||||
headers[i] = new ImageHeader(stream, this);
|
headers[i] = new ImageHeader(stream, this);
|
||||||
|
|
||||||
@@ -156,6 +155,8 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders
|
|||||||
|
|
||||||
foreach (var h in headers)
|
foreach (var h in headers)
|
||||||
Decompress(h);
|
Decompress(h);
|
||||||
|
|
||||||
|
Frames = headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Decompress(ImageHeader h)
|
void Decompress(ImageHeader h)
|
||||||
|
|||||||
@@ -42,8 +42,7 @@ namespace OpenRA.Mods.Cnc.Traits
|
|||||||
|
|
||||||
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any)
|
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any)
|
||||||
{
|
{
|
||||||
var occupied = new Dictionary<CPos, SubCell>() { { location, SubCell.FullCell } };
|
return new Dictionary<CPos, SubCell>() { { location, SubCell.FullCell } };
|
||||||
return occupied;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IOccupySpaceInfo.SharesCell => false;
|
bool IOccupySpaceInfo.SharesCell => false;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
@@ -74,7 +75,7 @@ namespace OpenRA.Mods.Common.SpriteLoaders
|
|||||||
|
|
||||||
public DdsSprite(Stream stream)
|
public DdsSprite(Stream stream)
|
||||||
{
|
{
|
||||||
Frames = new ISpriteFrame[] { new DdsFrame(stream) }.AsReadOnly();
|
Frames = new ISpriteFrame[] { new DdsFrame(stream) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
@@ -108,7 +109,7 @@ namespace OpenRA.Mods.Common.SpriteLoaders
|
|||||||
|
|
||||||
public TgaSprite(Stream stream)
|
public TgaSprite(Stream stream)
|
||||||
{
|
{
|
||||||
Frames = new ISpriteFrame[] { new TgaFrame(stream) }.AsReadOnly();
|
Frames = new ISpriteFrame[] { new TgaFrame(stream) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -239,10 +239,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos topLeft, SubCell subCell = SubCell.Any)
|
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos topLeft, SubCell subCell = SubCell.Any)
|
||||||
{
|
{
|
||||||
var occupied = OccupiedTiles(topLeft)
|
return OccupiedTiles(topLeft)
|
||||||
.ToDictionary(c => c, c => SubCell.FullCell);
|
.ToDictionary(c => c, c => SubCell.FullCell);
|
||||||
|
|
||||||
return occupied;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IOccupySpaceInfo.SharesCell => false;
|
bool IOccupySpaceInfo.SharesCell => false;
|
||||||
|
|||||||
@@ -34,8 +34,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any)
|
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any)
|
||||||
{
|
{
|
||||||
var occupied = new Dictionary<CPos, SubCell>() { { location, SubCell.FullCell } };
|
return new Dictionary<CPos, SubCell>() { { location, SubCell.FullCell } };
|
||||||
return occupied;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IOccupySpaceInfo.SharesCell => false;
|
bool IOccupySpaceInfo.SharesCell => false;
|
||||||
|
|||||||
@@ -37,8 +37,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any)
|
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any)
|
||||||
{
|
{
|
||||||
var occupied = new Dictionary<CPos, SubCell>() { { location, SubCell.FullCell } };
|
return new Dictionary<CPos, SubCell>() { { location, SubCell.FullCell } };
|
||||||
return occupied;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IOccupySpaceInfo.SharesCell => false;
|
bool IOccupySpaceInfo.SharesCell => false;
|
||||||
|
|||||||
@@ -21,10 +21,8 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any)
|
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any)
|
||||||
{
|
{
|
||||||
var occupied = OccupiesSpace ? new Dictionary<CPos, SubCell>() { { location, SubCell.FullCell } } :
|
return OccupiesSpace ? new Dictionary<CPos, SubCell>() { { location, SubCell.FullCell } } :
|
||||||
new Dictionary<CPos, SubCell>();
|
new Dictionary<CPos, SubCell>();
|
||||||
|
|
||||||
return occupied;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IOccupySpaceInfo.SharesCell => false;
|
bool IOccupySpaceInfo.SharesCell => false;
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
public readonly MissionObjectivesInfo Info;
|
public readonly MissionObjectivesInfo Info;
|
||||||
readonly List<MissionObjective> objectives = new List<MissionObjective>();
|
readonly List<MissionObjective> objectives = new List<MissionObjective>();
|
||||||
readonly Player player;
|
readonly Player player;
|
||||||
public ReadOnlyList<MissionObjective> Objectives;
|
public IReadOnlyList<MissionObjective> Objectives => objectives;
|
||||||
|
|
||||||
Player[] enemies;
|
Player[] enemies;
|
||||||
Player[] allies;
|
Player[] allies;
|
||||||
@@ -92,7 +92,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
{
|
{
|
||||||
Info = info;
|
Info = info;
|
||||||
this.player = player;
|
this.player = player;
|
||||||
Objectives = new ReadOnlyList<MissionObjective>(objectives);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void IWorldLoaded.WorldLoaded(World w, WorldRenderer wr)
|
void IWorldLoaded.WorldLoaded(World w, WorldRenderer wr)
|
||||||
|
|||||||
@@ -77,12 +77,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
var radarColorInfo = Info.TraitInfoOrDefault<RadarColorFromTerrainInfo>();
|
var radarColorInfo = Info.TraitInfoOrDefault<RadarColorFromTerrainInfo>();
|
||||||
RadarColor = radarColorInfo == null ? owner.Color : radarColorInfo.GetColorFromTerrain(world);
|
RadarColor = radarColorInfo == null ? owner.Color : radarColorInfo.GetColorFromTerrain(world);
|
||||||
|
|
||||||
if (ios != null)
|
Footprint = ios?.OccupiedCells(Info, location, subCell) ?? new Dictionary<CPos, SubCell>() { { location, SubCell.FullCell } };
|
||||||
Footprint = ios.OccupiedCells(Info, location, subCell);
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Footprint = new Dictionary<CPos, SubCell>() { { location, SubCell.FullCell } };
|
|
||||||
}
|
|
||||||
|
|
||||||
tooltip = Info.TraitInfos<EditorOnlyTooltipInfo>().FirstOrDefault(info => info.EnabledByDefault) as TooltipInfoBase
|
tooltip = Info.TraitInfos<EditorOnlyTooltipInfo>().FirstOrDefault(info => info.EnabledByDefault) as TooltipInfoBase
|
||||||
?? Info.TraitInfos<TooltipInfo>().FirstOrDefault(info => info.EnabledByDefault);
|
?? Info.TraitInfos<TooltipInfo>().FirstOrDefault(info => info.EnabledByDefault);
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
|
|
||||||
if (techLevels.Any())
|
if (techLevels.Any())
|
||||||
yield return new LobbyOption("techlevel", TechLevelDropdownLabel, TechLevelDropdownDescription, TechLevelDropdownVisible, TechLevelDropdownDisplayOrder,
|
yield return new LobbyOption("techlevel", TechLevelDropdownLabel, TechLevelDropdownDescription, TechLevelDropdownVisible, TechLevelDropdownDisplayOrder,
|
||||||
techLevels, TechLevel, TechLevelDropdownLocked);
|
techLevels, TechLevel, TechLevelDropdownLocked);
|
||||||
|
|
||||||
var gameSpeeds = Game.ModData.Manifest.Get<GameSpeeds>().Speeds
|
var gameSpeeds = Game.ModData.Manifest.Get<GameSpeeds>().Speeds
|
||||||
.ToDictionary(s => s.Key, s => s.Value.Name);
|
.ToDictionary(s => s.Key, s => s.Value.Name);
|
||||||
|
|||||||
Reference in New Issue
Block a user