Files
crystall-punk-14/Content.Client/Buckle/BuckleComponent.cs

64 lines
1.9 KiB
C#
Raw Normal View History

2022-04-10 16:48:11 +12:00
using Content.Shared.ActionBlocker;
2021-12-03 11:15:41 -08:00
using Content.Shared.Buckle.Components;
2022-04-23 21:05:02 -04:00
using Content.Shared.Vehicle.Components;
using Robust.Client.GameObjects;
2021-06-09 22:19:39 +02:00
namespace Content.Client.Buckle
{
[RegisterComponent]
[ComponentReference(typeof(SharedBuckleComponent))]
public sealed class BuckleComponent : SharedBuckleComponent
{
2022-04-10 16:48:11 +12:00
[Dependency] private readonly IEntityManager _entMan = default!;
[Dependency] private readonly IEntitySystemManager _sysMan = default!;
private bool _buckled;
private int? _originalDrawDepth;
2020-07-17 10:43:10 +02:00
public override bool Buckled => _buckled;
2021-12-03 11:15:41 -08:00
public override bool TryBuckle(EntityUid user, EntityUid to)
{
// TODO: Prediction
return false;
}
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
if (curState is not BuckleComponentState buckle)
{
return;
}
_buckled = buckle.Buckled;
LastEntityBuckledTo = buckle.LastEntityBuckledTo;
DontCollide = buckle.DontCollide;
2022-04-10 16:48:11 +12:00
_sysMan.GetEntitySystem<ActionBlockerSystem>().UpdateCanMove(Owner);
if (!_entMan.TryGetComponent(Owner, out SpriteComponent? ownerSprite))
{
return;
}
2022-06-19 21:27:21 -04:00
if (LastEntityBuckledTo != null && _entMan.HasComponent<VehicleComponent>(LastEntityBuckledTo))
2022-04-23 21:05:02 -04:00
{
return;
}
if (_buckled && buckle.DrawDepth.HasValue)
{
_originalDrawDepth ??= ownerSprite.DrawDepth;
ownerSprite.DrawDepth = buckle.DrawDepth.Value;
return;
}
if (_originalDrawDepth.HasValue && !buckle.DrawDepth.HasValue)
{
ownerSprite.DrawDepth = _originalDrawDepth.Value;
_originalDrawDepth = null;
}
}
}
}