using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; namespace Content.Shared._Horizon; public sealed class StarlightEntitySystem : EntitySystem { [Robust.Shared.IoC.Dependency] private readonly ILogManager _logManager = null!; private ISawmill _sawmill = null!; public override void Initialize() { base.Initialize(); _sawmill = _logManager.GetSawmill("StarlightEntitySystem"); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEntity(EntityUid uid, [NotNullWhen(true)] out Entity? entity, bool log = true) where T : class, IComponent { entity = null; if (!uid.IsValid() || !TryComp(uid, out MetaDataComponent? metadata)) { _sawmill.Error("Entity {EntityUid} invalid", uid); return false; } if (!TryComp(uid, out var comp1)) { if (log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T)); return false; } entity = (uid, comp1); return true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEntity(EntityUid uid, [NotNullWhen(true)] out Entity? entity, bool log = true) where T1 : class, IComponent where T2 : class, IComponent { entity = null; if (!uid.IsValid() || !TryComp(uid, out MetaDataComponent? metadata)) { _sawmill.Error($"Entity {uid} invalid"); return false; } if (!TryComp(uid, out var comp1)) { if (log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T1)); return false; } if (!TryComp(uid, out var comp2)) { if (log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T2)); return false; } entity = (uid, comp1, comp2); return true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEntity(EntityUid uid, [NotNullWhen(true)] out Entity? entity, bool log = true) where T1 : class, IComponent where T2 : class, IComponent where T3 : class, IComponent { entity = null; if (!uid.IsValid() || !TryComp(uid, out MetaDataComponent? metadata)) { _sawmill.Error($"Entity {uid} invalid"); return false; } if (!TryComp(uid, out var comp1)) { if (log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T1)); return false; } if (!TryComp(uid, out var comp2)) { if (log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T2)); return false; } if (!TryComp(uid, out var comp3)) { if (log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T3)); return false; } entity = (uid, comp1, comp2, comp3); return true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEntity(EntityUid uid, [NotNullWhen(true)] out Entity? entity, bool log = true) where T1 : class, IComponent where T2 : class, IComponent where T3 : class, IComponent where T4 : class, IComponent { entity = null; if (!uid.IsValid() || !TryComp(uid, out MetaDataComponent? metadata)) { _sawmill.Error($"Entity {uid} invalid"); return false; } if (!TryComp(uid, out var comp1)) { if (log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T1)); return false; } if (!TryComp(uid, out var comp2)) { if (log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T2)); return false; } if (!TryComp(uid, out var comp3)) { if (log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T3)); return false; } if (!TryComp(uid, out var comp4)) { if (log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T4)); return false; } entity = (uid, comp1, comp2, comp3, comp4); return true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEntity(EntityUid uid, [NotNullWhen(true)] out Entity? entity, bool log = true) where T1 : class, IComponent where T2 : class, IComponent where T3 : class, IComponent where T4 : class, IComponent where T5 : class, IComponent { entity = null; if (!uid.IsValid() || !TryComp(uid, out MetaDataComponent? metadata)) { _sawmill.Error($"Entity {uid} invalid"); return false; } if (!TryComp(uid, out var comp1)) { if (log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T1)); return false; } if (!TryComp(uid, out var comp2)) { if (log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T2)); return false; } if (!TryComp(uid, out var comp3)) { if (log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T3)); return false; } if (!TryComp(uid, out var comp4)) { if (log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T4)); return false; } if (!TryComp(uid, out var comp5)) { if (log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T5)); return false; } entity = (uid, comp1, comp2, comp3, comp4, comp5); return true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool TryEntity(EntityUid uid, [NotNullWhen(true)] out Entity? entity, bool log = true) where T1 : class, IComponent where T2 : class, IComponent where T3 : class, IComponent where T4 : class, IComponent where T5 : class, IComponent where T6 : class, IComponent { entity = null; if (!uid.IsValid() || !TryComp(uid, out MetaDataComponent? metadata)) { _sawmill.Error($"Entity {uid} invalid"); return false; } if (!TryComp(uid, out var comp1)) { if (log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T1)); return false; } if (!TryComp(uid, out var comp2)) { if (log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T2)); return false; } if (!TryComp(uid, out var comp3)) { if (log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T3)); return false; } if (!TryComp(uid, out var comp4)) { if (log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T4)); return false; } if (!TryComp(uid, out var comp5)) { if (log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T5)); return false; } if (!TryComp(uid, out var comp6)) { if (log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T6)); return false; } entity = (uid, comp1, comp2, comp3, comp4, comp5, comp6); return true; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Entity Entity(EntityUid uid, bool log = true) where T : class, IComponent { if (!uid.IsValid() || !TryComp(uid, out MetaDataComponent? metadata)) { _sawmill.Error("Entity {EntityUid} invalid", uid); return uid; } if (!TryComp(uid, out var comp1) && log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T)); return (uid, comp1); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Entity Entity(EntityUid uid, bool log = true) where T1 : class, IComponent where T2 : class, IComponent { if (!uid.IsValid() || !TryComp(uid, out MetaDataComponent? metadata)) { _sawmill.Error("Entity {EntityUid} invalid", uid); return uid; } if (!TryComp(uid, out var comp1) && log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T1)); if (!TryComp(uid, out var comp2) && log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T2)); return (uid, comp1, comp2); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Entity Entity(EntityUid uid, bool log = true) where T1 : class, IComponent where T2 : class, IComponent where T3 : class, IComponent { if (!uid.IsValid() || !TryComp(uid, out MetaDataComponent? metadata)) { _sawmill.Error("Entity {EntityUid} invalid", uid); return uid; } if (!TryComp(uid, out var comp1) && log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T1)); if (!TryComp(uid, out var comp2) && log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T2)); if (!TryComp(uid, out var comp3) && log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T3)); return (uid, comp1, comp2, comp3); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Entity Entity(EntityUid uid, bool log = true) where T1 : class, IComponent where T2 : class, IComponent where T3 : class, IComponent where T4 : class, IComponent { if (!uid.IsValid() || !TryComp(uid, out MetaDataComponent? metadata)) { _sawmill.Error("Entity {EntityUid} invalid", uid); return uid; } if (!TryComp(uid, out var comp1) && log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T1)); if (!TryComp(uid, out var comp2) && log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T2)); if (!TryComp(uid, out var comp3) && log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T3)); if (!TryComp(uid, out var comp4) && log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T4)); return (uid, comp1, comp2, comp3, comp4); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Entity Entity(EntityUid uid, bool log = true) where T1 : class, IComponent where T2 : class, IComponent where T3 : class, IComponent where T4 : class, IComponent where T5 : class, IComponent { if (!uid.IsValid() || !TryComp(uid, out MetaDataComponent? metadata)) { _sawmill.Error("Entity {EntityUid} invalid", uid); return uid; } if (!TryComp(uid, out var comp1) && log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T1)); if (!TryComp(uid, out var comp2) && log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T2)); if (!TryComp(uid, out var comp3) && log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T3)); if (!TryComp(uid, out var comp4) && log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T4)); if (!TryComp(uid, out var comp5) && log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T5)); return (uid, comp1, comp2, comp3, comp4, comp5); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public Entity Entity(EntityUid uid, bool log = true) where T1 : class, IComponent where T2 : class, IComponent where T3 : class, IComponent where T4 : class, IComponent where T5 : class, IComponent where T6 : class, IComponent { if (!uid.IsValid() || !TryComp(uid, out MetaDataComponent? metadata)) { _sawmill.Error("Entity {EntityUid} invalid", uid); return uid; } if (!TryComp(uid, out var comp1) && log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T1)); if (!TryComp(uid, out var comp2) && log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T2)); if (!TryComp(uid, out var comp3) && log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T3)); if (!TryComp(uid, out var comp4) && log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T4)); if (!TryComp(uid, out var comp5) && log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T5)); if (!TryComp(uid, out var comp6) && log) _sawmill.Error("Entity {EntityName}[{EntityPrototype}]:{EntityUid} does not have component {type}", metadata.EntityName, metadata.EntityPrototype, uid, typeof(T6)); return (uid, comp1, comp2, comp3, comp4, comp5, comp6); } }