Remove our own ReadOnlyDictionary and update usages

This commit is contained in:
teinarss
2021-03-16 20:03:38 +01:00
committed by reaperrr
parent afbdb395b2
commit e12ff2c59d
44 changed files with 73 additions and 142 deletions

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Eluant; using Eluant;

View File

@@ -294,6 +294,11 @@ namespace OpenRA
public int Count => mods.Count; public int Count => mods.Count;
public ICollection<string> Keys => mods.Keys; public ICollection<string> Keys => mods.Keys;
public ICollection<ExternalMod> Values => mods.Values; public ICollection<ExternalMod> Values => mods.Values;
IEnumerable<string> IReadOnlyDictionary<string, ExternalMod>.Keys => ((IReadOnlyDictionary<string, ExternalMod>)mods).Keys;
IEnumerable<ExternalMod> IReadOnlyDictionary<string, ExternalMod>.Values => ((IReadOnlyDictionary<string, ExternalMod>)mods).Values;
public bool ContainsKey(string key) { return mods.ContainsKey(key); } public bool ContainsKey(string key) { return mods.ContainsKey(key); }
public IEnumerator<KeyValuePair<string, ExternalMod>> GetEnumerator() { return mods.GetEnumerator(); } public IEnumerator<KeyValuePair<string, ExternalMod>> GetEnumerator() { return mods.GetEnumerator(); }
public bool TryGetValue(string key, out ExternalMod value) { return mods.TryGetValue(key, out value); } public bool TryGetValue(string key, out ExternalMod value) { return mods.TryGetValue(key, out value); }

View File

@@ -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 ReadOnlyDictionary<string, T>(yamlNodes.ToDictionaryWithConflictLog(k => k.Key.ToLowerInvariant(), makeObject, "LoadFromManifest<" + name + ">")); return new Dictionary<string, T>(yamlNodes.ToDictionaryWithConflictLog(k => k.Key.ToLowerInvariant(), makeObject, "LoadFromManifest<" + name + ">"));
} }
public static Ruleset LoadDefaults(ModData modData) public static Ruleset LoadDefaults(ModData modData)

View File

@@ -52,7 +52,7 @@ namespace OpenRA.Graphics
public readonly Dictionary<string, Rectangle> Regions = new Dictionary<string, Rectangle>(); public readonly Dictionary<string, Rectangle> Regions = new Dictionary<string, Rectangle>();
} }
public static IReadOnlyDictionary<string, Collection> Collections { get; private set; } public static IReadOnlyDictionary<string, Collection> Collections => collections;
static Dictionary<string, Collection> collections; static Dictionary<string, Collection> collections;
static Dictionary<string, (Sheet Sheet, int Density)> cachedSheets; static Dictionary<string, (Sheet Sheet, int Density)> cachedSheets;
static Dictionary<string, Dictionary<string, Sprite>> cachedSprites; static Dictionary<string, Dictionary<string, Sprite>> cachedSprites;
@@ -77,8 +77,6 @@ namespace OpenRA.Graphics
cachedPanelSprites = new Dictionary<string, Sprite[]>(); cachedPanelSprites = new Dictionary<string, Sprite[]>();
cachedCollectionSheets = new Dictionary<Collection, (Sheet, int)>(); cachedCollectionSheets = new Dictionary<Collection, (Sheet, int)>();
Collections = new ReadOnlyDictionary<string, Collection>(collections);
var chrome = MiniYaml.Merge(modData.Manifest.Chrome var chrome = MiniYaml.Merge(modData.Manifest.Chrome
.Select(s => MiniYaml.FromStream(fileSystem.Open(s), s))); .Select(s => MiniYaml.FromStream(fileSystem.Open(s), s)));

View File

@@ -38,8 +38,7 @@ namespace OpenRA.Graphics
Palettes = nodesDict["Cursors"].Nodes.Select(n => n.Value.Value) Palettes = nodesDict["Cursors"].Nodes.Select(n => n.Value.Value)
.Where(p => p != null) .Where(p => p != null)
.Distinct() .Distinct()
.ToDictionary(p => p, p => pals[p].ReadPalette(modData.DefaultFileSystem)) .ToDictionary(p => p, p => pals[p].ReadPalette(modData.DefaultFileSystem));
.AsReadOnly();
var frameCache = new FrameCache(fileSystem, modData.SpriteLoaders); var frameCache = new FrameCache(fileSystem, modData.SpriteLoaders);
var cursors = new Dictionary<string, CursorSequence>(); var cursors = new Dictionary<string, CursorSequence>();
@@ -47,7 +46,7 @@ namespace OpenRA.Graphics
foreach (var sequence in s.Value.Nodes) foreach (var sequence in s.Value.Nodes)
cursors.Add(sequence.Key, new CursorSequence(frameCache, sequence.Key, s.Key, s.Value.Value, sequence.Value)); 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) public bool HasCursorSequence(string cursor)

View File

@@ -28,7 +28,7 @@ namespace OpenRA.Graphics
public HardwarePalette() public HardwarePalette()
{ {
Texture = Game.Renderer.Context.CreateTexture(); Texture = Game.Renderer.Context.CreateTexture();
readOnlyModifiablePalettes = modifiablePalettes.AsReadOnly(); readOnlyModifiablePalettes = modifiablePalettes;
} }
public bool Contains(string name) public bool Contains(string name)

View File

@@ -10,6 +10,7 @@
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using OpenRA.FileSystem; using OpenRA.FileSystem;
using OpenRA.Primitives; using OpenRA.Primitives;

View File

@@ -125,7 +125,7 @@ namespace OpenRA.Graphics
} }
} }
return new ReadOnlyDictionary<string, UnitSequences>(items); return items;
} }
public void Preload() public void Preload()

View File

@@ -16,7 +16,6 @@ using System.IO;
using System.Linq; using System.Linq;
using OpenRA.FileSystem; using OpenRA.FileSystem;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Primitives;
namespace OpenRA namespace OpenRA
{ {
@@ -100,9 +99,9 @@ namespace OpenRA
} }
public Manifest this[string key] => mods[key]; public Manifest this[string key] => mods[key];
public IEnumerable<string> Keys => mods.Keys;
public IEnumerable<Manifest> Values => mods.Values;
public int Count => mods.Count; public int Count => mods.Count;
public ICollection<string> Keys => mods.Keys;
public ICollection<Manifest> Values => mods.Values;
public bool ContainsKey(string key) { return mods.ContainsKey(key); } public bool ContainsKey(string key) { return mods.ContainsKey(key); }
public IEnumerator<KeyValuePair<string, Manifest>> GetEnumerator() { return mods.GetEnumerator(); } public IEnumerator<KeyValuePair<string, Manifest>> GetEnumerator() { return mods.GetEnumerator(); }
public bool TryGetValue(string key, out Manifest value) { return mods.TryGetValue(key, out value); } public bool TryGetValue(string key, out Manifest value) { return mods.TryGetValue(key, out value); }

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using OpenRA.FileSystem; using OpenRA.FileSystem;
@@ -127,7 +128,7 @@ namespace OpenRA
MapFolders = YamlDictionary(yaml, "MapFolders"); MapFolders = YamlDictionary(yaml, "MapFolders");
if (yaml.TryGetValue("Packages", out var packages)) if (yaml.TryGetValue("Packages", out var packages))
Packages = packages.ToDictionary(x => x.Value).AsReadOnly(); Packages = packages.ToDictionary(x => x.Value);
Rules = YamlList(yaml, "Rules"); Rules = YamlList(yaml, "Rules");
Sequences = YamlList(yaml, "Sequences"); Sequences = YamlList(yaml, "Sequences");
@@ -213,10 +214,10 @@ namespace OpenRA
static IReadOnlyDictionary<string, string> YamlDictionary(Dictionary<string, MiniYaml> yaml, string key) static IReadOnlyDictionary<string, string> YamlDictionary(Dictionary<string, MiniYaml> yaml, string key)
{ {
if (!yaml.ContainsKey(key)) if (!yaml.ContainsKey(key))
return new ReadOnlyDictionary<string, string>(); return new Dictionary<string, string>();
var inner = yaml[key].ToDictionary(my => my.Value); var inner = yaml[key].ToDictionary(my => my.Value);
return new ReadOnlyDictionary<string, string>(inner); return inner;
} }
public bool Contains<T>() where T : IGlobalModData public bool Contains<T>() where T : IGlobalModData

View File

@@ -26,7 +26,7 @@ namespace OpenRA
public sealed class MapCache : IEnumerable<MapPreview>, IDisposable public sealed class MapCache : IEnumerable<MapPreview>, IDisposable
{ {
public static readonly MapPreview UnknownMap = new MapPreview(null, null, MapGridType.Rectangular, null); public static readonly MapPreview UnknownMap = new MapPreview(null, null, MapGridType.Rectangular, null);
public readonly IReadOnlyDictionary<IReadOnlyPackage, MapClassification> MapLocations; public IReadOnlyDictionary<IReadOnlyPackage, MapClassification> MapLocations => mapLocations;
readonly Dictionary<IReadOnlyPackage, MapClassification> mapLocations = new Dictionary<IReadOnlyPackage, MapClassification>(); readonly Dictionary<IReadOnlyPackage, MapClassification> mapLocations = new Dictionary<IReadOnlyPackage, MapClassification>();
readonly Cache<string, MapPreview> previews; readonly Cache<string, MapPreview> previews;
@@ -46,8 +46,6 @@ namespace OpenRA
var gridType = Exts.Lazy(() => modData.Manifest.Get<MapGrid>().Type); var gridType = Exts.Lazy(() => modData.Manifest.Get<MapGrid>().Type);
previews = new Cache<string, MapPreview>(uid => new MapPreview(modData, uid, gridType.Value, this)); previews = new Cache<string, MapPreview>(uid => new MapPreview(modData, uid, gridType.Value, this));
sheetBuilder = new SheetBuilder(SheetType.BGRA); sheetBuilder = new SheetBuilder(SheetType.BGRA);
MapLocations = new ReadOnlyDictionary<IReadOnlyPackage, MapClassification>(mapLocations);
} }
public void LoadMaps() public void LoadMaps()

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using OpenRA.FileSystem; using OpenRA.FileSystem;

View File

@@ -40,6 +40,11 @@ namespace OpenRA.Primitives
public ICollection<T> Keys => cache.Keys; public ICollection<T> Keys => cache.Keys;
public ICollection<U> Values => cache.Values; public ICollection<U> Values => cache.Values;
IEnumerable<T> IReadOnlyDictionary<T, U>.Keys => cache.Keys;
IEnumerable<U> IReadOnlyDictionary<T, U>.Values => cache.Values;
public IEnumerator<KeyValuePair<T, U>> GetEnumerator() { return cache.GetEnumerator(); } public IEnumerator<KeyValuePair<T, U>> GetEnumerator() { return cache.GetEnumerator(); }
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); }
} }

View File

@@ -12,6 +12,7 @@
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace OpenRA.Primitives namespace OpenRA.Primitives
{ {
@@ -33,12 +34,13 @@ namespace OpenRA.Primitives
: this(loader, EqualityComparer<T>.Default) { } : this(loader, EqualityComparer<T>.Default) { }
public U this[T key] => cache.GetOrAdd(key, loader); public U this[T key] => cache.GetOrAdd(key, loader);
public IEnumerable<T> Keys => cache.Keys;
public IEnumerable<U> Values => cache.Values;
public bool ContainsKey(T key) { return cache.ContainsKey(key); } public bool ContainsKey(T key) { return cache.ContainsKey(key); }
public bool TryGetValue(T key, out U value) { return cache.TryGetValue(key, out value); } public bool TryGetValue(T key, out U value) { return cache.TryGetValue(key, out value); }
public int Count => cache.Count; public int Count => cache.Count;
public ICollection<T> Keys => cache.Keys;
public ICollection<U> Values => cache.Values;
public IEnumerator<KeyValuePair<T, U>> GetEnumerator() { return cache.GetEnumerator(); } public IEnumerator<KeyValuePair<T, U>> GetEnumerator() { return cache.GetEnumerator(); }
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return GetEnumerator(); }
} }

View File

@@ -52,10 +52,13 @@ namespace OpenRA.Primitives
public T this[int playerIndex] => valueByPlayerIndex[playerIndex]; public T this[int playerIndex] => valueByPlayerIndex[playerIndex];
public int Count => valueByPlayerIndex.Length; public int Count => valueByPlayerIndex.Length;
public IEnumerable<Player> Keys => ((IReadOnlyDictionary<Player, T>)valueByPlayer).Keys;
public IEnumerable<T> Values => ((IReadOnlyDictionary<Player, T>)valueByPlayer).Values;
public IEnumerator<T> GetEnumerator() { return ((IEnumerable<T>)valueByPlayerIndex).GetEnumerator(); } public IEnumerator<T> GetEnumerator() { return ((IEnumerable<T>)valueByPlayerIndex).GetEnumerator(); }
ICollection<Player> IReadOnlyDictionary<Player, T>.Keys => valueByPlayer.Keys;
ICollection<T> IReadOnlyDictionary<Player, T>.Values => valueByPlayer.Values;
bool IReadOnlyDictionary<Player, T>.ContainsKey(Player key) { return valueByPlayer.ContainsKey(key); } bool IReadOnlyDictionary<Player, T>.ContainsKey(Player key) { return valueByPlayer.ContainsKey(key); }
bool IReadOnlyDictionary<Player, T>.TryGetValue(Player key, out T value) { return valueByPlayer.TryGetValue(key, out value); } bool IReadOnlyDictionary<Player, T>.TryGetValue(Player key, out T value) { return valueByPlayer.TryGetValue(key, out value); }
IEnumerator<KeyValuePair<Player, T>> IEnumerable<KeyValuePair<Player, T>>.GetEnumerator() { return valueByPlayer.GetEnumerator(); } IEnumerator<KeyValuePair<Player, T>> IEnumerable<KeyValuePair<Player, T>>.GetEnumerator() { return valueByPlayer.GetEnumerator(); }

View File

@@ -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
{
/// <summary>
/// A minimal read only dictionary 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 IReadOnlyDictionary<TKey, TValue> : IEnumerable<KeyValuePair<TKey, TValue>>
{
int Count { get; }
TValue this[TKey key] { get; }
ICollection<TKey> Keys { get; }
ICollection<TValue> Values { get; }
bool ContainsKey(TKey key);
bool TryGetValue(TKey key, out TValue value);
}
public static class ReadOnlyDictionary
{
public static IReadOnlyDictionary<TKey, TValue> AsReadOnly<TKey, TValue>(this IDictionary<TKey, TValue> dict)
{
return dict as IReadOnlyDictionary<TKey, TValue> ?? new ReadOnlyDictionary<TKey, TValue>(dict);
}
}
/// <summary>
/// A minimal read only dictionary for .NET 4 implemented as a wrapper
/// around an IDictionary.
/// </summary>
public class ReadOnlyDictionary<TKey, TValue> : IReadOnlyDictionary<TKey, TValue>
{
private readonly IDictionary<TKey, TValue> dict;
public ReadOnlyDictionary()
: this(new Dictionary<TKey, TValue>())
{
}
public ReadOnlyDictionary(IDictionary<TKey, TValue> 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<TKey> Keys => dict.Keys;
public ICollection<TValue> Values => dict.Values;
#endregion
#region IEnumerable implementation
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
{
return dict.GetEnumerator();
}
#endregion
#region IEnumerable implementation
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return dict.GetEnumerator();
}
#endregion
}
}

View File

@@ -113,7 +113,7 @@ namespace OpenRA
fontSheetBuilder = new SheetBuilder(SheetType.BGRA, 512); fontSheetBuilder = new SheetBuilder(SheetType.BGRA, 512);
Fonts = modData.Manifest.Get<Fonts>().FontList.ToDictionary(x => x.Key, Fonts = modData.Manifest.Get<Fonts>().FontList.ToDictionary(x => x.Key,
x => new SpriteFont(x.Value.Font, modData.DefaultFileSystem.Open(x.Value.Font).ReadAllBytes(), 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) => Window.OnWindowScaleChanged += (oldNative, oldEffective, newNative, newEffective) =>

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using OpenRA.Activities; using OpenRA.Activities;
using OpenRA.FileSystem; using OpenRA.FileSystem;

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using OpenRA.FileSystem; using OpenRA.FileSystem;

View File

@@ -9,6 +9,7 @@
*/ */
#endregion #endregion
using System.Collections.Generic;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Primitives; using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;

View File

@@ -10,6 +10,7 @@
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using OpenRA.Activities; using OpenRA.Activities;
using OpenRA.Mods.Common; using OpenRA.Mods.Common;
@@ -42,7 +43,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 } }; var occupied = new Dictionary<CPos, SubCell>() { { location, SubCell.FullCell } };
return new ReadOnlyDictionary<CPos, SubCell>(occupied); return occupied;
} }
bool IOccupySpaceInfo.SharesCell => false; bool IOccupySpaceInfo.SharesCell => false;

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using ICSharpCode.SharpZipLib.Zip.Compression; using ICSharpCode.SharpZipLib.Zip.Compression;

View File

@@ -10,6 +10,7 @@
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO; using System.IO;
using OpenRA.FileSystem; using OpenRA.FileSystem;
using OpenRA.Mods.Common.FileFormats; using OpenRA.Mods.Common.FileFormats;

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using OpenRA.Graphics; using OpenRA.Graphics;

View File

@@ -10,6 +10,7 @@
#endregion #endregion
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using OpenRA.GameRules; using OpenRA.GameRules;

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using OpenRA.FileFormats; using OpenRA.FileFormats;

View File

@@ -115,7 +115,7 @@ namespace OpenRA.Mods.Common.Terrain
// Templates // Templates
Templates = yaml["Templates"].ToDictionary().Values 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]; public TerrainTypeInfo this[byte index] => TerrainInfo[index];

View File

@@ -9,6 +9,8 @@
*/ */
#endregion #endregion
using System.Collections.Generic;
namespace OpenRA.Mods.Common.Terrain namespace OpenRA.Mods.Common.Terrain
{ {
public interface ITemplatedTerrainInfo : ITerrainInfo public interface ITemplatedTerrainInfo : ITerrainInfo

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using OpenRA.Activities; using OpenRA.Activities;
using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Activities;
@@ -179,7 +180,7 @@ namespace OpenRA.Mods.Common.Traits
yield return new FacingInit(PreviewFacing); yield return new FacingInit(PreviewFacing);
} }
public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any) { return new ReadOnlyDictionary<CPos, SubCell>(); } public IReadOnlyDictionary<CPos, SubCell> OccupiedCells(ActorInfo info, CPos location, SubCell subCell = SubCell.Any) { return new Dictionary<CPos, SubCell>(); }
bool IOccupySpaceInfo.SharesCell => false; bool IOccupySpaceInfo.SharesCell => false;

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Traits; using OpenRA.Traits;
@@ -241,7 +242,7 @@ namespace OpenRA.Mods.Common.Traits
var occupied = OccupiedTiles(topLeft) var occupied = OccupiedTiles(topLeft)
.ToDictionary(c => c, c => SubCell.FullCell); .ToDictionary(c => c, c => SubCell.FullCell);
return new ReadOnlyDictionary<CPos, SubCell>(occupied); return occupied;
} }
bool IOccupySpaceInfo.SharesCell => false; bool IOccupySpaceInfo.SharesCell => false;

View File

@@ -35,7 +35,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 } }; var occupied = new Dictionary<CPos, SubCell>() { { location, SubCell.FullCell } };
return new ReadOnlyDictionary<CPos, SubCell>(occupied); return occupied;
} }
bool IOccupySpaceInfo.SharesCell => false; bool IOccupySpaceInfo.SharesCell => false;

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using OpenRA.Activities; using OpenRA.Activities;
using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Activities;

View File

@@ -10,6 +10,7 @@
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Activities;
using OpenRA.Primitives; using OpenRA.Primitives;
@@ -37,7 +38,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 } }; var occupied = new Dictionary<CPos, SubCell>() { { location, SubCell.FullCell } };
return new ReadOnlyDictionary<CPos, SubCell>(occupied); return occupied;
} }
bool IOccupySpaceInfo.SharesCell => false; bool IOccupySpaceInfo.SharesCell => false;

View File

@@ -10,7 +10,6 @@
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits namespace OpenRA.Mods.Common.Traits
@@ -25,7 +24,7 @@ namespace OpenRA.Mods.Common.Traits
var occupied = OccupiesSpace ? new Dictionary<CPos, SubCell>() { { location, SubCell.FullCell } } : var occupied = OccupiesSpace ? new Dictionary<CPos, SubCell>() { { location, SubCell.FullCell } } :
new Dictionary<CPos, SubCell>(); new Dictionary<CPos, SubCell>();
return new ReadOnlyDictionary<CPos, SubCell>(occupied); return occupied;
} }
bool IOccupySpaceInfo.SharesCell => false; bool IOccupySpaceInfo.SharesCell => false;

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using OpenRA.Activities; using OpenRA.Activities;
using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Activities;
@@ -130,7 +131,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)
{ {
return new ReadOnlyDictionary<CPos, SubCell>(new Dictionary<CPos, SubCell>() { { location, subCell } }); return new Dictionary<CPos, SubCell>() { { location, subCell } };
} }
bool IOccupySpaceInfo.SharesCell => LocomotorInfo.SharesCell; bool IOccupySpaceInfo.SharesCell => LocomotorInfo.SharesCell;

View File

@@ -9,6 +9,7 @@
*/ */
#endregion #endregion
using System.Collections.Generic;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Primitives; using OpenRA.Primitives;
using OpenRA.Traits; using OpenRA.Traits;

View File

@@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Traits
if (startingCash.Any()) if (startingCash.Any())
yield return new LobbyOption("startingcash", DefaultCashDropdownLabel, DefaultCashDropdownDescription, DefaultCashDropdownVisible, DefaultCashDropdownDisplayOrder, yield return new LobbyOption("startingcash", DefaultCashDropdownLabel, DefaultCashDropdownDescription, DefaultCashDropdownVisible, DefaultCashDropdownDisplayOrder,
new ReadOnlyDictionary<string, string>(startingCash), DefaultCash.ToString(), DefaultCashDropdownLocked); startingCash, DefaultCash.ToString(), DefaultCashDropdownLocked);
} }
public override object Create(ActorInitializer init) { return new PlayerResources(init.Self, this); } public override object Create(ActorInitializer init) { return new PlayerResources(init.Self, this); }

View File

@@ -84,7 +84,7 @@ namespace OpenRA.Mods.Common.Traits
}); });
yield return new LobbyOption("timelimit", TimeLimitLabel, TimeLimitDescription, TimeLimitDropdownVisible, TimeLimitDisplayOrder, yield return new LobbyOption("timelimit", TimeLimitLabel, TimeLimitDescription, TimeLimitDropdownVisible, TimeLimitDisplayOrder,
new ReadOnlyDictionary<string, string>(timelimits), TimeLimitDefault.ToString(), TimeLimitLocked); timelimits, TimeLimitDefault.ToString(), TimeLimitLocked);
} }
public override object Create(ActorInitializer init) { return new TimeLimitManager(init.Self, this); } public override object Create(ActorInitializer init) { return new TimeLimitManager(init.Self, this); }

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using OpenRA.Graphics; using OpenRA.Graphics;
@@ -80,8 +81,7 @@ namespace OpenRA.Mods.Common.Traits
Footprint = ios.OccupiedCells(Info, location, subCell); Footprint = ios.OccupiedCells(Info, location, subCell);
else else
{ {
var footprint = new Dictionary<CPos, SubCell>() { { location, SubCell.FullCell } }; Footprint = new Dictionary<CPos, SubCell>() { { location, SubCell.FullCell } };
Footprint = new ReadOnlyDictionary<CPos, SubCell>(footprint);
} }
tooltip = Info.TraitInfos<EditorOnlyTooltipInfo>().FirstOrDefault(info => info.EnabledByDefault) as TooltipInfoBase tooltip = Info.TraitInfos<EditorOnlyTooltipInfo>().FirstOrDefault(info => info.EnabledByDefault) as TooltipInfoBase

View File

@@ -82,14 +82,14 @@ 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,
new ReadOnlyDictionary<string, string>(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);
// NOTE: The server hardcodes special-case logic for this option id // NOTE: The server hardcodes special-case logic for this option id
yield return new LobbyOption("gamespeed", GameSpeedDropdownLabel, GameSpeedDropdownDescription, GameSpeedDropdownVisible, GameSpeedDropdownDisplayOrder, yield return new LobbyOption("gamespeed", GameSpeedDropdownLabel, GameSpeedDropdownDescription, GameSpeedDropdownVisible, GameSpeedDropdownDisplayOrder,
new ReadOnlyDictionary<string, string>(gameSpeeds), GameSpeed, GameSpeedDropdownLocked); gameSpeeds, GameSpeed, GameSpeedDropdownLocked);
} }
void IRulesetLoaded<ActorInfo>.RulesetLoaded(Ruleset rules, ActorInfo info) void IRulesetLoaded<ActorInfo>.RulesetLoaded(Ruleset rules, ActorInfo info)

View File

@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Traits
IEnumerable<LobbyOption> ILobbyOptions.LobbyOptions(Ruleset rules) IEnumerable<LobbyOption> ILobbyOptions.LobbyOptions(Ruleset rules)
{ {
yield return new LobbyOption(ID, Label, Description, Visible, DisplayOrder, yield return new LobbyOption(ID, Label, Description, Visible, DisplayOrder,
new ReadOnlyDictionary<string, string>(Values), Default, Locked); Values, Default, Locked);
} }
public override object Create(ActorInitializer init) { return new ScriptLobbyDropdown(this); } public override object Create(ActorInitializer init) { return new ScriptLobbyDropdown(this); }

View File

@@ -48,7 +48,7 @@ namespace OpenRA.Mods.Common.Traits
if (startingUnits.Any()) if (startingUnits.Any())
yield return new LobbyOption("startingunits", DropdownLabel, DropdownDescription, DropdownVisible, DropdownDisplayOrder, yield return new LobbyOption("startingunits", DropdownLabel, DropdownDescription, DropdownVisible, DropdownDisplayOrder,
new ReadOnlyDictionary<string, string>(startingUnits), StartingUnitsClass, DropdownLocked); startingUnits, StartingUnitsClass, DropdownLocked);
} }
public override object Create(ActorInitializer init) { return new SpawnStartingUnits(this); } public override object Create(ActorInitializer init) { return new SpawnStartingUnits(this); }

View File

@@ -10,6 +10,7 @@
#endregion #endregion
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO; using System.IO;
using NUnit.Framework; using NUnit.Framework;
using OpenRA.Support; using OpenRA.Support;
@@ -19,13 +20,13 @@ namespace OpenRA.Test
[TestFixture] [TestFixture]
public class VariableExpressionTest public class VariableExpressionTest
{ {
IReadOnlyDictionary<string, int> testValues = new ReadOnlyDictionary<string, int>(new Dictionary<string, int>() IReadOnlyDictionary<string, int> testValues = new Dictionary<string, int>
{ {
{ "t", 5 }, { "t", 5 },
{ "t-1", 7 }, { "t-1", 7 },
{ "one", 1 }, { "one", 1 },
{ "five", 5 } { "five", 5 }
}); };
void AssertFalse(string expression) void AssertFalse(string expression)
{ {