Files
tbd-station-14/Content.Client/Cuffs/Components/CuffableComponent.cs
Acruid 15fb554c28 Engine Entity Anchoring Changes (#4195)
* Converted all SnapGridPositionChangedEvent subscriptions to AnchorStateChangedEvent.

* Fixes power tests with new anchored requirements.

* Moved AnchorableComponent into construction.
AnchorableComponent now uses Transform.Anchored.

* Fixed bug with nodes, power works again.

* Adds lifetime stages to Component.

* Update Engine to v0.4.70.
2021-06-19 19:41:26 -07:00

61 lines
2.1 KiB
C#

using Content.Shared.CharacterAppearance;
using Content.Shared.Cuffs.Components;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.GameObjects;
using Robust.Shared.Utility;
using Robust.Shared.ViewVariables;
namespace Content.Client.Cuffs.Components
{
[RegisterComponent]
[ComponentReference(typeof(SharedCuffableComponent))]
public class CuffableComponent : SharedCuffableComponent
{
[ViewVariables]
private string? _currentRSI;
[ViewVariables] [ComponentDependency] private readonly SpriteComponent? _spriteComponent = null;
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
if (curState is not CuffableComponentState cuffState)
{
return;
}
CanStillInteract = cuffState.CanStillInteract;
if (_spriteComponent != null)
{
_spriteComponent.LayerSetVisible(HumanoidVisualLayers.Handcuffs, cuffState.NumHandsCuffed > 0);
_spriteComponent.LayerSetColor(HumanoidVisualLayers.Handcuffs, cuffState.Color);
if (cuffState.NumHandsCuffed > 0)
{
if (_currentRSI != cuffState.RSI) // we don't want to keep loading the same RSI
{
_currentRSI = cuffState.RSI;
if (_currentRSI != null)
{
_spriteComponent.LayerSetState(HumanoidVisualLayers.Handcuffs, new RSI.StateId(cuffState.IconState), new ResourcePath(_currentRSI));
}
}
else
{
_spriteComponent.LayerSetState(HumanoidVisualLayers.Handcuffs, new RSI.StateId(cuffState.IconState)); // TODO: safety check to see if RSI contains the state?
}
}
}
}
protected override void OnRemove()
{
base.OnRemove();
_spriteComponent?.LayerSetVisible(HumanoidVisualLayers.Handcuffs, false);
}
}
}