From 29142b555dd8ac91548148c85e050ad1ea7ef2db Mon Sep 17 00:00:00 2001 From: Mervill Date: Sun, 28 Jul 2024 22:32:04 -0700 Subject: [PATCH 1/2] Make the powered examine text fully client predicted --- .../Power/EntitySystems/PowerReceiverSystem.cs | 4 +++- .../Power/EntitySystems/PowerReceiverSystem.cs | 11 ----------- .../EntitySystems/SharedPowerReceiverSystem.cs | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Content.Client/Power/EntitySystems/PowerReceiverSystem.cs b/Content.Client/Power/EntitySystems/PowerReceiverSystem.cs index 4d56592c2322..f11820fead02 100644 --- a/Content.Client/Power/EntitySystems/PowerReceiverSystem.cs +++ b/Content.Client/Power/EntitySystems/PowerReceiverSystem.cs @@ -1,6 +1,7 @@ -using Content.Client.Power.Components; +using Content.Client.Power.Components; using Content.Shared.Power.Components; using Content.Shared.Power.EntitySystems; +using Content.Shared.Examine; using Robust.Shared.GameStates; namespace Content.Client.Power.EntitySystems; @@ -10,6 +11,7 @@ public sealed class PowerReceiverSystem : SharedPowerReceiverSystem public override void Initialize() { base.Initialize(); + SubscribeLocalEvent(OnExamined); SubscribeLocalEvent(OnHandleState); } diff --git a/Content.Server/Power/EntitySystems/PowerReceiverSystem.cs b/Content.Server/Power/EntitySystems/PowerReceiverSystem.cs index 191d3fc4bdb9..8a92efef35f4 100644 --- a/Content.Server/Power/EntitySystems/PowerReceiverSystem.cs +++ b/Content.Server/Power/EntitySystems/PowerReceiverSystem.cs @@ -61,17 +61,6 @@ private void OnGetVerbs(EntityUid uid, ApcPowerReceiverComponent component, GetV }); } - /// - ///Adds some markup to the examine text of whatever object is using this component to tell you if it's powered or not, even if it doesn't have an icon state to do this for you. - /// - private void OnExamined(EntityUid uid, ApcPowerReceiverComponent component, ExaminedEvent args) - { - args.PushMarkup(Loc.GetString("power-receiver-component-on-examine-main", - ("stateText", Loc.GetString( component.Powered - ? "power-receiver-component-on-examine-powered" - : "power-receiver-component-on-examine-unpowered")))); - } - private void OnProviderShutdown(EntityUid uid, ApcPowerProviderComponent component, ComponentShutdown args) { foreach (var receiver in component.LinkedReceivers) diff --git a/Content.Shared/Power/EntitySystems/SharedPowerReceiverSystem.cs b/Content.Shared/Power/EntitySystems/SharedPowerReceiverSystem.cs index be2a9dc3abc6..f63fd5909e25 100644 --- a/Content.Shared/Power/EntitySystems/SharedPowerReceiverSystem.cs +++ b/Content.Shared/Power/EntitySystems/SharedPowerReceiverSystem.cs @@ -1,6 +1,18 @@ -namespace Content.Shared.Power.EntitySystems; +using Content.Shared.Examine; +using Content.Shared.Power.Components; + +namespace Content.Shared.Power.EntitySystems; public abstract class SharedPowerReceiverSystem : EntitySystem { - + /// + ///Adds some markup to the examine text of whatever object is using this component to tell you if it's powered or not, even if it doesn't have an icon state to do this for you. + /// + protected void OnExamined(EntityUid uid, SharedApcPowerReceiverComponent component, ExaminedEvent args) + { + args.PushMarkup(Loc.GetString("power-receiver-component-on-examine-main", + ("stateText", Loc.GetString(component.Powered + ? "power-receiver-component-on-examine-powered" + : "power-receiver-component-on-examine-unpowered")))); + } } From 74c95b117f0ee988250a01c9a696bf1e92929d17 Mon Sep 17 00:00:00 2001 From: Mervill Date: Mon, 29 Jul 2024 00:06:23 -0700 Subject: [PATCH 2/2] switch to using the Entity API for the examine event --- .../Power/EntitySystems/PowerReceiverSystem.cs | 5 +++++ .../Power/EntitySystems/PowerReceiverSystem.cs | 5 +++++ .../EntitySystems/SharedPowerReceiverSystem.cs | 13 +++++-------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Content.Client/Power/EntitySystems/PowerReceiverSystem.cs b/Content.Client/Power/EntitySystems/PowerReceiverSystem.cs index f11820fead02..61e20f751caf 100644 --- a/Content.Client/Power/EntitySystems/PowerReceiverSystem.cs +++ b/Content.Client/Power/EntitySystems/PowerReceiverSystem.cs @@ -15,6 +15,11 @@ public override void Initialize() SubscribeLocalEvent(OnHandleState); } + private void OnExamined(Entity ent, ref ExaminedEvent args) + { + args.PushMarkup(GetExamineText(ent.Comp.Powered)); + } + private void OnHandleState(EntityUid uid, ApcPowerReceiverComponent component, ref ComponentHandleState args) { if (args.Current is not ApcPowerReceiverComponentState state) diff --git a/Content.Server/Power/EntitySystems/PowerReceiverSystem.cs b/Content.Server/Power/EntitySystems/PowerReceiverSystem.cs index 8a92efef35f4..9b15bdfd287a 100644 --- a/Content.Server/Power/EntitySystems/PowerReceiverSystem.cs +++ b/Content.Server/Power/EntitySystems/PowerReceiverSystem.cs @@ -46,6 +46,11 @@ public override void Initialize() _provQuery = GetEntityQuery(); } + private void OnExamined(Entity ent, ref ExaminedEvent args) + { + args.PushMarkup(GetExamineText(ent.Comp.Powered)); + } + private void OnGetVerbs(EntityUid uid, ApcPowerReceiverComponent component, GetVerbsEvent args) { if (!_adminManager.HasAdminFlag(args.User, AdminFlags.Admin)) diff --git a/Content.Shared/Power/EntitySystems/SharedPowerReceiverSystem.cs b/Content.Shared/Power/EntitySystems/SharedPowerReceiverSystem.cs index f63fd5909e25..37ac75188968 100644 --- a/Content.Shared/Power/EntitySystems/SharedPowerReceiverSystem.cs +++ b/Content.Shared/Power/EntitySystems/SharedPowerReceiverSystem.cs @@ -5,14 +5,11 @@ namespace Content.Shared.Power.EntitySystems; public abstract class SharedPowerReceiverSystem : EntitySystem { - /// - ///Adds some markup to the examine text of whatever object is using this component to tell you if it's powered or not, even if it doesn't have an icon state to do this for you. - /// - protected void OnExamined(EntityUid uid, SharedApcPowerReceiverComponent component, ExaminedEvent args) + protected string GetExamineText(bool powered) { - args.PushMarkup(Loc.GetString("power-receiver-component-on-examine-main", - ("stateText", Loc.GetString(component.Powered - ? "power-receiver-component-on-examine-powered" - : "power-receiver-component-on-examine-unpowered")))); + return Loc.GetString("power-receiver-component-on-examine-main", + ("stateText", Loc.GetString(powered + ? "power-receiver-component-on-examine-powered" + : "power-receiver-component-on-examine-unpowered"))); } }