2020-10-13 21:51:54 +02:00
#nullable enable
using Content.Shared.GameObjects.Components.ActionBlocking ;
2020-08-25 08:54:23 -04:00
using Content.Shared.Preferences.Appearance ;
using Robust.Client.GameObjects ;
2020-09-13 14:23:52 +02:00
using Robust.Client.Graphics ;
using Robust.Shared.GameObjects ;
2020-08-25 08:54:23 -04:00
using Robust.Shared.Utility ;
using Robust.Shared.ViewVariables ;
namespace Content.Client.GameObjects.Components.ActionBlocking
{
[RegisterComponent]
public class CuffableComponent : SharedCuffableComponent
{
[ViewVariables]
2021-02-16 02:51:52 +01:00
private string? _currentRSI ;
2020-08-25 08:54:23 -04:00
2020-10-13 21:51:54 +02:00
[ViewVariables] [ ComponentDependency ] private readonly SpriteComponent ? _spriteComponent = null ;
public override void HandleComponentState ( ComponentState ? curState , ComponentState ? nextState )
2020-08-25 08:54:23 -04:00
{
2020-11-26 14:33:31 +01:00
if ( curState is not CuffableComponentState cuffState )
2020-08-25 08:54:23 -04:00
{
return ;
}
CanStillInteract = cuffState . CanStillInteract ;
2020-10-13 21:51:54 +02:00
if ( _spriteComponent ! = null )
2020-08-25 08:54:23 -04:00
{
2020-10-13 21:51:54 +02:00
_spriteComponent . LayerSetVisible ( HumanoidVisualLayers . Handcuffs , cuffState . NumHandsCuffed > 0 ) ;
_spriteComponent . LayerSetColor ( HumanoidVisualLayers . Handcuffs , cuffState . Color ) ;
2020-08-25 08:54:23 -04:00
if ( cuffState . NumHandsCuffed > 0 )
{
if ( _currentRSI ! = cuffState . RSI ) // we don't want to keep loading the same RSI
{
_currentRSI = cuffState . RSI ;
2021-02-16 02:51:52 +01:00
if ( _currentRSI ! = null )
{
_spriteComponent . LayerSetState ( HumanoidVisualLayers . Handcuffs , new RSI . StateId ( cuffState . IconState ) , new ResourcePath ( _currentRSI ) ) ;
}
2020-08-25 08:54:23 -04:00
}
else
{
2020-10-13 21:51:54 +02:00
_spriteComponent . LayerSetState ( HumanoidVisualLayers . Handcuffs , new RSI . StateId ( cuffState . IconState ) ) ; // TODO: safety check to see if RSI contains the state?
2020-08-25 08:54:23 -04:00
}
2020-10-13 21:51:54 +02:00
}
2020-08-25 08:54:23 -04:00
}
}
public override void OnRemove ( )
{
base . OnRemove ( ) ;
2020-10-13 21:51:54 +02:00
_spriteComponent ? . LayerSetVisible ( HumanoidVisualLayers . Handcuffs , false ) ;
2020-08-25 08:54:23 -04:00
}
}
}