2022-05-13 00:59:03 -07:00
|
|
|
|
using JetBrains.Annotations;
|
2020-10-26 23:19:46 +01:00
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Shared.Prototypes
|
2020-10-26 23:19:46 +01:00
|
|
|
|
{
|
2020-10-28 11:12:37 +01:00
|
|
|
|
[UsedImplicitly]
|
2020-10-26 23:19:46 +01:00
|
|
|
|
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-26 23:19:46 +01:00
|
|
|
|
{
|
2020-10-28 11:12:37 +01:00
|
|
|
|
return prototype.HasComponent(typeof(T), componentFactory);
|
2020-10-26 23:19:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-28 11:12:37 +01:00
|
|
|
|
public static bool HasComponent(this EntityPrototype prototype, Type component, IComponentFactory? componentFactory = null)
|
2020-10-26 23:19:46 +01:00
|
|
|
|
{
|
|
|
|
|
|
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>();
|
2020-10-26 23:19:46 +01:00
|
|
|
|
|
2023-01-19 03:56:45 +01:00
|
|
|
|
return prototypeManager.TryIndex(prototype, out EntityPrototype? proto) && proto.HasComponent(component, componentFactory);
|
2020-10-26 23:19:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|