Fix the flashlight's power bar and status with no battery (#1862)
Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com>
This commit is contained in:
@@ -13,7 +13,10 @@ namespace Content.Client.GameObjects.Components
|
||||
[RegisterComponent]
|
||||
public sealed class HandheldLightComponent : SharedHandheldLightComponent, IItemStatus
|
||||
{
|
||||
private bool _hasCell;
|
||||
|
||||
[ViewVariables] public float? Charge { get; private set; }
|
||||
[ViewVariables] protected override bool HasCell => _hasCell;
|
||||
|
||||
public Control MakeControl()
|
||||
{
|
||||
@@ -26,6 +29,7 @@ namespace Content.Client.GameObjects.Components
|
||||
return;
|
||||
|
||||
Charge = cast.Charge;
|
||||
_hasCell = cast.HasCell;
|
||||
}
|
||||
|
||||
private sealed class StatusControl : Control
|
||||
|
||||
@@ -53,6 +53,8 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
[ViewVariables]
|
||||
public bool Activated { get; private set; }
|
||||
|
||||
[ViewVariables] protected override bool HasCell => Cell != null;
|
||||
|
||||
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs eventArgs)
|
||||
{
|
||||
if (!eventArgs.Using.HasComponent<BatteryComponent>()) return false;
|
||||
@@ -211,6 +213,8 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
return;
|
||||
}
|
||||
|
||||
Dirty();
|
||||
|
||||
if (!user.TryGetComponent(out HandsComponent? hands))
|
||||
{
|
||||
return;
|
||||
@@ -229,17 +233,17 @@ namespace Content.Server.GameObjects.Components.Interactable
|
||||
{
|
||||
if (Cell == null)
|
||||
{
|
||||
return new HandheldLightComponentState(null);
|
||||
return new HandheldLightComponentState(null, false);
|
||||
}
|
||||
|
||||
if (Wattage > Cell.CurrentCharge)
|
||||
{
|
||||
// Practically zero.
|
||||
// This is so the item status works correctly.
|
||||
return new HandheldLightComponentState(0);
|
||||
return new HandheldLightComponentState(0, HasCell);
|
||||
}
|
||||
|
||||
return new HandheldLightComponentState(Cell.CurrentCharge / Cell.MaxCharge);
|
||||
return new HandheldLightComponentState(Cell.CurrentCharge / Cell.MaxCharge, HasCell);
|
||||
}
|
||||
|
||||
[Verb]
|
||||
|
||||
@@ -9,15 +9,20 @@ namespace Content.Shared.GameObjects.Components
|
||||
public sealed override string Name => "HandheldLight";
|
||||
public sealed override uint? NetID => ContentNetIDs.HANDHELD_LIGHT;
|
||||
|
||||
protected abstract bool HasCell { get; }
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
protected sealed class HandheldLightComponentState : ComponentState
|
||||
{
|
||||
public HandheldLightComponentState(float? charge) : base(ContentNetIDs.HANDHELD_LIGHT)
|
||||
public HandheldLightComponentState(float? charge, bool hasCell) : base(ContentNetIDs.HANDHELD_LIGHT)
|
||||
{
|
||||
Charge = charge;
|
||||
HasCell = hasCell;
|
||||
}
|
||||
|
||||
public float? Charge { get; }
|
||||
|
||||
public bool HasCell { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user