Files
OldThink/Content.Shared/Prototypes/EntityPrototypeHelpers.cs

36 lines
1.4 KiB
C#
Raw Permalink Normal View History

2022-05-13 00:59:03 -07:00
using JetBrains.Annotations;
using Robust.Shared.Prototypes;
2021-06-09 22:19:39 +02:00
namespace Content.Shared.Prototypes
{
2020-10-28 11:12:37 +01:00
[UsedImplicitly]
public static class EntityPrototypeHelpers
{
2020-10-28 11:12:37 +01:00
public static bool HasComponent<T>(this EntityPrototype prototype, IComponentFactory? componentFactory = null) where T : IComponent
{
2020-10-28 11:12:37 +01:00
return prototype.HasComponent(typeof(T), componentFactory);
}
2020-10-28 11:12:37 +01:00
public static bool HasComponent(this EntityPrototype prototype, Type component, IComponentFactory? componentFactory = null)
{
componentFactory ??= IoCManager.Resolve<IComponentFactory>();
var registration = componentFactory.GetRegistration(component);
2020-10-28 11:12:37 +01:00
return prototype.Components.ContainsKey(registration.Name);
}
public static bool HasComponent<T>(string prototype, IPrototypeManager? prototypeManager = null, IComponentFactory? componentFactory = null) where T : IComponent
{
return HasComponent(prototype, typeof(T), prototypeManager, componentFactory);
}
public static bool HasComponent(string prototype, Type component, IPrototypeManager? prototypeManager = null, IComponentFactory? componentFactory = null)
{
prototypeManager ??= IoCManager.Resolve<IPrototypeManager>();
return prototypeManager.TryIndex(prototype, out EntityPrototype? proto) && proto.HasComponent(component, componentFactory);
}
}
}