Remove all obsolete BatteryComponent method calls (#25871)

Removed all obsolete, non-ECS method calls to BatteryComponent
This commit is contained in:
Tayrtahn
2024-03-06 00:34:50 -05:00
committed by GitHub
parent 4228305b12
commit 2935e5bd78
12 changed files with 44 additions and 57 deletions

View File

@@ -151,7 +151,7 @@ public sealed class EmergencyLightSystem : SharedEmergencyLightSystem
}
else
{
battery.CurrentCharge += component.ChargingWattage * frameTime * component.ChargingEfficiency;
_battery.SetCharge(uid, battery.CurrentCharge + component.ChargingWattage * frameTime * component.ChargingEfficiency, battery);
if (battery.IsFullyCharged)
{
if (TryComp<ApcPowerReceiverComponent>(uid, out var receiver))

View File

@@ -1,5 +1,6 @@
using Content.Server.Actions;
using Content.Server.Popups;
using Content.Server.Power.EntitySystems;
using Content.Server.PowerCell;
using Content.Shared.Actions;
using Content.Shared.Examine;
@@ -25,6 +26,7 @@ namespace Content.Server.Light.EntitySystems
[Dependency] private readonly ActionContainerSystem _actionContainer = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly PowerCellSystem _powerCell = default!;
[Dependency] private readonly BatterySystem _battery = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedPointLightSystem _lights = default!;
@@ -268,7 +270,7 @@ namespace Content.Server.Light.EntitySystems
_appearance.SetData(uid, HandheldLightVisuals.Power, HandheldLightPowerStates.Dying, appearanceComponent);
}
if (component.Activated && !battery.TryUseCharge(component.Wattage * frameTime))
if (component.Activated && !_battery.TryUseCharge(uid, component.Wattage * frameTime, battery))
TurnOff(uid, false);
UpdateLevel(uid);

View File

@@ -7,56 +7,34 @@ namespace Content.Server.Power.Components
/// </summary>
[RegisterComponent]
[Virtual]
[Access(typeof(BatterySystem))]
public partial class BatteryComponent : Component
{
[Dependency] private readonly IEntityManager _entMan = default!;
public string SolutionName = "battery";
/// <summary>
/// Maximum charge of the battery in joules (ie. watt seconds)
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public float MaxCharge
{
get => _maxCharge;
[Obsolete("Use system method")]
set => _entMan.System<BatterySystem>().SetMaxCharge(Owner, value, this);
}
[DataField("maxCharge")]
[Access(typeof(BatterySystem))]
public float _maxCharge;
[DataField]
public float MaxCharge;
/// <summary>
/// Current charge of the battery in joules (ie. watt seconds)
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public float CurrentCharge
{
get => Charge;
[Obsolete("Use system method")]
set => _entMan.System<BatterySystem>().SetCharge(Owner, value, this);
}
[DataField("startingCharge")]
[Access(typeof(BatterySystem))]
public float Charge;
public float CurrentCharge;
/// <summary>
/// True if the battery is fully charged.
/// </summary>
[ViewVariables] public bool IsFullyCharged => MathHelper.CloseToPercent(CurrentCharge, MaxCharge);
[ViewVariables]
public bool IsFullyCharged => MathHelper.CloseToPercent(CurrentCharge, MaxCharge);
/// <summary>
/// The price per one joule. Default is 1 credit for 10kJ.
/// </summary>
[DataField("pricePerJoule")]
[ViewVariables(VVAccess.ReadWrite)]
[DataField]
public float PricePerJoule = 0.0001f;
[Obsolete("Use system method")]
public bool TryUseCharge(float value)
=> _entMan.System<BatterySystem>().TryUseCharge(Owner, value, this);
}
/// <summary>

View File

@@ -62,9 +62,9 @@ namespace Content.Server.Power.EntitySystems
var enumerator = AllEntityQuery<PowerNetworkBatteryComponent, BatteryComponent>();
while (enumerator.MoveNext(out var netBat, out var bat))
{
DebugTools.Assert(bat.Charge <= bat.MaxCharge && bat.Charge >= 0);
DebugTools.Assert(bat.CurrentCharge <= bat.MaxCharge && bat.CurrentCharge >= 0);
netBat.NetworkBattery.Capacity = bat.MaxCharge;
netBat.NetworkBattery.CurrentStorage = bat.Charge;
netBat.NetworkBattery.CurrentStorage = bat.CurrentCharge;
}
}
@@ -108,10 +108,10 @@ namespace Content.Server.Power.EntitySystems
if (value <= 0 || !Resolve(uid, ref battery) || battery.CurrentCharge == 0)
return 0;
var newValue = Math.Clamp(0, battery.CurrentCharge - value, battery._maxCharge);
var delta = newValue - battery.Charge;
battery.Charge = newValue;
var ev = new ChargeChangedEvent(battery.CurrentCharge, battery._maxCharge);
var newValue = Math.Clamp(0, battery.CurrentCharge - value, battery.MaxCharge);
var delta = newValue - battery.CurrentCharge;
battery.CurrentCharge = newValue;
var ev = new ChargeChangedEvent(battery.CurrentCharge, battery.MaxCharge);
RaiseLocalEvent(uid, ref ev);
return delta;
}
@@ -121,13 +121,13 @@ namespace Content.Server.Power.EntitySystems
if (!Resolve(uid, ref battery))
return;
var old = battery._maxCharge;
battery._maxCharge = Math.Max(value, 0);
battery.Charge = Math.Min(battery.Charge, battery._maxCharge);
if (MathHelper.CloseTo(battery._maxCharge, old))
var old = battery.MaxCharge;
battery.MaxCharge = Math.Max(value, 0);
battery.CurrentCharge = Math.Min(battery.CurrentCharge, battery.MaxCharge);
if (MathHelper.CloseTo(battery.MaxCharge, old))
return;
var ev = new ChargeChangedEvent(battery.CurrentCharge, battery._maxCharge);
var ev = new ChargeChangedEvent(battery.CurrentCharge, battery.MaxCharge);
RaiseLocalEvent(uid, ref ev);
}
@@ -136,12 +136,12 @@ namespace Content.Server.Power.EntitySystems
if (!Resolve(uid, ref battery))
return;
var old = battery.Charge;
battery.Charge = MathHelper.Clamp(value, 0, battery._maxCharge);
if (MathHelper.CloseTo(battery.Charge, old))
var old = battery.CurrentCharge;
battery.CurrentCharge = MathHelper.Clamp(value, 0, battery.MaxCharge);
if (MathHelper.CloseTo(battery.CurrentCharge, old))
return;
var ev = new ChargeChangedEvent(battery.CurrentCharge, battery._maxCharge);
var ev = new ChargeChangedEvent(battery.CurrentCharge, battery.MaxCharge);
RaiseLocalEvent(uid, ref ev);
}
@@ -150,7 +150,7 @@ namespace Content.Server.Power.EntitySystems
/// </summary>
public bool TryUseCharge(EntityUid uid, float value, BatteryComponent? battery = null)
{
if (!Resolve(uid, ref battery, false) || value > battery.Charge)
if (!Resolve(uid, ref battery, false) || value > battery.CurrentCharge)
return false;
UseCharge(uid, value, battery);

View File

@@ -17,6 +17,7 @@ internal sealed class ChargerSystem : EntitySystem
{
[Dependency] private readonly ContainerSystem _container = default!;
[Dependency] private readonly PowerCellSystem _powerCell = default!;
[Dependency] private readonly BatterySystem _battery = default!;
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
public override void Initialize()
@@ -201,11 +202,11 @@ internal sealed class ChargerSystem : EntitySystem
if (!SearchForBattery(targetEntity, out var heldBattery))
return;
heldBattery.CurrentCharge += component.ChargeRate * frameTime;
_battery.SetCharge(targetEntity, heldBattery.CurrentCharge + component.ChargeRate * frameTime, heldBattery);
// Just so the sprite won't be set to 99.99999% visibility
if (heldBattery.MaxCharge - heldBattery.CurrentCharge < 0.01)
{
heldBattery.CurrentCharge = heldBattery.MaxCharge;
_battery.SetCharge(targetEntity, heldBattery.MaxCharge, heldBattery);
}
UpdateStatus(uid, component);

View File

@@ -1,5 +1,6 @@
using Content.Server.Administration;
using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems;
using Content.Shared.Administration;
using Robust.Shared.Console;
@@ -39,7 +40,8 @@ namespace Content.Server.Power
shell.WriteLine($"No battery found with id {id}.");
return;
}
battery.CurrentCharge = (battery.MaxCharge * percent) / 100;
var system = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<BatterySystem>();
system.SetCharge(id.Value, battery.MaxCharge * percent / 100, battery);
// Don't acknowledge b/c people WILL forall this
}
}

View File

@@ -179,7 +179,7 @@ public sealed partial class PowerCellSystem : SharedPowerCellSystem
return false;
}
_sharedAppearanceSystem.SetData(uid, PowerCellSlotVisuals.Enabled, battery.Charge > 0);
_sharedAppearanceSystem.SetData(uid, PowerCellSlotVisuals.Enabled, battery.CurrentCharge > 0);
return true;
}

View File

@@ -7,6 +7,7 @@ using Content.Server.Station.Systems;
using Robust.Shared.Timing;
using Robust.Shared.Audio;
using Robust.Shared.Audio.Systems;
using Content.Server.Power.EntitySystems;
namespace Content.Server.PowerSink
{
@@ -31,6 +32,7 @@ namespace Content.Server.PowerSink
[Dependency] private readonly ExplosionSystem _explosionSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly StationSystem _station = default!;
[Dependency] private readonly BatterySystem _battery = default!;
public override void Initialize()
{
@@ -64,7 +66,7 @@ namespace Content.Server.PowerSink
if (!transform.Anchored)
continue;
battery.CurrentCharge += networkLoad.NetworkLoad.ReceivingPower / 1000;
_battery.SetCharge(entity, battery.CurrentCharge + networkLoad.NetworkLoad.ReceivingPower / 1000, battery);
var currentBatteryThreshold = battery.CurrentCharge / battery.MaxCharge;

View File

@@ -1,4 +1,5 @@
using Content.Server.Popups;
using Content.Server.Power.EntitySystems;
using Content.Server.PowerCell;
using Content.Server.Radio.Components;
using Content.Shared.Examine;
@@ -10,6 +11,7 @@ namespace Content.Server.Radio.EntitySystems;
public sealed class JammerSystem : EntitySystem
{
[Dependency] private readonly PowerCellSystem _powerCell = default!;
[Dependency] private readonly BatterySystem _battery = default!;
[Dependency] private readonly PopupSystem _popup = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
@@ -29,7 +31,7 @@ public sealed class JammerSystem : EntitySystem
while (query.MoveNext(out var uid, out var _, out var jam))
{
if (_powerCell.TryGetBatteryFromSlot(uid, out var battery) &&
!battery.TryUseCharge(jam.Wattage * frameTime))
!_battery.TryUseCharge(uid, jam.Wattage * frameTime, battery))
{
RemComp<ActiveRadioJammerComponent>(uid);
}

View File

@@ -31,7 +31,7 @@ public sealed class BatterySensorSystem : EntitySystem
{
[DeviceNetworkConstants.Command] = DeviceNetworkCommandSyncData,
[DeviceNetworkCommandSyncData] = new BatterySensorData(
battery.Charge,
battery.CurrentCharge,
battery.MaxCharge,
netBattery.CurrentReceiving,
netBattery.MaxChargeRate,

View File

@@ -107,7 +107,7 @@ public sealed partial class BorgSystem
if (_powerCell.TryGetBatteryFromSlot(uid, out var battery))
{
hasBattery = true;
chargePercent = battery.Charge / battery.MaxCharge;
chargePercent = battery.CurrentCharge / battery.MaxCharge;
}
var state = new BorgBuiState(chargePercent, hasBattery);

View File

@@ -41,7 +41,7 @@ public sealed partial class GunSystem
if (!TryComp<BatteryComponent>(uid, out var battery))
return;
UpdateShots(uid, component, battery.Charge, battery.MaxCharge);
UpdateShots(uid, component, battery.CurrentCharge, battery.MaxCharge);
}
private void UpdateShots(EntityUid uid, BatteryAmmoProviderComponent component, float charge, float maxCharge)