Rules.Categories
This commit is contained in:
@@ -15,9 +15,8 @@ namespace OpenRa.Game.GameRules
|
||||
public InfoLoader(params Pair<string, Func<string,T>>[] srcs)
|
||||
{
|
||||
foreach (var src in srcs)
|
||||
foreach (var s in Rules.AllRules.GetSection(src.First))
|
||||
foreach (var name in Rules.Categories[src.First])
|
||||
{
|
||||
var name = s.Key.ToLowerInvariant();
|
||||
var t = src.Second(name);
|
||||
FieldLoader.Load(t, Rules.AllRules.GetSection(name));
|
||||
infos[name] = t;
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace OpenRa.Game
|
||||
static class Rules
|
||||
{
|
||||
public static IniFile AllRules;
|
||||
public static Dictionary<string, List<String>> Categories;
|
||||
public static InfoLoader<UnitInfo> UnitInfo;
|
||||
public static InfoLoader<WeaponInfo> WeaponInfo;
|
||||
public static InfoLoader<WarheadInfo> WarheadInfo;
|
||||
@@ -23,6 +24,16 @@ namespace OpenRa.Game
|
||||
FileSystem.Open( "units.ini" ),
|
||||
FileSystem.Open( "campaignUnits.ini" ) );
|
||||
|
||||
Categories = LoadCategories(
|
||||
"BuildingTypes",
|
||||
"InfantryTypes",
|
||||
"VehicleTypes",
|
||||
"ShipTypes",
|
||||
"PlaneTypes",
|
||||
"WeaponTypes",
|
||||
"WarheadTypes",
|
||||
"ProjectileTypes" );
|
||||
|
||||
UnitInfo = new InfoLoader<UnitInfo>(
|
||||
Pair.New<string,Func<string,UnitInfo>>( "BuildingTypes", s => new UnitInfo.BuildingInfo(s)),
|
||||
Pair.New<string,Func<string,UnitInfo>>( "InfantryTypes", s => new UnitInfo.InfantryInfo(s)),
|
||||
@@ -38,5 +49,14 @@ namespace OpenRa.Game
|
||||
ProjectileInfo = new InfoLoader<ProjectileInfo>(
|
||||
Pair.New<string, Func<string, ProjectileInfo>>("ProjectileTypes", _ => new ProjectileInfo()));
|
||||
}
|
||||
|
||||
static Dictionary<string, List<string>> LoadCategories( params string[] types )
|
||||
{
|
||||
var ret = new Dictionary<string, List<string>>();
|
||||
foreach( var t in types )
|
||||
ret[ t ] = AllRules.GetSection( t ).Select( x => x.Key.ToLowerInvariant() ).ToList();
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user