EntityPrototypeHelpers.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using JetBrains.Annotations;
  2. using Robust.Shared.Prototypes;
  3. namespace Content.Shared.Prototypes
  4. {
  5. [UsedImplicitly]
  6. public static class EntityPrototypeHelpers
  7. {
  8. public static bool HasComponent<T>(this EntityPrototype prototype, IComponentFactory? componentFactory = null) where T : IComponent
  9. {
  10. return prototype.HasComponent(typeof(T), componentFactory);
  11. }
  12. public static bool HasComponent(this EntityPrototype prototype, Type component, IComponentFactory? componentFactory = null)
  13. {
  14. componentFactory ??= IoCManager.Resolve<IComponentFactory>();
  15. var registration = componentFactory.GetRegistration(component);
  16. return prototype.Components.ContainsKey(registration.Name);
  17. }
  18. public static bool HasComponent<T>(string prototype, IPrototypeManager? prototypeManager = null, IComponentFactory? componentFactory = null) where T : IComponent
  19. {
  20. return HasComponent(prototype, typeof(T), prototypeManager, componentFactory);
  21. }
  22. public static bool HasComponent(string prototype, Type component, IPrototypeManager? prototypeManager = null, IComponentFactory? componentFactory = null)
  23. {
  24. prototypeManager ??= IoCManager.Resolve<IPrototypeManager>();
  25. return prototypeManager.TryIndex(prototype, out EntityPrototype? proto) && proto.HasComponent(component, componentFactory);
  26. }
  27. }
  28. }