From a9c18acd3523782b9c835cd1b29802cd80762d3f Mon Sep 17 00:00:00 2001 From: ike709 Date: Thu, 12 May 2022 06:11:50 -0500 Subject: [PATCH] Remove misc Startup/Shutdown overrides (#8113) Co-authored-by: ike709 --- Content.Client/Markers/MarkerComponent.cs | 16 ------------- Content.Client/Markers/MarkerSystem.cs | 23 ++++++++++++++++++- .../Components/PointingArrowComponent.cs | 9 -------- .../Components/RoguePointingArrowComponent.cs | 9 -------- Content.Client/Pointing/PointingSystem.cs | 21 +++++++++++++++++ .../Roles/Components/GhostRoleComponent.cs | 16 +------------ Content.Server/Ghost/Roles/GhostRoleSystem.cs | 14 +++++++++++ 7 files changed, 58 insertions(+), 50 deletions(-) diff --git a/Content.Client/Markers/MarkerComponent.cs b/Content.Client/Markers/MarkerComponent.cs index 630ddba7ef..1af9f829c3 100644 --- a/Content.Client/Markers/MarkerComponent.cs +++ b/Content.Client/Markers/MarkerComponent.cs @@ -7,21 +7,5 @@ namespace Content.Client.Markers [RegisterComponent] public sealed class MarkerComponent : Component { - protected override void Startup() - { - base.Startup(); - - UpdateVisibility(); - } - - public void UpdateVisibility() - { - var system = EntitySystem.Get(); - - if (IoCManager.Resolve().TryGetComponent(Owner, out ISpriteComponent? sprite)) - { - sprite.Visible = system.MarkersVisible; - } - } } } diff --git a/Content.Client/Markers/MarkerSystem.cs b/Content.Client/Markers/MarkerSystem.cs index 5355d6bec3..bfaf333baa 100644 --- a/Content.Client/Markers/MarkerSystem.cs +++ b/Content.Client/Markers/MarkerSystem.cs @@ -1,3 +1,4 @@ +using Robust.Client.GameObjects; using Robust.Shared.GameObjects; namespace Content.Client.Markers @@ -16,11 +17,31 @@ namespace Content.Client.Markers } } + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnStartup); + } + + private void OnStartup(EntityUid uid, MarkerComponent marker, ComponentStartup args) + { + UpdateVisibility(marker); + } + + private void UpdateVisibility(MarkerComponent marker) + { + if (EntityManager.TryGetComponent(marker.Owner, out SpriteComponent? sprite)) + { + sprite.Visible = MarkersVisible; + } + } + private void UpdateMarkers() { foreach (var markerComponent in EntityManager.EntityQuery(true)) { - markerComponent.UpdateVisibility(); + UpdateVisibility(markerComponent); } } } diff --git a/Content.Client/Pointing/Components/PointingArrowComponent.cs b/Content.Client/Pointing/Components/PointingArrowComponent.cs index 29f3e671bb..cbc1527482 100644 --- a/Content.Client/Pointing/Components/PointingArrowComponent.cs +++ b/Content.Client/Pointing/Components/PointingArrowComponent.cs @@ -8,14 +8,5 @@ namespace Content.Client.Pointing.Components [ComponentReference(typeof(SharedPointingArrowComponent))] public sealed class PointingArrowComponent : SharedPointingArrowComponent { - protected override void Startup() - { - base.Startup(); - - if (IoCManager.Resolve().TryGetComponent(Owner, out SpriteComponent? sprite)) - { - sprite.DrawDepth = (int) DrawDepth.Overlays; - } - } } } diff --git a/Content.Client/Pointing/Components/RoguePointingArrowComponent.cs b/Content.Client/Pointing/Components/RoguePointingArrowComponent.cs index 6b8a261603..970d020bb5 100644 --- a/Content.Client/Pointing/Components/RoguePointingArrowComponent.cs +++ b/Content.Client/Pointing/Components/RoguePointingArrowComponent.cs @@ -9,14 +9,5 @@ namespace Content.Client.Pointing.Components [RegisterComponent] public sealed class RoguePointingArrowComponent : SharedRoguePointingArrowComponent { - protected override void Startup() - { - base.Startup(); - - if (IoCManager.Resolve().TryGetComponent(Owner, out SpriteComponent? sprite)) - { - sprite.DrawDepth = (int) DrawDepth.Overlays; - } - } } } diff --git a/Content.Client/Pointing/PointingSystem.cs b/Content.Client/Pointing/PointingSystem.cs index 9b1ce47795..8bef309335 100644 --- a/Content.Client/Pointing/PointingSystem.cs +++ b/Content.Client/Pointing/PointingSystem.cs @@ -2,6 +2,8 @@ using Content.Client.Pointing.Components; using Content.Shared.MobState.Components; using Content.Shared.Pointing; using Content.Shared.Verbs; +using Robust.Client.GameObjects; +using DrawDepth = Content.Shared.DrawDepth.DrawDepth; namespace Content.Client.Pointing; @@ -12,6 +14,9 @@ internal sealed class PointingSystem : EntitySystem base.Initialize(); SubscribeLocalEvent>(AddPointingVerb); + SubscribeLocalEvent(OnArrowStartup); + SubscribeLocalEvent(OnRogueArrowStartup); + } private void AddPointingVerb(GetVerbsEvent args) @@ -44,4 +49,20 @@ internal sealed class PointingSystem : EntitySystem args.Verbs.Add(verb); } + + private void OnArrowStartup(EntityUid uid, PointingArrowComponent arrow, ComponentStartup args) + { + if (EntityManager.TryGetComponent(uid, out SpriteComponent? sprite)) + { + sprite.DrawDepth = (int) DrawDepth.Overlays; + } + } + + private void OnRogueArrowStartup(EntityUid uid, RoguePointingArrowComponent arrow, ComponentStartup args) + { + if (EntityManager.TryGetComponent(uid, out SpriteComponent? sprite)) + { + sprite.DrawDepth = (int) DrawDepth.Overlays; + } + } } diff --git a/Content.Server/Ghost/Roles/Components/GhostRoleComponent.cs b/Content.Server/Ghost/Roles/Components/GhostRoleComponent.cs index cdaabd5416..e54e87e783 100644 --- a/Content.Server/Ghost/Roles/Components/GhostRoleComponent.cs +++ b/Content.Server/Ghost/Roles/Components/GhostRoleComponent.cs @@ -7,6 +7,7 @@ using Robust.Shared.Localization; namespace Content.Server.Ghost.Roles.Components { + [Friend(typeof(GhostRoleSystem))] public abstract class GhostRoleComponent : Component { [DataField("name")] public string _roleName = "Unknown"; @@ -69,21 +70,6 @@ namespace Content.Server.Ghost.Roles.Components [DataField("reregister")] public bool ReregisterOnGhost { get; set; } = true; - protected override void Initialize() - { - base.Initialize(); - if (_roleRules == "") - _roleRules = Loc.GetString("ghost-role-component-default-rules"); - EntitySystem.Get().RegisterGhostRole(this); - } - - protected override void Shutdown() - { - base.Shutdown(); - - EntitySystem.Get().UnregisterGhostRole(this); - } - public abstract bool Take(IPlayerSession session); } } diff --git a/Content.Server/Ghost/Roles/GhostRoleSystem.cs b/Content.Server/Ghost/Roles/GhostRoleSystem.cs index fd0bc98f86..dba521430c 100644 --- a/Content.Server/Ghost/Roles/GhostRoleSystem.cs +++ b/Content.Server/Ghost/Roles/GhostRoleSystem.cs @@ -53,6 +53,8 @@ namespace Content.Server.Ghost.Roles SubscribeLocalEvent(OnMindAdded); SubscribeLocalEvent(OnMindRemoved); SubscribeLocalEvent(OnMobStateChanged); + SubscribeLocalEvent(OnInit); + SubscribeLocalEvent(OnShutdown); _playerManager.PlayerStatusChanged += PlayerStatusChanged; } @@ -266,6 +268,18 @@ namespace Content.Server.Ghost.Roles _ghostRoles.Clear(); _nextRoleIdentifier = 0; } + + private void OnInit(EntityUid uid, GhostRoleComponent role, ComponentInit args) + { + if (role.RoleRules == "") + role.RoleRules = Loc.GetString("ghost-role-component-default-rules"); + RegisterGhostRole(role); + } + + private void OnShutdown(EntityUid uid, GhostRoleComponent role, ComponentShutdown args) + { + UnregisterGhostRole(role); + } } [AnyCommand]