CatStation/Content.Client/Light/HandheldLightSystem.cs
Whatstone d9ffbf1d03
Cleanup: AppearanceSystem.TryGetData to AppearanceChangeEvent.TryGetData (#45373)
* First impl. of appearance TryGetData cleanup

* Handful of fixes

* DamageVisuals: fix HandleDamage call, inheritdoc

* bunch of unused AppearanceSystem instances

* Handful more unused appearance systems, inheritdoc

* JetpackSystem: Ent<T>

* cleanup roundup, more Ent<T>

* a few lingering AppearanceSystem.TryGetData calls

* more lingering AppearanceData access

* Remove unnecessary inheritdoc

* once again, with feeling
2026-10-05 00:45:37 +00:00

72 lines
2.6 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.GameObjects;
using Content.Client.Light.EntitySystems;
namespace Content.Client.Light;
public sealed partial class HandheldLightSystem : SharedHandheldLightSystem
{
[Dependency] private SharedAppearanceSystem _appearance = default!;
[Dependency] private LightBehaviorSystem _lightBehavior = default!;
public override void Initialize()
{
base.Initialize();
Subs.ItemStatus<HandheldLightComponent>(ent => new HandheldLightStatus(ent));
SubscribeLocalEvent<HandheldLightComponent, AppearanceChangeEvent>(OnAppearanceChange);
}
/// <remarks>
/// TODO: Not properly predicted yet. Don't call this function if you want a the actual return value!
/// </remarks>
public override bool TurnOff(Entity<HandheldLightComponent> ent, bool makeNoise = true)
{
return true;
}
/// <remarks>
/// TODO: Not properly predicted yet. Don't call this function if you want a the actual return value!
/// </remarks>
public override bool TurnOn(EntityUid user, Entity<HandheldLightComponent> uid)
{
return true;
}
private void OnAppearanceChange(EntityUid uid, HandheldLightComponent component, ref AppearanceChangeEvent args)
{
if (!args.TryGetData<bool>(ToggleableVisuals.Enabled, out var enabled))
return;
if (!args.TryGetData<HandheldLightPowerStates>(HandheldLightVisuals.Power, out var state))
return;
if (!TryComp<LightBehaviourComponent>(uid, out var lightBehaviour))
return;
// Reset any running behaviour to reset the animated properties back to the original value, to avoid conflicts between resets
if (_lightBehavior.HasRunningBehaviours((uid, lightBehaviour)))
{
_lightBehavior.StopLightBehaviour((uid, lightBehaviour), resetToOriginalSettings: true);
}
if (!enabled)
return;
switch (state)
{
case HandheldLightPowerStates.FullPower:
break; // We just needed to reset all behaviours
case HandheldLightPowerStates.LowPower:
_lightBehavior.StartLightBehaviour((uid, lightBehaviour), component.RadiatingBehaviourId);
break;
case HandheldLightPowerStates.Dying:
_lightBehavior.StartLightBehaviour((uid, lightBehaviour), component.BlinkingBehaviourId);
break;
}
}
}