* Early commit * Early commit 2 * merging master broke my git * does anyone even read these * life is fleeting * it just works * this time passing integration tests * Remove hashset yaml serialization for now * You got a license for those nullables? * No examine, no context menu, part and mechanism parenting and visibility * Fix wrong brain sprite state * Removing layers was a mistake * just tear body system a new one and see if it still breathes * Remove redundant code * Add that comment back * Separate damage and body, component states, stomach rework * Add containers for body parts * Bring layers back pls * Fix parts magically changing color * Reimplement sprite layer visibility * Fix tests * Add leg test * Active legs is gone Crab rave * Merge fixes, rename DamageState to CurrentState * Remove IShowContextMenu and ICanExamine
51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
#nullable enable
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Linq;
|
|
using Content.Shared.GameObjects.Components.Body.Behavior;
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
|
|
namespace Content.Shared.GameObjects.Components.Body.Mechanism
|
|
{
|
|
public static class MechanismExtensions
|
|
{
|
|
public static bool HasMechanismBehavior<T>(this IEntity entity) where T : IMechanismBehavior
|
|
{
|
|
// TODO BODY optimize
|
|
return entity.TryGetBody(out var body) &&
|
|
body.Parts.Values.Any(p => p.Mechanisms.Any(m => m.Owner.HasComponent<T>()));
|
|
}
|
|
|
|
public static IEnumerable<T> GetMechanismBehaviors<T>(this IEntity entity) where T : class, IMechanismBehavior
|
|
{
|
|
if (!entity.TryGetBody(out var body))
|
|
{
|
|
yield break;
|
|
}
|
|
|
|
foreach (var part in body.Parts.Values)
|
|
foreach (var mechanism in part.Mechanisms)
|
|
{
|
|
if (mechanism.Owner.TryGetComponent(out T? behavior))
|
|
{
|
|
yield return behavior;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static bool TryGetMechanismBehaviors<T>(this IEntity entity, [NotNullWhen(true)] out List<T>? behaviors)
|
|
where T : class, IMechanismBehavior
|
|
{
|
|
behaviors = entity.GetMechanismBehaviors<T>().ToList();
|
|
|
|
if (behaviors.Count == 0)
|
|
{
|
|
behaviors = null;
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|