2022-12-20 18:24:50 -04:00
|
|
|
using Content.Client.Rotation;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Shared.Buckle;
|
2022-07-16 13:51:52 +10:00
|
|
|
using Content.Shared.Buckle.Components;
|
2023-12-26 18:32:25 -05:00
|
|
|
using Content.Shared.Rotation;
|
2022-11-14 20:30:30 +01:00
|
|
|
using Robust.Client.GameObjects;
|
2024-06-20 03:14:18 +12:00
|
|
|
using Robust.Shared.GameStates;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
2023-05-01 03:04:23 -04:00
|
|
|
namespace Content.Client.Buckle;
|
2022-11-14 20:30:30 +01:00
|
|
|
|
2023-05-01 03:04:23 -04:00
|
|
|
internal sealed class BuckleSystem : SharedBuckleSystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly RotationVisualizerSystem _rotationVisualizerSystem = default!;
|
2022-11-14 20:30:30 +01:00
|
|
|
|
2023-05-01 03:04:23 -04:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2021-06-09 22:19:39 +02:00
|
|
|
|
2023-05-01 03:04:23 -04:00
|
|
|
SubscribeLocalEvent<BuckleComponent, AppearanceChangeEvent>(OnAppearanceChange);
|
2024-06-20 03:14:18 +12:00
|
|
|
SubscribeLocalEvent<StrapComponent, MoveEvent>(OnStrapMoveEvent);
|
2023-05-01 03:04:23 -04:00
|
|
|
}
|
2022-11-14 20:30:30 +01:00
|
|
|
|
2024-06-20 03:14:18 +12:00
|
|
|
private void OnStrapMoveEvent(EntityUid uid, StrapComponent component, ref MoveEvent args)
|
2023-05-01 03:04:23 -04:00
|
|
|
{
|
2024-06-20 03:14:18 +12:00
|
|
|
// I'm moving this to the client-side system, but for the sake of posterity let's keep this comment:
|
|
|
|
|
// > This is mega cursed. Please somebody save me from Mr Buckle's wild ride
|
2022-11-14 20:30:30 +01:00
|
|
|
|
2024-06-20 03:14:18 +12:00
|
|
|
// The nice thing is its still true, this is quite cursed, though maybe not omega cursed anymore.
|
|
|
|
|
// This code is garbage, it doesn't work with rotated viewports. I need to finally get around to reworking
|
|
|
|
|
// sprite rendering for entity layers & direction dependent sorting.
|
|
|
|
|
|
|
|
|
|
if (args.NewRotation == args.OldRotation)
|
2023-05-01 03:04:23 -04:00
|
|
|
return;
|
2022-11-14 20:30:30 +01:00
|
|
|
|
2024-06-20 03:14:18 +12:00
|
|
|
if (!TryComp<SpriteComponent>(uid, out var strapSprite))
|
2023-05-01 03:04:23 -04:00
|
|
|
return;
|
2022-11-14 20:30:30 +01:00
|
|
|
|
2024-06-20 03:14:18 +12:00
|
|
|
var isNorth = Transform(uid).LocalRotation.GetCardinalDir() == Direction.North;
|
|
|
|
|
foreach (var buckledEntity in component.BuckledEntities)
|
2022-12-20 18:24:50 -04:00
|
|
|
{
|
2024-06-20 03:14:18 +12:00
|
|
|
if (!TryComp<BuckleComponent>(buckledEntity, out var buckle))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!TryComp<SpriteComponent>(buckledEntity, out var buckledSprite))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (isNorth)
|
|
|
|
|
{
|
|
|
|
|
buckle.OriginalDrawDepth ??= buckledSprite.DrawDepth;
|
|
|
|
|
buckledSprite.DrawDepth = strapSprite.DrawDepth - 1;
|
|
|
|
|
}
|
|
|
|
|
else if (buckle.OriginalDrawDepth.HasValue)
|
|
|
|
|
{
|
|
|
|
|
buckledSprite.DrawDepth = buckle.OriginalDrawDepth.Value;
|
|
|
|
|
buckle.OriginalDrawDepth = null;
|
|
|
|
|
}
|
2023-05-01 03:04:23 -04:00
|
|
|
}
|
|
|
|
|
}
|
2023-01-24 07:50:35 +11:00
|
|
|
|
2023-05-01 03:04:23 -04: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
|
|
|
|
2023-12-26 18:32:25 -05:00
|
|
|
if (!Appearance.TryGetData<bool>(uid, BuckleVisuals.Buckled, out var buckled, args.Component) ||
|
2023-05-01 03:04:23 -04:00
|
|
|
!buckled ||
|
|
|
|
|
args.Sprite == null)
|
|
|
|
|
{
|
2023-12-26 18:32:25 -05:00
|
|
|
_rotationVisualizerSystem.SetHorizontalAngle((uid, rotVisuals), rotVisuals.DefaultRotation);
|
2023-05-01 03:04:23 -04:00
|
|
|
return;
|
2022-12-20 18:24:50 -04:00
|
|
|
}
|
2023-05-01 03:04:23 -04:00
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
}
|