Rules.Categories
This commit is contained in:
@@ -10,7 +10,8 @@ namespace OpenRa.Game
|
||||
static class Rules
|
||||
{
|
||||
public static IniFile AllRules;
|
||||
public static Dictionary<string, List<String>> Categories;
|
||||
public static Dictionary<string, List<string>> Categories = new Dictionary<string,List<string>>();
|
||||
public static Dictionary<string, string> UnitCategory;
|
||||
public static InfoLoader<UnitInfo> UnitInfo;
|
||||
public static InfoLoader<WeaponInfo> WeaponInfo;
|
||||
public static InfoLoader<WarheadInfo> WarheadInfo;
|
||||
@@ -24,39 +25,39 @@ namespace OpenRa.Game
|
||||
FileSystem.Open( "units.ini" ),
|
||||
FileSystem.Open( "campaignUnits.ini" ) );
|
||||
|
||||
Categories = LoadCategories(
|
||||
"BuildingTypes",
|
||||
"InfantryTypes",
|
||||
"VehicleTypes",
|
||||
"ShipTypes",
|
||||
"PlaneTypes",
|
||||
"WeaponTypes",
|
||||
"WarheadTypes",
|
||||
"ProjectileTypes" );
|
||||
LoadCategories(
|
||||
"Building",
|
||||
"Infantry",
|
||||
"Vehicle",
|
||||
"Ship",
|
||||
"Plane" );
|
||||
UnitCategory = Categories.SelectMany( x => x.Value.Select( y => new KeyValuePair<string, string>( y, x.Key ) ) ).ToDictionary( x => x.Key, x => x.Value );
|
||||
|
||||
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)),
|
||||
Pair.New<string,Func<string,UnitInfo>>( "VehicleTypes", s => new UnitInfo.VehicleInfo(s)),
|
||||
Pair.New<string,Func<string,UnitInfo>>( "ShipTypes", s => new UnitInfo.VehicleInfo(s)),
|
||||
Pair.New<string,Func<string,UnitInfo>>( "PlaneTypes", s => new UnitInfo.VehicleInfo(s)));
|
||||
Pair.New<string,Func<string,UnitInfo>>( "Building", s => new UnitInfo.BuildingInfo(s)),
|
||||
Pair.New<string,Func<string,UnitInfo>>( "Infantry", s => new UnitInfo.InfantryInfo(s)),
|
||||
Pair.New<string,Func<string,UnitInfo>>( "Vehicle", s => new UnitInfo.VehicleInfo(s)),
|
||||
Pair.New<string,Func<string,UnitInfo>>( "Ship", s => new UnitInfo.VehicleInfo(s)),
|
||||
Pair.New<string,Func<string,UnitInfo>>( "Plane", s => new UnitInfo.VehicleInfo(s)));
|
||||
|
||||
LoadCategories(
|
||||
"Weapon",
|
||||
"Warhead",
|
||||
"Projectile" );
|
||||
|
||||
WeaponInfo = new InfoLoader<WeaponInfo>(
|
||||
Pair.New<string,Func<string,WeaponInfo>>("WeaponTypes", _ => new WeaponInfo()));
|
||||
Pair.New<string,Func<string,WeaponInfo>>("Weapon", _ => new WeaponInfo()));
|
||||
WarheadInfo = new InfoLoader<WarheadInfo>(
|
||||
Pair.New<string,Func<string,WarheadInfo>>("WarheadTypes", _ => new WarheadInfo()));
|
||||
Pair.New<string,Func<string,WarheadInfo>>("Warhead", _ => new WarheadInfo()));
|
||||
|
||||
ProjectileInfo = new InfoLoader<ProjectileInfo>(
|
||||
Pair.New<string, Func<string, ProjectileInfo>>("ProjectileTypes", _ => new ProjectileInfo()));
|
||||
Pair.New<string, Func<string, ProjectileInfo>>("Projectile", _ => new ProjectileInfo()));
|
||||
}
|
||||
|
||||
static Dictionary<string, List<string>> LoadCategories( params string[] types )
|
||||
static void 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;
|
||||
Categories[ t ] = AllRules.GetSection( t + "Types" ).Select( x => x.Key.ToLowerInvariant() ).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user