* partial buckling refactor * git mv test * change test namespace * git mv test * Update test namespace * Add pulling test * Network BuckleTime * Add two more tests * smelly
93 lines
3.4 KiB
C#
93 lines
3.4 KiB
C#
using Content.Client.Rotation;
|
|
using Content.Shared.Buckle;
|
|
using Content.Shared.Buckle.Components;
|
|
using Content.Shared.Rotation;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Shared.GameStates;
|
|
|
|
namespace Content.Client.Buckle;
|
|
|
|
internal sealed class BuckleSystem : SharedBuckleSystem
|
|
{
|
|
[Dependency] private readonly RotationVisualizerSystem _rotationVisualizerSystem = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<BuckleComponent, ComponentHandleState>(OnHandleState);
|
|
SubscribeLocalEvent<BuckleComponent, AppearanceChangeEvent>(OnAppearanceChange);
|
|
SubscribeLocalEvent<StrapComponent, MoveEvent>(OnStrapMoveEvent);
|
|
}
|
|
|
|
private void OnStrapMoveEvent(EntityUid uid, StrapComponent component, ref MoveEvent args)
|
|
{
|
|
// 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
|
|
|
|
// 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)
|
|
return;
|
|
|
|
if (!TryComp<SpriteComponent>(uid, out var strapSprite))
|
|
return;
|
|
|
|
var isNorth = Transform(uid).LocalRotation.GetCardinalDir() == Direction.North;
|
|
foreach (var buckledEntity in component.BuckledEntities)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnHandleState(Entity<BuckleComponent> ent, ref ComponentHandleState args)
|
|
{
|
|
if (args.Current is not BuckleState state)
|
|
return;
|
|
|
|
ent.Comp.DontCollide = state.DontCollide;
|
|
ent.Comp.BuckleTime = state.BuckleTime;
|
|
var strapUid = EnsureEntity<BuckleComponent>(state.BuckledTo, ent);
|
|
|
|
SetBuckledTo(ent, strapUid == null ? null : new (strapUid.Value, null));
|
|
|
|
var (uid, component) = ent;
|
|
|
|
}
|
|
|
|
private void OnAppearanceChange(EntityUid uid, BuckleComponent component, ref AppearanceChangeEvent args)
|
|
{
|
|
if (!TryComp<RotationVisualsComponent>(uid, out var rotVisuals))
|
|
return;
|
|
|
|
if (!Appearance.TryGetData<bool>(uid, BuckleVisuals.Buckled, out var buckled, args.Component) ||
|
|
!buckled ||
|
|
args.Sprite == null)
|
|
{
|
|
_rotationVisualizerSystem.SetHorizontalAngle((uid, rotVisuals), rotVisuals.DefaultRotation);
|
|
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);
|
|
}
|
|
}
|