#nullable enable
using System;
using System.Diagnostics.CodeAnalysis;
using Content.Shared.GameObjects.Components.Body.Part.Property;
namespace Content.Shared.GameObjects.Components.Body.Part
{
public static class BodyPartExtensions
{
///
/// Checks if the given has the specified property.
///
/// The to check in.
///
/// The type of to check for.
///
/// true if found, false otherwise.
public static bool HasProperty(this IBodyPart part, Type type)
{
return part.Owner.HasComponent(type);
}
///
/// Checks if the given has the specified property.
///
/// The to check in.
///
/// The type of to check for.
///
/// true if found, false otherwise.
public static bool HasProperty(this IBodyPart part) where T : class, IBodyPartProperty
{
return part.HasProperty(typeof(T));
}
///
/// Tries to retrieve the with the
/// specified type.
///
/// The to search in.
///
/// The type of to search for.
///
///
/// The property, if it was found. Null otherwise.
///
///
/// true if a component with the specified type was found, false otherwise.
///
public static bool TryGetProperty(this IBodyPart part, Type type,
[NotNullWhen(true)] out IBodyPartProperty? property)
{
if (!part.Owner.TryGetComponent(type, out var component))
{
property = null;
return false;
}
return (property = component as IBodyPartProperty) != null;
}
///
/// Tries to retrieve the with the
/// specified type.
///
/// The to search in.
///
/// The type of to search for.
///
///
/// The property, if it was found. Null otherwise.
///
///
/// true if a component with the specified type was found, false otherwise.
///
public static bool TryGetProperty(this IBodyPart part, [NotNullWhen(true)] out T? property) where T : class, IBodyPartProperty
{
return part.Owner.TryGetComponent(out property);
}
}
}