From 5934c6728f7a3ac6c789239d2420f6aec914da18 Mon Sep 17 00:00:00 2001 From: DrSmugleaf Date: Tue, 17 Oct 2023 19:42:47 -0700 Subject: [PATCH] Replace all T : Component constraints with T : IComponent (#21073) --- Content.Client/Antag/AntagStatusIconSystem.cs | 6 +++--- Content.IntegrationTests/PoolManager.cs | 2 +- Content.Server/GameTicking/Rules/GameRuleSystem.cs | 2 +- .../EntitySystems/ParticleAcceleratorSystem.Parts.cs | 8 ++++---- Content.Server/StationEvents/Events/StationEventSystem.cs | 3 +-- Content.Shared/Body/Systems/SharedBodySystem.Organs.cs | 4 ++-- Content.Shared/Body/Systems/SharedBodySystem.Parts.cs | 8 ++++---- Content.Shared/Mind/SharedMindSystem.cs | 8 ++++---- Content.Shared/Roles/SharedRoleSystem.cs | 8 ++++---- Content.Shared/StatusEffect/StatusEffectsSystem.cs | 5 +---- 10 files changed, 25 insertions(+), 29 deletions(-) diff --git a/Content.Client/Antag/AntagStatusIconSystem.cs b/Content.Client/Antag/AntagStatusIconSystem.cs index 3c1c72d03b..bf3955b49a 100644 --- a/Content.Client/Antag/AntagStatusIconSystem.cs +++ b/Content.Client/Antag/AntagStatusIconSystem.cs @@ -1,8 +1,8 @@ +using Content.Shared.Ghost; using Content.Shared.StatusIcon; using Content.Shared.StatusIcon.Components; -using Robust.Shared.Prototypes; -using Content.Shared.Ghost; using Robust.Client.Player; +using Robust.Shared.Prototypes; namespace Content.Client.Antag; @@ -10,7 +10,7 @@ namespace Content.Client.Antag; /// Used for assigning specified icons for antags. /// public abstract class AntagStatusIconSystem : SharedStatusIconSystem - where T : Component + where T : IComponent { [Dependency] private readonly IPrototypeManager _prototype = default!; [Dependency] private readonly IPlayerManager _player = default!; diff --git a/Content.IntegrationTests/PoolManager.cs b/Content.IntegrationTests/PoolManager.cs index 3f8d261e8d..a2015f3fdb 100644 --- a/Content.IntegrationTests/PoolManager.cs +++ b/Content.IntegrationTests/PoolManager.cs @@ -428,7 +428,7 @@ we are just going to end this here to save a lot of time. This is the exception /// /// Helper method that retrieves all entity prototypes that have some component. /// - public static List GetPrototypesWithComponent(RobustIntegrationTest.IntegrationInstance instance) where T : Component + public static List GetPrototypesWithComponent(RobustIntegrationTest.IntegrationInstance instance) where T : IComponent { var protoMan = instance.ResolveDependency(); var compFact = instance.ResolveDependency(); diff --git a/Content.Server/GameTicking/Rules/GameRuleSystem.cs b/Content.Server/GameTicking/Rules/GameRuleSystem.cs index b13f00f363..ba781e32e2 100644 --- a/Content.Server/GameTicking/Rules/GameRuleSystem.cs +++ b/Content.Server/GameTicking/Rules/GameRuleSystem.cs @@ -3,7 +3,7 @@ using Content.Server.GameTicking.Rules.Components; namespace Content.Server.GameTicking.Rules; -public abstract partial class GameRuleSystem : EntitySystem where T : Component +public abstract partial class GameRuleSystem : EntitySystem where T : IComponent { [Dependency] protected readonly IChatManager ChatManager = default!; [Dependency] protected readonly GameTicker GameTicker = default!; diff --git a/Content.Server/ParticleAccelerator/EntitySystems/ParticleAcceleratorSystem.Parts.cs b/Content.Server/ParticleAccelerator/EntitySystems/ParticleAcceleratorSystem.Parts.cs index 860fbdcefe..e76d857810 100644 --- a/Content.Server/ParticleAccelerator/EntitySystems/ParticleAcceleratorSystem.Parts.cs +++ b/Content.Server/ParticleAccelerator/EntitySystems/ParticleAcceleratorSystem.Parts.cs @@ -1,10 +1,10 @@ +using System.Diagnostics.CodeAnalysis; +using System.Numerics; using Content.Server.ParticleAccelerator.Components; using JetBrains.Annotations; using Robust.Server.Player; using Robust.Shared.Map.Components; using Robust.Shared.Physics.Events; -using System.Diagnostics.CodeAnalysis; -using System.Numerics; namespace Content.Server.ParticleAccelerator.EntitySystems; @@ -127,12 +127,12 @@ public sealed partial class ParticleAcceleratorSystem } private bool ScanPart(EntityUid uid, Vector2i coordinates, Angle? rotation, [NotNullWhen(true)] out EntityUid? part, [NotNullWhen(true)] out T? comp, MapGridComponent? grid = null) - where T : Component + where T : IComponent { if (!Resolve(uid, ref grid)) { part = null; - comp = null; + comp = default; return false; } diff --git a/Content.Server/StationEvents/Events/StationEventSystem.cs b/Content.Server/StationEvents/Events/StationEventSystem.cs index 97b96ff7b0..41a7b153f5 100644 --- a/Content.Server/StationEvents/Events/StationEventSystem.cs +++ b/Content.Server/StationEvents/Events/StationEventSystem.cs @@ -1,5 +1,4 @@ using System.Diagnostics.CodeAnalysis; -using System.Linq; using Content.Server.Administration.Logs; using Content.Server.Atmos.EntitySystems; using Content.Server.Chat.Systems; @@ -22,7 +21,7 @@ namespace Content.Server.StationEvents.Events; /// /// An abstract entity system inherited by all station events for their behavior. /// -public abstract partial class StationEventSystem : GameRuleSystem where T : Component +public abstract partial class StationEventSystem : GameRuleSystem where T : IComponent { [Dependency] protected readonly IAdminLogManager AdminLogManager = default!; [Dependency] private readonly IGameTiming _timing = default!; diff --git a/Content.Shared/Body/Systems/SharedBodySystem.Organs.cs b/Content.Shared/Body/Systems/SharedBodySystem.Organs.cs index d2a7b7256a..6e392b9892 100644 --- a/Content.Shared/Body/Systems/SharedBodySystem.Organs.cs +++ b/Content.Shared/Body/Systems/SharedBodySystem.Organs.cs @@ -151,7 +151,7 @@ public partial class SharedBodySystem public List<(T Comp, OrganComponent Organ)> GetBodyOrganComponents( EntityUid uid, BodyComponent? body = null) - where T : Component + where T : IComponent { if (!Resolve(uid, ref body)) return new List<(T Comp, OrganComponent Organ)>(); @@ -180,7 +180,7 @@ public partial class SharedBodySystem EntityUid uid, [NotNullWhen(true)] out List<(T Comp, OrganComponent Organ)>? comps, BodyComponent? body = null) - where T : Component + where T : IComponent { if (!Resolve(uid, ref body)) { diff --git a/Content.Shared/Body/Systems/SharedBodySystem.Parts.cs b/Content.Shared/Body/Systems/SharedBodySystem.Parts.cs index 66397017e1..463a4b7661 100644 --- a/Content.Shared/Body/Systems/SharedBodySystem.Parts.cs +++ b/Content.Shared/Body/Systems/SharedBodySystem.Parts.cs @@ -679,7 +679,7 @@ public partial class SharedBodySystem public List<(T Comp, OrganComponent Organ)> GetBodyPartOrganComponents( EntityUid uid, BodyPartComponent? part = null) - where T : Component + where T : IComponent { if (!Resolve(uid, ref part)) return new List<(T Comp, OrganComponent Organ)>(); @@ -709,7 +709,7 @@ public partial class SharedBodySystem EntityUid uid, [NotNullWhen(true)] out List<(T Comp, OrganComponent Organ)>? comps, BodyPartComponent? part = null) - where T : Component + where T : IComponent { if (!Resolve(uid, ref part)) { @@ -751,7 +751,7 @@ public partial class SharedBodySystem public IEnumerable<(EntityUid AdjacentId, T Component)> GetBodyPartAdjacentPartsComponents( EntityUid partId, BodyPartComponent? part = null) - where T : Component + where T : IComponent { if (!Resolve(partId, ref part, false)) yield break; @@ -768,7 +768,7 @@ public partial class SharedBodySystem EntityUid partId, [NotNullWhen(true)] out List<(EntityUid AdjacentId, T Component)>? comps, BodyPartComponent? part = null) - where T : Component + where T : IComponent { if (!Resolve(partId, ref part, false)) { diff --git a/Content.Shared/Mind/SharedMindSystem.cs b/Content.Shared/Mind/SharedMindSystem.cs index be11d8a2ad..cc4ac4af23 100644 --- a/Content.Shared/Mind/SharedMindSystem.cs +++ b/Content.Shared/Mind/SharedMindSystem.cs @@ -292,7 +292,7 @@ public abstract class SharedMindSystem : EntitySystem return true; } - public bool TryGetObjectiveComp(EntityUid uid, [NotNullWhen(true)] out T? objective) where T : Component + public bool TryGetObjectiveComp(EntityUid uid, [NotNullWhen(true)] out T? objective) where T : IComponent { if (TryGetMind(uid, out var mindId, out var mind) && TryGetObjectiveComp(mindId, out objective, mind)) { @@ -302,7 +302,7 @@ public abstract class SharedMindSystem : EntitySystem return false; } - public bool TryGetObjectiveComp(EntityUid mindId, [NotNullWhen(true)] out T? objective, MindComponent? mind = null) where T : Component + public bool TryGetObjectiveComp(EntityUid mindId, [NotNullWhen(true)] out T? objective, MindComponent? mind = null) where T : IComponent { if (Resolve(mindId, ref mind)) { @@ -382,9 +382,9 @@ public abstract class SharedMindSystem : EntitySystem /// Gets a role component from a player's mind. /// /// Whether a role was found - public bool TryGetRole(EntityUid user, [NotNullWhen(true)] out T? role) where T : Component + public bool TryGetRole(EntityUid user, [NotNullWhen(true)] out T? role) where T : IComponent { - role = null; + role = default; if (!TryComp(user, out var mindContainer) || mindContainer.Mind == null) return false; diff --git a/Content.Shared/Roles/SharedRoleSystem.cs b/Content.Shared/Roles/SharedRoleSystem.cs index 75296b96f4..ebd6730bbe 100644 --- a/Content.Shared/Roles/SharedRoleSystem.cs +++ b/Content.Shared/Roles/SharedRoleSystem.cs @@ -65,7 +65,7 @@ public abstract class SharedRoleSystem : EntitySystem /// /// Thrown if we already have a role with this type. /// - public void MindAddRole(EntityUid mindId, T component, MindComponent? mind = null, bool silent = false) where T : Component, new() + public void MindAddRole(EntityUid mindId, T component, MindComponent? mind = null, bool silent = false) where T : IComponent, new() { if (!Resolve(mindId, ref mind)) return; @@ -99,7 +99,7 @@ public abstract class SharedRoleSystem : EntitySystem /// /// Thrown if we do not have this role. /// - public void MindRemoveRole(EntityUid mindId) where T : Component + public void MindRemoveRole(EntityUid mindId) where T : IComponent { if (!RemComp(mindId)) { @@ -118,7 +118,7 @@ public abstract class SharedRoleSystem : EntitySystem $"'Role {typeof(T).Name}' removed from mind of {_minds.MindOwnerLoggingString(mind)}"); } - public bool MindTryRemoveRole(EntityUid mindId) where T : Component + public bool MindTryRemoveRole(EntityUid mindId) where T : IComponent { if (!MindHasRole(mindId)) return false; @@ -127,7 +127,7 @@ public abstract class SharedRoleSystem : EntitySystem return true; } - public bool MindHasRole(EntityUid mindId) where T : Component + public bool MindHasRole(EntityUid mindId) where T : IComponent { return HasComp(mindId); } diff --git a/Content.Shared/StatusEffect/StatusEffectsSystem.cs b/Content.Shared/StatusEffect/StatusEffectsSystem.cs index bedc5a824c..17b8864493 100644 --- a/Content.Shared/StatusEffect/StatusEffectsSystem.cs +++ b/Content.Shared/StatusEffect/StatusEffectsSystem.cs @@ -1,8 +1,5 @@ using System.Diagnostics.CodeAnalysis; using Content.Shared.Alert; -using Content.Shared.Mobs; -using Content.Shared.Mobs.Components; -using Content.Shared.Mobs.Systems; using Content.Shared.Rejuvenate; using Robust.Shared.GameStates; using Robust.Shared.Prototypes; @@ -107,7 +104,7 @@ namespace Content.Shared.StatusEffect /// The component type to add and remove from the entity. public bool TryAddStatusEffect(EntityUid uid, string key, TimeSpan time, bool refresh, StatusEffectsComponent? status = null) - where T : Component, new() + where T : IComponent, new() { if (!Resolve(uid, ref status, false)) return false;