Files
tbd-station-14/Content.Client/GameObjects/Components/Conveyor/TwoWayLeverVisualizer.cs
DrSmugleaf 902aa128c2 Enable nullability in Content.Client (#3257)
* Enable nullability in Content.Client

* Remove #nullable enable

* Merge fixes

* Remove Debug.Assert

* Merge fixes

* Fix build

* Fix build
2021-03-10 14:48:29 +01:00

56 lines
1.6 KiB
C#

using Content.Shared.GameObjects.Components.MachineLinking;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Client.GameObjects.Components.Conveyor
{
[UsedImplicitly]
public class TwoWayLeverVisualizer : AppearanceVisualizer
{
[DataField("state_forward")]
private string? _stateForward;
[DataField("state_off")]
private string? _stateOff;
[DataField("state_reversed")]
private string? _stateReversed;
private void ChangeState(AppearanceComponent appearance)
{
if (!appearance.Owner.TryGetComponent(out ISpriteComponent? sprite))
{
return;
}
appearance.TryGetData(TwoWayLeverVisuals.State, out TwoWayLeverSignal state);
var texture = state switch
{
TwoWayLeverSignal.Middle => _stateOff,
TwoWayLeverSignal.Right => _stateForward,
TwoWayLeverSignal.Left => _stateReversed,
_ => _stateOff
};
sprite.LayerSetState(0, texture);
}
public override void InitializeEntity(IEntity entity)
{
base.InitializeEntity(entity);
var appearance = entity.EnsureComponent<AppearanceComponent>();
ChangeState(appearance);
}
public override void OnChangeData(AppearanceComponent component)
{
base.OnChangeData(component);
ChangeState(component);
}
}
}