Don't use ienumerable stuff in body system (#7316)

This commit is contained in:
mirrorcult
2022-03-28 13:52:53 -07:00
committed by GitHub
parent 6405ac6d9b
commit 6060dbca1b
2 changed files with 14 additions and 10 deletions

View File

@@ -47,18 +47,22 @@ namespace Content.Server.Body.Systems
/// <param name="uid">The entity to check for the component on.</param>
/// <param name="body">The body to check for mechanisms on.</param>
/// <typeparam name="T">The component to check for.</typeparam>
public IEnumerable<(T Comp, MechanismComponent Mech)> GetComponentsOnMechanisms<T>(EntityUid uid,
public List<(T Comp, MechanismComponent Mech)> GetComponentsOnMechanisms<T>(EntityUid uid,
SharedBodyComponent? body=null) where T : Component
{
if (!Resolve(uid, ref body))
yield break;
return new();
var query = EntityManager.GetEntityQuery<T>();
var list = new List<(T Comp, MechanismComponent Mech)>(3);
foreach (var (part, _) in body.Parts)
foreach (var mechanism in part.Mechanisms)
{
if (EntityManager.TryGetComponent<T>((mechanism).Owner, out var comp))
yield return (comp, mechanism);
if (query.TryGetComponent(mechanism.Owner, out var comp))
list.Add((comp, mechanism));
}
return list;
}
/// <summary>
@@ -71,7 +75,7 @@ namespace Content.Server.Body.Systems
/// <typeparam name="T">The component to check for.</typeparam>
/// <returns>Whether any were found.</returns>
public bool TryGetComponentsOnMechanisms<T>(EntityUid uid,
[NotNullWhen(true)] out IEnumerable<(T Comp, MechanismComponent Mech)>? comps,
[NotNullWhen(true)] out List<(T Comp, MechanismComponent Mech)>? comps,
SharedBodyComponent? body=null) where T: Component
{
if (!Resolve(uid, ref body))
@@ -80,9 +84,9 @@ namespace Content.Server.Body.Systems
return false;
}
comps = GetComponentsOnMechanisms<T>(uid, body).ToArray();
comps = GetComponentsOnMechanisms<T>(uid, body);
if (!comps.Any())
if (comps.Count == 0)
{
comps = null;
return false;