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()
@@ -96,6 +96,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)
{ {

View File

@@ -71,16 +71,9 @@ 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");
{ FieldLoader.Load(info, my);
var fullTypeName = mod.Second + "." + traitName + "Info"; return info;
var info = (ITraitInfo)mod.First.CreateInstance(fullTypeName);
if (info == null) continue;
FieldLoader.Load(info, my);
return info;
}
throw new InvalidOperationException("Cannot locate trait: {0}".F(traitName));
} }
public IEnumerable<ITraitInfo> TraitsInConstructOrder() public IEnumerable<ITraitInfo> TraitsInConstructOrder()