From ec19f9f4a9bbc6b57625314ab55a555775c29d81 Mon Sep 17 00:00:00 2001 From: Mervill Date: Mon, 29 Jul 2024 00:28:17 -0700 Subject: [PATCH] Make the powered examine text fully client predicted (#30441) * Make the powered examine text fully client predicted * switch to using the Entity API for the examine event --- .../Power/EntitySystems/PowerReceiverSystem.cs | 9 ++++++++- .../Power/EntitySystems/PowerReceiverSystem.cs | 16 +++++----------- .../EntitySystems/SharedPowerReceiverSystem.cs | 13 +++++++++++-- 3 files changed, 24 insertions(+), 14 deletions(-) diff --git a/Content.Client/Power/EntitySystems/PowerReceiverSystem.cs b/Content.Client/Power/EntitySystems/PowerReceiverSystem.cs index 4d56592c23..61e20f751c 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,9 +11,15 @@ public sealed class PowerReceiverSystem : SharedPowerReceiverSystem public override void Initialize() { base.Initialize(); + SubscribeLocalEvent(OnExamined); 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 191d3fc4bd..9b15bdfd28 100644 --- a/Content.Server/Power/EntitySystems/PowerReceiverSystem.cs +++ b/Content.Server/Power/EntitySystems/PowerReceiverSystem.cs @@ -46,6 +46,11 @@ namespace Content.Server.Power.EntitySystems _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)) @@ -61,17 +66,6 @@ namespace Content.Server.Power.EntitySystems }); } - /// - ///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 be2a9dc3ab..37ac751889 100644 --- a/Content.Shared/Power/EntitySystems/SharedPowerReceiverSystem.cs +++ b/Content.Shared/Power/EntitySystems/SharedPowerReceiverSystem.cs @@ -1,6 +1,15 @@ -namespace Content.Shared.Power.EntitySystems; +using Content.Shared.Examine; +using Content.Shared.Power.Components; + +namespace Content.Shared.Power.EntitySystems; public abstract class SharedPowerReceiverSystem : EntitySystem { - + protected string GetExamineText(bool powered) + { + 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"))); + } }