Files
tbd-station-14/Content.Client/Light/HandheldLightSystem.cs
Pieter-Jan Briers e665c2487e Use item status extension method (#23884)
Just removes some lines of code.
2024-01-11 19:14:13 -05:00

68 lines
2.2 KiB
C#

using Content.Client.Items;
using Content.Client.Light.Components;
using Content.Shared.Light;
using Content.Shared.Light.Components;
using Content.Shared.Toggleable;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Shared.Animations;
namespace Content.Client.Light;
public sealed class HandheldLightSystem : SharedHandheldLightSystem
{
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
public override void Initialize()
{
base.Initialize();
Subs.ItemStatus<HandheldLightComponent>(ent => new HandheldLightStatus(ent));
SubscribeLocalEvent<HandheldLightComponent, AppearanceChangeEvent>(OnAppearanceChange);
}
private void OnAppearanceChange(EntityUid uid, HandheldLightComponent? component, ref AppearanceChangeEvent args)
{
if (!Resolve(uid, ref component))
{
return;
}
if (!_appearance.TryGetData<bool>(uid, ToggleableLightVisuals.Enabled, out var enabled, args.Component))
{
return;
}
if (!_appearance.TryGetData<HandheldLightPowerStates>(uid, HandheldLightVisuals.Power, out var state, args.Component))
{
return;
}
if (TryComp<LightBehaviourComponent>(uid, out var lightBehaviour))
{
// Reset any running behaviour to reset the animated properties back to the original value, to avoid conflicts between resets
if (lightBehaviour.HasRunningBehaviours())
{
lightBehaviour.StopLightBehaviour(resetToOriginalSettings: true);
}
if (!enabled)
{
return;
}
switch (state)
{
case HandheldLightPowerStates.FullPower:
break; // We just needed to reset all behaviours
case HandheldLightPowerStates.LowPower:
lightBehaviour.StartLightBehaviour(component.RadiatingBehaviourId);
break;
case HandheldLightPowerStates.Dying:
lightBehaviour.StartLightBehaviour(component.BlinkingBehaviourId);
break;
}
}
}
}