Files
crystall-punk-14/Content.Client/Shuttles/ThrusterVisualizer.cs

71 lines
2.5 KiB
C#
Raw Normal View History

2021-11-21 17:09:49 +11:00
using Content.Shared.Shuttles.Components;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
2021-12-05 18:09:01 +01:00
using Robust.Shared.IoC;
2021-11-21 17:09:49 +11:00
namespace Content.Client.Shuttles
{
public sealed class ThrusterVisualizer : AppearanceVisualizer
{
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
2021-12-05 18:09:01 +01:00
var entities = IoCManager.Resolve<IEntityManager>();
if (!entities.TryGetComponent(component.Owner, out SpriteComponent? spriteComponent)) return;
2021-11-21 17:09:49 +11:00
component.TryGetData(ThrusterVisualState.State, out bool state);
switch (state)
{
case true:
spriteComponent.LayerSetVisible(ThrusterVisualLayers.ThrustOn, true);
if (component.TryGetData(ThrusterVisualState.Thrusting, out bool thrusting) && thrusting)
{
if (spriteComponent.LayerMapTryGet(ThrusterVisualLayers.Thrusting, out _))
{
spriteComponent.LayerSetVisible(ThrusterVisualLayers.Thrusting, true);
}
if (spriteComponent.LayerMapTryGet(ThrusterVisualLayers.ThrustingUnshaded, out _))
{
spriteComponent.LayerSetVisible(ThrusterVisualLayers.ThrustingUnshaded, true);
}
}
else
{
DisableThrusting(component, spriteComponent);
}
break;
case false:
spriteComponent.LayerSetVisible(ThrusterVisualLayers.ThrustOn, false);
DisableThrusting(component, spriteComponent);
break;
}
}
private void DisableThrusting(AppearanceComponent component, SpriteComponent spriteComponent)
{
if (spriteComponent.LayerMapTryGet(ThrusterVisualLayers.Thrusting, out _))
{
spriteComponent.LayerSetVisible(ThrusterVisualLayers.Thrusting, false);
}
if (spriteComponent.LayerMapTryGet(ThrusterVisualLayers.ThrustingUnshaded, out _))
{
spriteComponent.LayerSetVisible(ThrusterVisualLayers.ThrustingUnshaded, false);
}
}
}
public enum ThrusterVisualLayers : byte
{
Base,
ThrustOn,
Thrusting,
ThrustingUnshaded,
}
}