Handle IPC charge icons client-side (#5535)

* Handle IPC charge icons client-side

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Yeag

* Yeag²

* Yeag³

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Tobias Berger 2026-03-21 19:37:36 +00:00 committed by GitHub
parent 00f3dd128d
commit 5a7bc69311
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 110 additions and 34 deletions

View File

@ -0,0 +1,31 @@
using Content.Client.Alerts;
using Content.Shared._EE.Silicon.Components;
using Content.Shared._EE.Silicon.Systems;
namespace Content.Client._DV.Silicon.Charge;
public sealed class SiliconChargeSystem : SharedSiliconChargeSystem
{
[Dependency] private readonly ClientAlertsSystem _alerts = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SiliconComponent, ComponentInit>(OnSiliconInit);
SubscribeLocalEvent<SiliconComponent, SiliconChargeStateUpdateEvent>(OnSiliconChargeStateUpdate);
}
private void OnSiliconInit(EntityUid uid, SiliconComponent component, ComponentInit args)
{
if (!component.BatteryPowered)
return;
_alerts.ShowAlert(uid, component.BatteryAlert, component.ChargeState);
}
private void OnSiliconChargeStateUpdate(EntityUid uid, SiliconComponent component, SiliconChargeStateUpdateEvent ev)
{
_alerts.ShowAlert(uid, component.BatteryAlert, ev.ChargePercent);
}
}

View File

@ -0,0 +1,29 @@
using Content.Client.Alerts;
using Content.Shared._EE.Silicon.Components;
using Content.Shared._DV.Silicons.Charge;
namespace Content.Client._DV.Silicon.Charge;
public sealed class SiliconDrainSystem : SharedSiliconDrainSystem
{
[Dependency] private readonly ClientAlertsSystem _alerts = default!;
protected override void UpdateChargeIcon(Entity<SiliconComponent> ent, short chargePercent)
{
// If you can't find a battery, set the indicator and skip it.
if (!TryGetSiliconBattery(ent, out _))
{
if (_alerts.IsShowingAlert(ent.Owner, ent.Comp.BatteryAlert))
{
_alerts.ClearAlert(ent.Owner, ent.Comp.BatteryAlert);
_alerts.ShowAlert(ent.Owner, ent.Comp.NoBatteryAlert);
}
}
// If the battery was replaced and the no battery indicator is showing, replace the indicator
else if (_alerts.IsShowingAlert(ent.Owner, ent.Comp.NoBatteryAlert))
{
_alerts.ClearAlert(ent.Owner, ent.Comp.NoBatteryAlert);
_alerts.ShowAlert(ent.Owner, ent.Comp.BatteryAlert, chargePercent);
}
}
}

View File

@ -0,0 +1,5 @@
using Content.Shared._EE.Silicon.Systems;
namespace Content.Server._DV.Silicon.Charge;
public sealed class SiliconChargeSystem : SharedSiliconChargeSystem;

View File

@ -0,0 +1,12 @@
using Content.Shared._DV.Silicons.Charge;
using Content.Shared._EE.Silicon.Components;
namespace Content.Server._DV.Silicons.Charge;
public sealed class SiliconDrainSystem : SharedSiliconDrainSystem
{
protected override void UpdateChargeIcon(Entity<SiliconComponent> ent, short chargePercent)
{
// No-op on Server
}
}

View File

@ -1,7 +1,7 @@
using Content.Server.Chat.Systems;
using Content.Server.Lightning;
using Content.Server.Popups;
using Content.Shared._DV.Silicons.Charge.Systems; // DeltaV - Moved IPC charge to shared
using Content.Server._DV.Silicons.Charge; // DeltaV - Moved IPC charge to shared and split into server/client
using Content.Shared._EE.Silicon.DeadStartupButton;
using Content.Shared.Audio;
using Content.Shared.Damage;
@ -26,7 +26,7 @@ public sealed class DeadStartupButtonSystem : SharedDeadStartupButtonSystem
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly IRobustRandom _robustRandom = default!;
[Dependency] private readonly LightningSystem _lightning = default!;
[Dependency] private readonly SiliconChargeSystem _siliconChargeSystem = default!;
[Dependency] private readonly SiliconDrainSystem _siliconChargeSystem = default!; // DeltaV - Renamed type from "Charge" to "Drain" to disambiguate
[Dependency] private readonly PowerCellSystem _powerCell = default!;
[Dependency] private readonly SharedBatterySystem _battery = default!;

View File

@ -1,7 +1,7 @@
using Content.Shared.Power.Components;
using Content.Shared._EE.Silicon.Systems;
using Content.Shared.Bed.Sleep;
using Content.Shared._DV.Silicons.Charge.Systems; // DeltaV - Moved IPC charge to shared
using Content.Server._DV.Silicons.Charge; // DeltaV - Moved IPC charge to shared and split into server/client
using Content.Server.Humanoid;
using Content.Shared.Humanoid;
@ -10,7 +10,7 @@ namespace Content.Server._EE.Silicon.Death;
public sealed class SiliconDeathSystem : EntitySystem
{
[Dependency] private readonly SleepingSystem _sleep = default!;
[Dependency] private readonly SiliconChargeSystem _silicon = default!;
[Dependency] private readonly SiliconDrainSystem _silicon = default!; // DeltaV - Renamed type from "Charge" to "Drain" to disambiguate
[Dependency] private readonly HumanoidAppearanceSystem _humanoidAppearanceSystem = default!;
public override void Initialize()

View File

@ -20,16 +20,15 @@ using Content.Shared.Movement.Components;
using Robust.Shared.Physics.Components;
// End TheDen
namespace Content.Shared._DV.Silicons.Charge.Systems;
namespace Content.Shared._DV.Silicons.Charge;
public sealed class SiliconChargeSystem : EntitySystem
public abstract class SharedSiliconDrainSystem : EntitySystem
{
[Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] private readonly MovementSpeedModifierSystem _moveMod = default!;
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IConfigurationManager _config = default!;
[Dependency] private readonly PowerCellSystem _powerCell = default!;
[Dependency] private readonly AlertsSystem _alerts = default!;
[Dependency] private readonly SharedJetpackSystem _jetpack = default!; // TheDen - IPC Dynamic Power draw
[Dependency] private readonly SharedBatterySystem _battery = default!;
public override void Initialize()
@ -96,11 +95,6 @@ public sealed class SiliconChargeSystem : EntitySystem
if (!TryGetSiliconBattery(silicon, out var batteryComp))
{
UpdateChargeState(silicon, 0, siliconComp);
if (_alerts.IsShowingAlert(silicon, siliconComp.BatteryAlert))
{
_alerts.ClearAlert(silicon, siliconComp.BatteryAlert);
_alerts.ShowAlert(silicon, siliconComp.NoBatteryAlert);
}
continue;
}
@ -135,12 +129,19 @@ public sealed class SiliconChargeSystem : EntitySystem
_powerCell.TryUseCharge(silicon, frameTime * drainRate);
// Figure out the current state of the Silicon.
var chargePercent = (short) MathF.Round(_battery.GetCharge(batteryComp.Value.AsNullable()) / batteryComp.Value.Comp.MaxCharge * 10f);
var chargePercent = (short)MathF.Round(_battery.GetCharge(batteryComp.Value.AsNullable()) / batteryComp.Value.Comp.MaxCharge * 10f);
UpdateChargeState(silicon, chargePercent, siliconComp);
}
}
/// <summary>
///Makes sure the entity is showing the right charge alert
/// </summary>
/// <param name="ent">The silicon whose charge to check</param>
/// <param name="chargePercent">Charge level, normalized to range 0-100</param>
protected abstract void UpdateChargeIcon(Entity<SiliconComponent> ent, short chargePercent);
/// <summary>
/// Checks if anything needs to be updated, and updates it.
/// </summary>
@ -151,13 +152,7 @@ public sealed class SiliconChargeSystem : EntitySystem
RaiseLocalEvent(uid, new SiliconChargeStateUpdateEvent(chargePercent));
_moveMod.RefreshMovementSpeedModifiers(uid);
// If the battery was replaced and the no battery indicator is showing, replace the indicator
if (_alerts.IsShowingAlert(uid, component.NoBatteryAlert) && chargePercent != 0)
{
_alerts.ClearAlert(uid, component.NoBatteryAlert);
_alerts.ShowAlert(uid, component.BatteryAlert, chargePercent);
}
UpdateChargeIcon((uid, component), chargePercent);
}
// TheDen - IPC Dynamic Power draw

View File

@ -9,17 +9,19 @@ using Content.Shared.PowerCell.Components;
namespace Content.Shared._EE.Silicon.Systems;
public sealed class SharedSiliconChargeSystem : EntitySystem
public abstract class SharedSiliconChargeSystem : EntitySystem // DeltaV - Make class abstract to split into Client/Server
{
[Dependency] private readonly AlertsSystem _alertsSystem = default!;
// [Dependency] private readonly AlertsSystem _alertsSystem = default!; // DeltaV - Moved alert handling to Client
[Dependency] private readonly ItemSlotsSystem _itemSlots = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SiliconComponent, ComponentInit>(OnSiliconInit);
SubscribeLocalEvent<SiliconComponent, SiliconChargeStateUpdateEvent>(OnSiliconChargeStateUpdate);
// Begin DeltaV - Moved alert handling to Client
// SubscribeLocalEvent<SiliconComponent, ComponentInit>(OnSiliconInit);
// SubscribeLocalEvent<SiliconComponent, SiliconChargeStateUpdateEvent>(OnSiliconChargeStateUpdate);
// End DeltaV - Moved alert handling to Client
SubscribeLocalEvent<SiliconComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovespeed);
SubscribeLocalEvent<SiliconComponent, ItemSlotInsertAttemptEvent>(OnItemSlotInsertAttempt);
SubscribeLocalEvent<SiliconComponent, ItemSlotEjectAttemptEvent>(OnItemSlotEjectAttempt);
@ -48,18 +50,20 @@ public sealed class SharedSiliconChargeSystem : EntitySystem
args.Cancelled = true;
}
private void OnSiliconInit(EntityUid uid, SiliconComponent component, ComponentInit args)
{
if (!component.BatteryPowered)
return;
// Begin DeltaV - Moved alert handling to Client
// private void OnSiliconInit(EntityUid uid, SiliconComponent component, ComponentInit args)
// {
// if (!component.BatteryPowered)
// return;
_alertsSystem.ShowAlert(uid, component.BatteryAlert, component.ChargeState);
}
// _alertsSystem.ShowAlert(uid, component.BatteryAlert, component.ChargeState);
// }
private void OnSiliconChargeStateUpdate(EntityUid uid, SiliconComponent component, SiliconChargeStateUpdateEvent ev)
{
_alertsSystem.ShowAlert(uid, component.BatteryAlert, ev.ChargePercent);
}
// private void OnSiliconChargeStateUpdate(EntityUid uid, SiliconComponent component, SiliconChargeStateUpdateEvent ev)
// {
// _alertsSystem.ShowAlert(uid, component.BatteryAlert, ev.ChargePercent);
// }
// End DeltaV - Moved alert handling to Client
private void OnRefreshMovespeed(EntityUid uid, SiliconComponent component, RefreshMovementSpeedModifiersEvent args)
{