Allow IGlobalModData to opt-in to custom parsing.

This commit is contained in:
Paul Chote
2015-03-08 20:40:14 +00:00
parent 60937b096b
commit 2cc714be4e

View File

@@ -154,8 +154,20 @@ namespace OpenRA
if (t == null || !typeof(IGlobalModData).IsAssignableFrom(t))
throw new InvalidDataException("`{0}` is not a valid mod manifest entry.".F(kv.Key));
var module = oc.CreateObject<IGlobalModData>(kv.Key);
FieldLoader.Load(module, kv.Value);
IGlobalModData module;
var ctor = t.GetConstructor(new Type[] { typeof(MiniYaml) } );
if (ctor != null)
{
// Class has opted-in to DIY initialization
module = (IGlobalModData)ctor.Invoke(new object[] { kv.Value });
}
else
{
// Automatically load the child nodes using FieldLoader
module = oc.CreateObject<IGlobalModData>(kv.Key);
FieldLoader.Load(module, kv.Value);
}
modules.Add(module);
}
}