Skip to content

Commit c2d0490

Browse files
authored
Add EntitySystem.TryComp(EntityUid, Type, out IComponent?) proxy method (space-wizards#6746)
1 parent 960edb3 commit c2d0490

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Robust.Shared/GameObjects/EntitySystem.Proxy.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,14 @@ protected bool TryComp<T>(EntityUid uid, [NotNullWhen(true)] out T? comp) where
495495
return EntityManager.TryGetComponent(uid, out comp);
496496
}
497497

498+
/// <inheritdoc cref="IEntityManager.TryGetComponent(EntityUid?, Type, out IComponent)"/>
499+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
500+
[ProxyFor(typeof(EntityManager), nameof(EntityManager.TryGetComponent))]
501+
protected bool TryComp(EntityUid uid, Type type, [NotNullWhen(true)] out IComponent? comp)
502+
{
503+
return EntityManager.TryGetComponent(uid, type, out comp);
504+
}
505+
498506
/// <inheritdoc cref="IEntityManager.TryGetComponent&lt;T&gt;(EntityUid, out T)"/>
499507
[MethodImpl(MethodImplOptions.AggressiveInlining)]
500508
protected bool TryComp(EntityUid uid, [NotNullWhen(true)] out TransformComponent? comp)
@@ -523,6 +531,20 @@ protected bool TryComp<T>([NotNullWhen(true)] EntityUid? uid, [NotNullWhen(true)
523531
return EntityManager.TryGetComponent(uid.Value, out comp);
524532
}
525533

534+
/// <inheritdoc cref="IEntityManager.TryGetComponent(EntityUid?, Type, out IComponent)"/>
535+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
536+
[ProxyFor(typeof(EntityManager), nameof(EntityManager.TryGetComponent))]
537+
protected bool TryComp([NotNullWhen(true)] EntityUid? uid, Type type, [NotNullWhen(true)] out IComponent? comp)
538+
{
539+
if (!uid.HasValue)
540+
{
541+
comp = null;
542+
return false;
543+
}
544+
545+
return EntityManager.TryGetComponent(uid.Value, type, out comp);
546+
}
547+
526548
/// <inheritdoc cref="IEntityManager.TryGetComponent&lt;T&gt;(EntityUid?, out T)"/>
527549
protected bool TryComp([NotNullWhen(true)] EntityUid? uid, [NotNullWhen(true)] out TransformComponent? comp)
528550
{

0 commit comments

Comments
 (0)