Fix Loading of scripts

This commit is contained in:
hondacrx
2017-06-28 23:53:41 -04:00
parent 658fc1b672
commit 6ccf8d1ff0
3 changed files with 26 additions and 22 deletions
+18 -13
View File
@@ -77,34 +77,39 @@ namespace Game.Scripting
foreach (var type in asm.GetTypes())
{
var attributes = (ScriptAttribute[])type.GetCustomAttributes<ScriptAttribute>(true);
var attributes = (ScriptAttribute[])type.GetCustomAttributes<ScriptAttribute>();
if (attributes.Empty())
{
var baseType = type.BaseType;
while (baseType != null)
{
if (baseType == typeof(ScriptObject))
{
Log.outWarn(LogFilter.Server, "Script {0} does not have ScriptAttribute", type.Name);
continue;
}
baseType = baseType.BaseType;
}
}
var constructors = type.GetConstructors();
if (constructors.Length == 0)
else
{
Log.outError(LogFilter.Scripts, "Type: {0} contains no Public Constructors. Can't load script.", type.Name);
break;
}
foreach (var attribute in attributes)
{
if (!constructors.Any(p => p.GetParameters().Length == attribute.Args.Length))
var constructors = type.GetConstructors();
if (constructors.Length == 0)
{
Log.outError(LogFilter.Scripts, "Type: {0} has ScriptAttribute that does not match paramter count: {1} Can't load script.", type.Name, attribute.Args.Length);
Log.outError(LogFilter.Scripts, "Type: {0} contains no Public Constructors. Can't load script.", type.Name);
continue;
}
Activator.CreateInstance(type, attribute.Args);
foreach (var attribute in attributes)
{
if (!constructors.Any(p => p.GetParameters().Length == attribute.Args.Length))
{
Log.outError(LogFilter.Scripts, "Type: {0} has ScriptAttribute that does not match paramter count: {1} Can't load script.", type.Name, attribute.Args.Length);
continue;
}
Activator.CreateInstance(type, attribute.Args);
}
}
}