Files
OldThink/Content.Client/Light/HandheldLightSystem.cs

71 lines
2.3 KiB
C#
Raw Normal View History

using Content.Client.Items;
2021-12-27 18:15:16 +11:00
using Content.Client.Light.Components;
using Content.Shared.Light;
using Content.Shared.Toggleable;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Shared.Animations;
2021-12-27 18:15:16 +11:00
namespace Content.Client.Light;
public sealed class HandheldLightSystem : SharedHandheldLightSystem
2021-12-27 18:15:16 +11:00
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<HandheldLightComponent, ItemStatusCollectMessage>(OnGetStatusControl);
SubscribeLocalEvent<HandheldLightComponent, AppearanceChangeEvent>(OnAppearanceChange);
}
private static void OnGetStatusControl(EntityUid uid, HandheldLightComponent component, ItemStatusCollectMessage args)
2021-12-27 18:15:16 +11:00
{
args.Controls.Add(new HandheldLightStatus(component));
2021-12-27 18:15:16 +11:00
}
private void OnAppearanceChange(EntityUid uid, HandheldLightComponent? component, ref AppearanceChangeEvent args)
{
if (!Resolve(uid, ref component))
{
return;
}
if (!args.Component.TryGetData(ToggleableLightVisuals.Enabled, out bool enabled))
{
return;
}
if (!args.Component.TryGetData(HandheldLightVisuals.Power,
out HandheldLightPowerStates state))
{
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;
}
}
}
2021-12-27 18:15:16 +11:00
}