There were TWO bugs here FIRST, APCs *did* update their visual state on initialization, but at that point the relevant power state hasn't been initialized yet, so it always returns a bogus result. There aren't guaranteed to be subsequent power updates that actually trigger the APC to update so this can get it stuck. Fixed by just deferring the on-init update to be after the first update tick, which is itself ordered to be after power update. SECOND: Once I fixed that, I ran into the issue that APCs created at *server startup* also fail to update, because the throttling system (to prevent frequent APC updates) thinks the LastChargeStateTime was at server startup. Fixed by making that variable nullable so it defaults to null. Also removed the useless datafields on the "last update" fields. These are all just used to cache and throttle updates, something that should not be persisted to a map file.
52 lines
1.6 KiB
C#
52 lines
1.6 KiB
C#
using Content.Server.Power.NodeGroups;
|
|
using Content.Shared.APC;
|
|
using Robust.Shared.Audio;
|
|
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
|
|
|
namespace Content.Server.Power.Components;
|
|
|
|
[RegisterComponent]
|
|
public sealed partial class ApcComponent : BaseApcNetComponent
|
|
{
|
|
[DataField("onReceiveMessageSound")]
|
|
public SoundSpecifier OnReceiveMessageSound = new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg");
|
|
|
|
public ApcChargeState LastChargeState;
|
|
public TimeSpan? LastChargeStateTime;
|
|
|
|
public ApcExternalPowerState LastExternalState;
|
|
|
|
/// <summary>
|
|
/// Time the ui was last updated automatically.
|
|
/// Done after every <see cref="VisualsChangeDelay"/> to show the latest load.
|
|
/// If charge state changes it will be instantly updated.
|
|
/// </summary>
|
|
public TimeSpan LastUiUpdate;
|
|
|
|
[DataField("enabled")]
|
|
public bool MainBreakerEnabled = true;
|
|
// TODO: remove this since it probably breaks when 2 people use it
|
|
[DataField("hasAccess")]
|
|
public bool HasAccess = false;
|
|
|
|
/// <summary>
|
|
/// APC state needs to always be updated after first processing tick.
|
|
/// </summary>
|
|
public bool NeedStateUpdate;
|
|
|
|
public const float HighPowerThreshold = 0.9f;
|
|
public static TimeSpan VisualsChangeDelay = TimeSpan.FromSeconds(1);
|
|
|
|
// TODO ECS power a little better!
|
|
// End the suffering
|
|
protected override void AddSelfToNet(IApcNet apcNet)
|
|
{
|
|
apcNet.AddApc(Owner, this);
|
|
}
|
|
|
|
protected override void RemoveSelfFromNet(IApcNet apcNet)
|
|
{
|
|
apcNet.RemoveApc(Owner, this);
|
|
}
|
|
}
|