Files

66 lines
2.7 KiB
C#
Raw Permalink Normal View History

2022-12-20 18:24:50 -04:00
using Content.Client.Rotation;
2021-06-09 22:19:39 +02:00
using Content.Shared.Buckle;
using Content.Shared.Buckle.Components;
using Content.Shared.Rotation;
2022-11-14 20:30:30 +01:00
using Robust.Client.GameObjects;
2021-06-09 22:19:39 +02:00
namespace Content.Client.Buckle;
2022-11-14 20:30:30 +01:00
internal sealed class BuckleSystem : SharedBuckleSystem
{
[Dependency] private readonly RotationVisualizerSystem _rotationVisualizerSystem = default!;
2022-11-14 20:30:30 +01:00
public override void Initialize()
{
base.Initialize();
2021-06-09 22:19:39 +02:00
SubscribeLocalEvent<BuckleComponent, AfterAutoHandleStateEvent>(OnBuckleAfterAutoHandleState);
SubscribeLocalEvent<BuckleComponent, AppearanceChangeEvent>(OnAppearanceChange);
}
2022-11-14 20:30:30 +01:00
private void OnBuckleAfterAutoHandleState(EntityUid uid, BuckleComponent component, ref AfterAutoHandleStateEvent args)
{
2023-09-16 07:15:05 +03:00
ActionBlocker.UpdateCanMove(uid);
2022-11-14 20:30:30 +01:00
if (!TryComp<SpriteComponent>(uid, out var ownerSprite))
return;
2022-11-14 20:30:30 +01:00
// Adjust draw depth when the chair faces north so that the seat back is drawn over the player.
// Reset the draw depth when rotated in any other direction.
// TODO when ECSing, make this a visualizer
// This code was written before rotatable viewports were introduced, so hard-coding Direction.North
// and comparing it against LocalRotation now breaks this in other rotations. This is a FIXME, but
// better to get it working for most people before we look at a more permanent solution.
if (component is { Buckled: true, LastEntityBuckledTo: { } } &&
Transform(component.LastEntityBuckledTo.Value).LocalRotation.GetCardinalDir() == Direction.North &&
TryComp<SpriteComponent>(component.LastEntityBuckledTo, out var buckledSprite))
{
component.OriginalDrawDepth ??= ownerSprite.DrawDepth;
ownerSprite.DrawDepth = buckledSprite.DrawDepth - 1;
return;
2022-11-14 20:30:30 +01:00
}
// If here, we're not turning north and should restore the saved draw depth.
if (component.OriginalDrawDepth.HasValue)
2022-12-20 18:24:50 -04:00
{
ownerSprite.DrawDepth = component.OriginalDrawDepth.Value;
component.OriginalDrawDepth = null;
}
}
2023-01-24 07:50:35 +11:00
private void OnAppearanceChange(EntityUid uid, BuckleComponent component, ref AppearanceChangeEvent args)
{
if (!TryComp<RotationVisualsComponent>(uid, out var rotVisuals))
return;
2022-12-20 18:24:50 -04:00
if (!Appearance.TryGetData<bool>(uid, BuckleVisuals.Buckled, out var buckled, args.Component) ||
!buckled ||
args.Sprite == null)
return;
// Animate strapping yourself to something at a given angle
// TODO: Dump this when buckle is better
_rotationVisualizerSystem.AnimateSpriteRotation(uid, args.Sprite, rotVisuals.HorizontalRotation, 0.125f);
2021-06-09 22:19:39 +02:00
}
}