Changed MiniYaml.NodesDict property into a method.
Method is now called ToDictionary. - Cached a few invocations into locals which should prevent some redundant evaluation. - Added ToDictionary overloads that take projection functions for the keys and elements, since several callsites were doing a subsequent Linq.ToDictionary call to get this.
This commit is contained in:
@@ -31,20 +31,20 @@ namespace OpenRA.Graphics
|
||||
var sequences = new MiniYaml(null, sequenceFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.MergeLiberal));
|
||||
var shadowIndex = new int[] { };
|
||||
|
||||
if (sequences.NodesDict.ContainsKey("ShadowIndex"))
|
||||
var nodesDict = sequences.ToDictionary();
|
||||
if (nodesDict.ContainsKey("ShadowIndex"))
|
||||
{
|
||||
Array.Resize(ref shadowIndex, shadowIndex.Length + 1);
|
||||
Exts.TryParseIntegerInvariant(sequences.NodesDict["ShadowIndex"].Value,
|
||||
Exts.TryParseIntegerInvariant(nodesDict["ShadowIndex"].Value,
|
||||
out shadowIndex[shadowIndex.Length - 1]);
|
||||
}
|
||||
|
||||
palette = new HardwarePalette();
|
||||
foreach (var p in sequences.NodesDict["Palettes"].Nodes)
|
||||
foreach (var p in nodesDict["Palettes"].Nodes)
|
||||
palette.AddPalette(p.Key, new Palette(GlobalFileSystem.Open(p.Value.Value), shadowIndex), false);
|
||||
|
||||
|
||||
var spriteLoader = new SpriteLoader(new string[0], new SheetBuilder(SheetType.Indexed));
|
||||
foreach (var s in sequences.NodesDict["Cursors"].Nodes)
|
||||
foreach (var s in nodesDict["Cursors"].Nodes)
|
||||
LoadSequencesForCursor(spriteLoader, s.Key, s.Value);
|
||||
|
||||
palette.Initialize();
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace OpenRA.Graphics
|
||||
public CursorSequence(SpriteLoader loader, string cursorSrc, string palette, MiniYaml info)
|
||||
{
|
||||
sprites = loader.LoadAllSprites(cursorSrc);
|
||||
var d = info.NodesDict;
|
||||
var d = info.ToDictionary();
|
||||
|
||||
start = Exts.ParseIntegerInvariant(d["start"].Value);
|
||||
this.palette = palette;
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace OpenRA.Graphics
|
||||
{
|
||||
var srcOverride = info.Value;
|
||||
Name = name;
|
||||
var d = info.NodesDict;
|
||||
var d = info.ToDictionary();
|
||||
var offset = float2.Zero;
|
||||
var blendMode = BlendMode.Alpha;
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ namespace OpenRA.Graphics
|
||||
else
|
||||
{
|
||||
t = Exts.Lazy(() => (IReadOnlyDictionary<string, Sequence>)new ReadOnlyDictionary<string, Sequence>(
|
||||
node.Value.NodesDict.ToDictionary(x => x.Key, x =>
|
||||
node.Value.ToDictionary().ToDictionary(x => x.Key, x =>
|
||||
{
|
||||
using (new Support.PerfTimer("new Sequence(\"{0}\")".F(node.Key), 20))
|
||||
return new Sequence(spriteLoader.Value, node.Key, x.Key, x.Value);
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace OpenRA.Graphics
|
||||
Game.modData.VoxelLoader.RefreshBuffer();
|
||||
}
|
||||
|
||||
static Voxel LoadVoxel(string unit, string name, MiniYaml info)
|
||||
static Voxel LoadVoxel(string unit, MiniYaml info)
|
||||
{
|
||||
var vxl = unit;
|
||||
var hva = unit;
|
||||
@@ -55,7 +55,7 @@ namespace OpenRA.Graphics
|
||||
Game.modData.LoadScreen.Display();
|
||||
try
|
||||
{
|
||||
var seq = sequences.NodesDict.ToDictionary(x => x.Key, x => LoadVoxel(unit,x.Key,x.Value));
|
||||
var seq = sequences.ToDictionary(my => LoadVoxel(unit, my));
|
||||
units.Add(unit, seq);
|
||||
}
|
||||
catch (FileNotFoundException) {} // Do nothing; we can crash later if we actually wanted art
|
||||
|
||||
Reference in New Issue
Block a user