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

@@ -41,11 +41,12 @@ namespace OpenRA.Mods.RA.Move
static object LoadSpeeds(MiniYaml y)
{
Dictionary<string, TerrainInfo> ret = new Dictionary<string, TerrainInfo>();
foreach (var t in y.NodesDict["TerrainSpeeds"].Nodes)
foreach (var t in y.ToDictionary()["TerrainSpeeds"].Nodes)
{
var speed = FieldLoader.GetValue<decimal>("speed", t.Value.Value);
var cost = t.Value.NodesDict.ContainsKey("PathingCost")
? FieldLoader.GetValue<int>("cost", t.Value.NodesDict["PathingCost"].Value)
var nodesDict = t.Value.ToDictionary();
var cost = nodesDict.ContainsKey("PathingCost")
? FieldLoader.GetValue<int>("cost", nodesDict["PathingCost"].Value)
: (int)(10000 / speed);
ret.Add(t.Key, new TerrainInfo { Speed = speed, Cost = cost });
}