clean that up...

This commit is contained in:
Chris Forbes
2010-04-04 13:04:39 +12:00
parent 7ff04ee333
commit 3d0b0dc82b
2 changed files with 18 additions and 12 deletions

View File

@@ -56,7 +56,7 @@ namespace OpenRA
static bool changePending; static bool changePending;
public static Pair<Assembly, string>[] ModAssemblies; public static Pair<Assembly, string>[] ModAssemblies;
public static void LoadModPackages(Manifest manifest) static void LoadModPackages(Manifest manifest)
{ {
FileSystem.UnmountAll(); FileSystem.UnmountAll();
Timer.Time("reset: {0}"); Timer.Time("reset: {0}");
@@ -67,7 +67,7 @@ namespace OpenRA
Timer.Time("mount temporary packages: {0}"); Timer.Time("mount temporary packages: {0}");
} }
internal static void LoadModAssemblies(Manifest m) static void LoadModAssemblies(Manifest m)
{ {
// All the core namespaces // All the core namespaces
var asms = typeof(Game).Assembly.GetNamespaces() var asms = typeof(Game).Assembly.GetNamespaces()
@@ -97,6 +97,19 @@ namespace OpenRA
ModAssemblies = asms.ToArray(); ModAssemblies = asms.ToArray();
} }
public static T CreateObject<T>(string classname)
{
foreach (var mod in ModAssemblies)
{
var fullTypeName = mod.Second + "." + classname;
var obj = mod.First.CreateInstance(fullTypeName);
if (obj != null)
return (T)obj;
}
throw new InvalidOperationException("Cannot locate type: {0}".F(classname));
}
public static void ChangeMap(string mapName) public static void ChangeMap(string mapName)
{ {
Timer.Time( "----ChangeMap" ); Timer.Time( "----ChangeMap" );

View File

@@ -71,18 +71,11 @@ namespace OpenRA.GameRules
static ITraitInfo LoadTraitInfo(string traitName, MiniYaml my) static ITraitInfo LoadTraitInfo(string traitName, MiniYaml my)
{ {
foreach (var mod in Game.ModAssemblies) var info = Game.CreateObject<ITraitInfo>(traitName + "Info");
{
var fullTypeName = mod.Second + "." + traitName + "Info";
var info = (ITraitInfo)mod.First.CreateInstance(fullTypeName);
if (info == null) continue;
FieldLoader.Load(info, my); FieldLoader.Load(info, my);
return info; return info;
} }
throw new InvalidOperationException("Cannot locate trait: {0}".F(traitName));
}
public IEnumerable<ITraitInfo> TraitsInConstructOrder() public IEnumerable<ITraitInfo> TraitsInConstructOrder()
{ {
var ret = new List<ITraitInfo>(); var ret = new List<ITraitInfo>();