2021-06-09 22:19:39 +02:00
using Content.Shared.CharacterAppearance ;
using Content.Shared.Cuffs.Components ;
2020-08-25 08:54:23 -04:00
using Robust.Client.GameObjects ;
2020-09-13 14:23:52 +02:00
using Robust.Client.Graphics ;
using Robust.Shared.GameObjects ;
2022-01-15 03:26:37 +01:00
using Robust.Shared.IoC ;
2020-08-25 08:54:23 -04:00
using Robust.Shared.Utility ;
using Robust.Shared.ViewVariables ;
2021-06-09 22:19:39 +02:00
namespace Content.Client.Cuffs.Components
2020-08-25 08:54:23 -04:00
{
[RegisterComponent]
2021-06-17 00:37:05 +10:00
[ComponentReference(typeof(SharedCuffableComponent))]
2022-02-16 00:23:23 -07:00
public sealed class CuffableComponent : SharedCuffableComponent
2020-08-25 08:54:23 -04:00
{
[ViewVariables]
2021-02-16 02:51:52 +01:00
private string? _currentRSI ;
2020-08-25 08:54:23 -04:00
2022-01-15 03:26:37 +01:00
[Dependency] private readonly IEntityManager _entityManager = default ! ;
2020-10-13 21:51:54 +02:00
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 ;
2022-01-15 03:26:37 +01:00
if ( _entityManager . TryGetComponent < SpriteComponent > ( Owner , out var spriteComponent ) )
2020-08-25 08:54:23 -04:00
{
2022-01-15 03:26:37 +01: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 )
{
2022-01-15 03:26:37 +01:00
spriteComponent . LayerSetState ( HumanoidVisualLayers . Handcuffs , new RSI . StateId ( cuffState . IconState ) , new ResourcePath ( _currentRSI ) ) ;
2021-02-16 02:51:52 +01:00
}
2020-08-25 08:54:23 -04:00
}
else
{
2022-01-15 03:26:37 +01: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
}
}
2021-06-19 19:41:26 -07:00
protected override void OnRemove ( )
2020-08-25 08:54:23 -04:00
{
base . OnRemove ( ) ;
2022-01-15 03:26:37 +01:00
if ( _entityManager . TryGetComponent < SpriteComponent > ( Owner , out var spriteComponent ) )
spriteComponent . LayerSetVisible ( HumanoidVisualLayers . Handcuffs , false ) ;
2020-08-25 08:54:23 -04:00
}
}
}