Make verbs be created through IDynamicTypeFactory
To allow for dependencies to be declared on them
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Shared.GameObjects.Verbs
|
||||
@@ -16,6 +17,8 @@ namespace Content.Shared.GameObjects.Verbs
|
||||
// This works for now though.
|
||||
public static IEnumerable<(IComponent, Verb)> GetVerbs(IEntity entity)
|
||||
{
|
||||
var typeFactory = IoCManager.Resolve<IDynamicTypeFactory>();
|
||||
|
||||
foreach (var component in entity.GetAllComponents())
|
||||
{
|
||||
var type = component.GetType();
|
||||
@@ -26,7 +29,7 @@ namespace Content.Shared.GameObjects.Verbs
|
||||
continue;
|
||||
}
|
||||
|
||||
var verb = (Verb)Activator.CreateInstance(nestedType);
|
||||
var verb = typeFactory.CreateInstance<Verb>(nestedType);
|
||||
yield return (component, verb);
|
||||
}
|
||||
}
|
||||
@@ -38,6 +41,8 @@ namespace Content.Shared.GameObjects.Verbs
|
||||
/// <param name="assembly">The assembly to search for global verbs in.</param>
|
||||
public static IEnumerable<GlobalVerb> GetGlobalVerbs(Assembly assembly)
|
||||
{
|
||||
var typeFactory = IoCManager.Resolve<IDynamicTypeFactory>();
|
||||
|
||||
foreach (Type type in assembly.GetTypes())
|
||||
{
|
||||
if (Attribute.IsDefined(type, typeof(GlobalVerbAttribute)))
|
||||
@@ -46,7 +51,7 @@ namespace Content.Shared.GameObjects.Verbs
|
||||
{
|
||||
continue;
|
||||
}
|
||||
yield return (GlobalVerb)Activator.CreateInstance(type);
|
||||
yield return typeFactory.CreateInstance<GlobalVerb>(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user