Files
tbd-station-14/Content.Shared/Utility/EntityPrototypeHelpers.cs
Acruid ca4fd649fe Massive Namespace Cleanup (#3120)
* Engine namespace changes.

* Automated remove redundant using statements.

* Simplified Graphics namespace.

* Apparently the container system stores full type names in the map file.😞 This updates those names.

* API Changes to LocalizationManager.LoadCulture.

* Update submodule to v0.3.2
2021-02-11 01:13:03 -08:00

40 lines
1.5 KiB
C#

#nullable enable
using System;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Prototypes;
namespace Content.Shared.Utility
{
[UsedImplicitly]
public static class EntityPrototypeHelpers
{
public static bool HasComponent<T>(this EntityPrototype prototype, IComponentFactory? componentFactory = null) where T : IComponent
{
return prototype.HasComponent(typeof(T), componentFactory);
}
public static bool HasComponent(this EntityPrototype prototype, Type component, IComponentFactory? componentFactory = null)
{
componentFactory ??= IoCManager.Resolve<IComponentFactory>();
var registration = componentFactory.GetRegistration(component);
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);
}
}
}