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:
RoosterDragon
2014-05-21 05:14:16 +01:00
parent 334a210231
commit 2e992a7310
21 changed files with 104 additions and 74 deletions

View File

@@ -80,8 +80,9 @@ namespace OpenRA
static object LoadOptions(MiniYaml y)
{
var options = new MapOptions();
if (y.NodesDict.ContainsKey("Options"))
FieldLoader.Load(options, y.NodesDict["Options"]);
var nodesDict = y.ToDictionary();
if (nodesDict.ContainsKey("Options"))
FieldLoader.Load(options, nodesDict["Options"]);
return options;
}
@@ -185,18 +186,20 @@ namespace OpenRA
RequiresMod = upgradeForMod;
}
var nd = yaml.ToDictionary();
// Load players
foreach (var kv in yaml.NodesDict["Players"].NodesDict)
foreach (var my in nd["Players"].ToDictionary().Values)
{
var player = new PlayerReference(kv.Value);
var player = new PlayerReference(my);
Players.Add(player.Name, player);
}
Actors = Exts.Lazy(() =>
{
var ret = new Dictionary<string, ActorReference>();
foreach (var kv in yaml.NodesDict["Actors"].NodesDict)
ret.Add(kv.Key, new ActorReference(kv.Value.Value, kv.Value.NodesDict));
foreach (var kv in nd["Actors"].ToDictionary())
ret.Add(kv.Key, new ActorReference(kv.Value.Value, kv.Value.ToDictionary()));
return ret;
});
@@ -204,9 +207,9 @@ namespace OpenRA
Smudges = Exts.Lazy(() =>
{
var ret = new List<SmudgeReference>();
foreach (var kv in yaml.NodesDict["Smudges"].NodesDict)
foreach (var name in nd["Smudges"].ToDictionary().Keys)
{
var vals = kv.Key.Split(' ');
var vals = name.Split(' ');
var loc = vals[1].Split(',');
ret.Add(new SmudgeReference(vals[0], new int2(
Exts.ParseIntegerInvariant(loc[0]),

View File

@@ -56,9 +56,9 @@ namespace OpenRA
static object LoadTiles(MiniYaml y)
{
return y.NodesDict["Tiles"].NodesDict.ToDictionary(
t => byte.Parse(t.Key),
t => t.Value.Value);
return y.ToDictionary()["Tiles"].ToDictionary(
name => byte.Parse(name),
my => my.Value);
}
static readonly string[] Fields = { "Id", "Image", "Frames", "Size", "PickAny" };
@@ -105,11 +105,11 @@ namespace OpenRA
FieldLoader.Load(this, yaml["General"]);
// TerrainTypes
Terrain = yaml["Terrain"].NodesDict.Values
Terrain = yaml["Terrain"].ToDictionary().Values
.Select(y => new TerrainTypeInfo(y)).ToDictionary(t => t.Type);
// Templates
Templates = yaml["Templates"].NodesDict.Values
Templates = yaml["Templates"].ToDictionary().Values
.Select(y => new TileTemplate(y)).ToDictionary(t => t.Id);
}