Rewrite ActorInit queries.

This commit is contained in:
Paul Chote
2020-05-24 22:28:16 +01:00
committed by teinarss
parent 626b40f31b
commit 7c6ec577dc
66 changed files with 332 additions and 265 deletions

View File

@@ -41,11 +41,18 @@ namespace OpenRA.Mods.Common.Scripting
if (initType == null)
throw new LuaException("Unknown initializer type '{0}'".F(typeName));
// Cast it up to an IActorInit<T>
var genericType = initType.GetInterfaces()
.First(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IActorInit<>));
var innerType = genericType.GetGenericArguments().First();
var valueType = innerType.IsEnum ? Enum.GetUnderlyingType(innerType) : innerType;
// HACK: Handle OwnerInit as a special case until ActorInit creation can be rewritten
Type innerType, valueType;
if (initType != typeof(OwnerInit))
{
// Cast it up to an IActorInit<T>
var genericType = initType.GetInterfaces()
.First(x => x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IActorInit<>));
innerType = genericType.GetGenericArguments().First();
valueType = innerType.IsEnum ? Enum.GetUnderlyingType(innerType) : innerType;
}
else
innerType = valueType = typeof(Player);
// Try and coerce the table value to the required type
object value;