component.NextBeepTime = _timing.CurTime;
UpdateBeep(uid, component, false);
if (draw != null)
- draw.Enabled = true;
+ _powerCell.SetPowerCellDrawEnabled(uid, true, draw);
return true;
}
component.Enabled = false;
_appearance.SetData(uid, ProximityBeeperVisuals.Enabled, false);
- if (TryComp<PowerCellDrawComponent>(uid, out var draw))
- draw.Enabled = true;
+ _powerCell.SetPowerCellDrawEnabled(uid, true);
UpdateBeep(uid, component);
return true;
}
/// <summary>
/// Indicates that the entity's ActivatableUI requires power or else it closes.
/// </summary>
-[RegisterComponent]
+[RegisterComponent, Access(typeof(PowerCellSystem))]
public sealed class PowerCellDrawComponent : Component
{
[ViewVariables(VVAccess.ReadWrite), DataField("enabled")]
- public bool Enabled = false;
+ public bool Enabled;
/// <summary>
/// How much the entity draws while the UI is open.
/// This is used to ensure the UI won't open again without a minimum use power.
/// </summary>
[ViewVariables(VVAccess.ReadWrite), DataField("useRate")]
- public float UseRate = 0f;
+ public float UseRate;
/// <summary>
/// When the next automatic power draw will occur
#endregion
+ public void SetPowerCellDrawEnabled(EntityUid uid, bool enabled, PowerCellDrawComponent? component = null)
+ {
+ if (!Resolve(uid, ref component, false))
+ return;
+
+ component.Enabled = enabled;
+ component.NextUpdateTime = _timing.CurTime;
+ }
+
/// <summary>
/// Returns whether the entity has a slotted battery and charge for the requested action.
/// </summary>
private void OnPowerCellRemoved(EntityUid uid, PowerCellDrawComponent component, EntRemovedFromContainerMessage args)
{
- if (TryComp<PowerCellDrawComponent>(uid, out var draw))
- {
- draw.Enabled = false;
- }
+ _cell.SetPowerCellDrawEnabled(uid, false);
if (HasComp<ActivatableUIRequiresPowerCellComponent>(uid) &&
TryComp<ActivatableUIComponent>(uid, out var activatable) &&
private void OnBatteryOpened(EntityUid uid, ActivatableUIRequiresPowerCellComponent component, BoundUIOpenedEvent args)
{
- if (!TryComp<PowerCellDrawComponent>(uid, out var draw))
- return;
-
- draw.Enabled = true;
+ _cell.SetPowerCellDrawEnabled(uid, true);
}
private void OnBatteryClosed(EntityUid uid, ActivatableUIRequiresPowerCellComponent component, BoundUIClosedEvent args)
{
- if (!TryComp<PowerCellDrawComponent>(uid, out var draw))
- return;
-
- draw.Enabled = false;
+ _cell.SetPowerCellDrawEnabled(uid, false);
}
/// <summary>