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