Skip to content

Commit

Permalink
Make the powered examine text fully client predicted (space-wizards#3…
Browse files Browse the repository at this point in the history
…0441)

* Make the powered examine text fully client predicted

* switch to using the Entity<T> API for the examine event
  • Loading branch information
Mervill authored Jul 29, 2024
1 parent c586561 commit ec19f9f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
9 changes: 8 additions & 1 deletion Content.Client/Power/EntitySystems/PowerReceiverSystem.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,9 +11,15 @@ public sealed class PowerReceiverSystem : SharedPowerReceiverSystem
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ApcPowerReceiverComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<ApcPowerReceiverComponent, ComponentHandleState>(OnHandleState);
}

private void OnExamined(Entity<ApcPowerReceiverComponent> 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)
Expand Down
16 changes: 5 additions & 11 deletions Content.Server/Power/EntitySystems/PowerReceiverSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public override void Initialize()
_provQuery = GetEntityQuery<ApcPowerProviderComponent>();
}

private void OnExamined(Entity<ApcPowerReceiverComponent> ent, ref ExaminedEvent args)
{
args.PushMarkup(GetExamineText(ent.Comp.Powered));
}

private void OnGetVerbs(EntityUid uid, ApcPowerReceiverComponent component, GetVerbsEvent<Verb> args)
{
if (!_adminManager.HasAdminFlag(args.User, AdminFlags.Admin))
Expand All @@ -61,17 +66,6 @@ private void OnGetVerbs(EntityUid uid, ApcPowerReceiverComponent component, GetV
});
}

///<summary>
///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.
///</summary>
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)
Expand Down
13 changes: 11 additions & 2 deletions Content.Shared/Power/EntitySystems/SharedPowerReceiverSystem.cs
Original file line number Diff line number Diff line change
@@ -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")));
}
}

0 comments on commit ec19f9f

Please sign in to comment.