duplication
This commit is contained in:
@@ -20,25 +20,31 @@ namespace OpenRa.Game.GameRules
|
|||||||
throw new InvalidOperationException();
|
throw new InvalidOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Func<string, IniSection, BaseInfo> BindInfoCtor<T>()
|
||||||
|
where T : BaseInfo
|
||||||
|
{
|
||||||
|
var ctor = typeof(T).GetConstructor(new[] { typeof(string), typeof(IniSection) });
|
||||||
|
return (s, i) => (BaseInfo)ctor.Invoke(new object [] { s,i });
|
||||||
|
}
|
||||||
|
|
||||||
readonly Dictionary<string, BaseInfo> unitInfos = new Dictionary<string, BaseInfo>();
|
readonly Dictionary<string, BaseInfo> unitInfos = new Dictionary<string, BaseInfo>();
|
||||||
|
|
||||||
public UnitInfo( IniFile rules )
|
public UnitInfo( IniFile rules )
|
||||||
{
|
{
|
||||||
foreach( var s in Util.ReadAllLines( FileSystem.Open( "buildings.txt" ) ) )
|
var srcs = new []
|
||||||
{
|
{
|
||||||
var unitName = s.Split( ',' )[ 0 ];
|
Pair.New( "buildings.txt", BindInfoCtor<BuildingInfo>() ),
|
||||||
unitInfos.Add( unitName.ToLowerInvariant(), new BuildingInfo( unitName, rules.GetSection( unitName ) ) );
|
Pair.New( "infantry.txt", BindInfoCtor<InfantryInfo>() ),
|
||||||
}
|
Pair.New( "vehicles.txt", BindInfoCtor<VehicleInfo>() ),
|
||||||
foreach( var s in Util.ReadAllLines( FileSystem.Open( "infantry.txt" ) ) )
|
};
|
||||||
{
|
|
||||||
var unitName = s.Split( ',' )[ 0 ];
|
foreach( var src in srcs )
|
||||||
unitInfos.Add( unitName.ToLowerInvariant(), new InfantryInfo( unitName, rules.GetSection( unitName ) ) );
|
foreach (var s in Util.ReadAllLines(FileSystem.Open(src.First)))
|
||||||
}
|
{
|
||||||
foreach( var s in Util.ReadAllLines( FileSystem.Open( "vehicles.txt" ) ) )
|
var unitName = s.Split(',')[0];
|
||||||
{
|
unitInfos.Add(unitName.ToLowerInvariant(),
|
||||||
var unitName = s.Split( ',' )[ 0 ];
|
src.Second(unitName, rules.GetSection(unitName)));
|
||||||
unitInfos.Add( unitName.ToLowerInvariant(), new VehicleInfo( unitName, rules.GetSection( unitName ) ) );
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public BaseInfo Get( string unitName )
|
public BaseInfo Get( string unitName )
|
||||||
|
|||||||
Reference in New Issue
Block a user