ECS handheld lights (#5864)
This commit is contained in:
@@ -3,6 +3,7 @@ using Content.Shared.Light.Component;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Analyzers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Timing;
|
||||
@@ -12,27 +13,18 @@ using static Robust.Client.UserInterface.Controls.BoxContainer;
|
||||
namespace Content.Client.Light.Components
|
||||
{
|
||||
[RegisterComponent]
|
||||
[Friend(typeof(HandheldLightSystem))]
|
||||
public sealed class HandheldLightComponent : SharedHandheldLightComponent, IItemStatus
|
||||
{
|
||||
[ViewVariables] protected override bool HasCell => _level != null;
|
||||
[ViewVariables] protected override bool HasCell => Level != null;
|
||||
|
||||
private byte? _level;
|
||||
public byte? Level;
|
||||
|
||||
public Control MakeControl()
|
||||
{
|
||||
return new StatusControl(this);
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
base.HandleComponentState(curState, nextState);
|
||||
|
||||
if (curState is not HandheldLightComponentState cast)
|
||||
return;
|
||||
|
||||
_level = cast.Charge;
|
||||
}
|
||||
|
||||
private sealed class StatusControl : Control
|
||||
{
|
||||
private const float TimerCycle = 1;
|
||||
@@ -83,7 +75,7 @@ namespace Content.Client.Light.Components
|
||||
_timer += args.DeltaSeconds;
|
||||
_timer %= TimerCycle;
|
||||
|
||||
var level = _parent._level;
|
||||
var level = _parent.Level;
|
||||
|
||||
for (var i = 0; i < _sections.Length; i++)
|
||||
{
|
||||
|
||||
23
Content.Client/Light/HandheldLightSystem.cs
Normal file
23
Content.Client/Light/HandheldLightSystem.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Content.Client.Light.Components;
|
||||
using Content.Shared.Light.Component;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Client.Light;
|
||||
|
||||
public sealed class HandheldLightSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<HandheldLightComponent, ComponentHandleState>(OnHandleState);
|
||||
}
|
||||
|
||||
private void OnHandleState(EntityUid uid, HandheldLightComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not SharedHandheldLightComponent.HandheldLightComponentState state)
|
||||
return;
|
||||
|
||||
component.Level = state.Charge;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user