Files
tbd-station-14/Content.Client/Singularity/Systems/EmitterSystem.cs
MilenVolf c7870882f6 LockVisualizer (#25224)
* LockVisualizer

* Fix state

* Clean some code

* Make it component, fix tests fail

* Fix for StateUnlocked

Now it is possible to manually set the unlocked state and it will work!

* Optimize LockVisualizer, add check for unlocked state

* No todo I guess
2024-02-16 16:52:31 -07:00

50 lines
1.7 KiB
C#

using Content.Shared.Singularity.Components;
using Content.Shared.Singularity.EntitySystems;
using Robust.Client.GameObjects;
namespace Content.Client.Singularity.Systems;
public sealed class EmitterSystem : SharedEmitterSystem
{
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<EmitterComponent, AppearanceChangeEvent>(OnAppearanceChange);
}
private void OnAppearanceChange(EntityUid uid, EmitterComponent component, ref AppearanceChangeEvent args)
{
if (args.Sprite == null)
return;
if (!_appearance.TryGetData<EmitterVisualState>(uid, EmitterVisuals.VisualState, out var state, args.Component))
state = EmitterVisualState.Off;
if (!args.Sprite.LayerMapTryGet(EmitterVisualLayers.Lights, out var layer))
return;
switch (state)
{
case EmitterVisualState.On:
if (component.OnState == null)
break;
args.Sprite.LayerSetVisible(layer, true);
args.Sprite.LayerSetState(layer, component.OnState);
break;
case EmitterVisualState.Underpowered:
if (component.UnderpoweredState == null)
break;
args.Sprite.LayerSetVisible(layer, true);
args.Sprite.LayerSetState(layer, component.UnderpoweredState);
break;
case EmitterVisualState.Off:
args.Sprite.LayerSetVisible(layer, false);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}