Clean up some trait info loading code

Remove some methods that traits define to load their YAML values on their own.
This commit is contained in:
Pavel Penev
2015-08-28 02:12:20 +03:00
parent 8ddbabbfde
commit 256929073c
7 changed files with 9 additions and 102 deletions

View File

@@ -114,23 +114,18 @@ namespace OpenRA.Mods.Common.AI
string IBotInfo.Name { get { return this.Name; } }
[Desc("What units to the AI should build.", "What % of the total army must be this type of unit.")]
[FieldLoader.LoadUsing("LoadUnits")]
public readonly Dictionary<string, float> UnitsToBuild = null;
[Desc("What buildings to the AI should build.", "What % of the total base must be this type of building.")]
[FieldLoader.LoadUsing("LoadBuildings")]
public readonly Dictionary<string, float> BuildingFractions = null;
[Desc("Tells the AI what unit types fall under the same common name.")]
[FieldLoader.LoadUsing("LoadUnitsCommonNames")]
public readonly Dictionary<string, string[]> UnitsCommonNames = null;
[Desc("Tells the AI what building types fall under the same common name.")]
[FieldLoader.LoadUsing("LoadBuildingsCommonNames")]
public readonly Dictionary<string, string[]> BuildingCommonNames = null;
[Desc("What buildings should the AI have max limits n.", "What is the limit of the building.")]
[FieldLoader.LoadUsing("LoadBuildingLimits")]
public readonly Dictionary<string, int> BuildingLimits = null;
// TODO Update OpenRA.Utility/Command.cs#L300 to first handle lists and also read nested ones
@@ -138,22 +133,6 @@ namespace OpenRA.Mods.Common.AI
[FieldLoader.LoadUsing("LoadDecisions")]
public readonly List<SupportPowerDecision> PowerDecisions = new List<SupportPowerDecision>();
static object LoadList<T>(MiniYaml y, string field)
{
var nd = y.ToDictionary();
return nd.ContainsKey(field)
? nd[field].ToDictionary(my => FieldLoader.GetValue<T>(field, my.Value))
: new Dictionary<string, T>();
}
static object LoadUnits(MiniYaml y) { return LoadList<float>(y, "UnitsToBuild"); }
static object LoadBuildings(MiniYaml y) { return LoadList<float>(y, "BuildingFractions"); }
static object LoadUnitsCommonNames(MiniYaml y) { return LoadList<string[]>(y, "UnitsCommonNames"); }
static object LoadBuildingsCommonNames(MiniYaml y) { return LoadList<string[]>(y, "BuildingCommonNames"); }
static object LoadBuildingLimits(MiniYaml y) { return LoadList<int>(y, "BuildingLimits"); }
static object LoadDecisions(MiniYaml yaml)
{
var ret = new List<SupportPowerDecision>();