diff --git a/Content.Client/Buckle/BuckleSystem.cs b/Content.Client/Buckle/BuckleSystem.cs index 4b89d9b106..9d2f72b7cf 100644 --- a/Content.Client/Buckle/BuckleSystem.cs +++ b/Content.Client/Buckle/BuckleSystem.cs @@ -65,16 +65,22 @@ namespace Content.Client.Buckle private void OnAppearanceChange(EntityUid uid, BuckleComponent component, ref AppearanceChangeEvent args) { + if (!TryComp(uid, out var rotVisuals)) + return; + if (!_appearanceSystem.TryGetData(uid, StrapVisuals.RotationAngle, out var angle, args.Component) || !_appearanceSystem.TryGetData(uid, BuckleVisuals.Buckled, out var buckled, args.Component) || !buckled || args.Sprite == null) { + _rotationVisualizerSystem.SetHorizontalAngle(uid, RotationVisualsComponent.DefaultRotation, rotVisuals); return; } // Animate strapping yourself to something at a given angle - _rotationVisualizerSystem.AnimateSpriteRotation(args.Sprite, Angle.FromDegrees(angle), 0.125f); + _rotationVisualizerSystem.SetHorizontalAngle(uid, Angle.FromDegrees(angle), rotVisuals); + // TODO: Dump this when buckle is better + _rotationVisualizerSystem.AnimateSpriteRotation(uid, args.Sprite, rotVisuals.HorizontalRotation, 0.125f); } } } diff --git a/Content.Client/Rotation/RotationVisualizerSystem.cs b/Content.Client/Rotation/RotationVisualizerSystem.cs index 3f7d4564e8..892a93eb51 100644 --- a/Content.Client/Rotation/RotationVisualizerSystem.cs +++ b/Content.Client/Rotation/RotationVisualizerSystem.cs @@ -7,6 +7,18 @@ namespace Content.Client.Rotation; public sealed class RotationVisualizerSystem : VisualizerSystem { + public void SetHorizontalAngle(EntityUid uid, Angle angle, RotationVisualsComponent? component = null) + { + if (!Resolve(uid, ref component)) + return; + + if (component.HorizontalRotation.Equals(angle)) + return; + + component.HorizontalRotation = angle; + Dirty(component); + } + protected override void OnAppearanceChange(EntityUid uid, RotationVisualsComponent component, ref AppearanceChangeEvent args) { base.OnAppearanceChange(uid, component, ref args); @@ -20,10 +32,10 @@ public sealed class RotationVisualizerSystem : VisualizerSystem /// Rotates a sprite between two animated keyframes given a certain time. /// - public void AnimateSpriteRotation(SpriteComponent spriteComp, Angle rotation, float animationTime) + public void AnimateSpriteRotation(EntityUid uid, SpriteComponent spriteComp, Angle rotation, float animationTime) { if (spriteComp.Rotation.Equals(rotation)) { return; } - var animationComp = EnsureComp(spriteComp.Owner); + var animationComp = EnsureComp(uid); const string animationKey = "rotate"; // Stop the current rotate animation and then start a new one if (AnimationSystem.HasRunningAnimation(animationComp, animationKey)) diff --git a/Content.Client/Rotation/RotationVisualsComponent.cs b/Content.Client/Rotation/RotationVisualsComponent.cs index ee7fc6a7cc..3ca602746e 100644 --- a/Content.Client/Rotation/RotationVisualsComponent.cs +++ b/Content.Client/Rotation/RotationVisualsComponent.cs @@ -3,11 +3,12 @@ namespace Content.Client.Rotation; [RegisterComponent] public sealed class RotationVisualsComponent : Component { + public static readonly Angle DefaultRotation = Angle.FromDegrees(90); + [ViewVariables(VVAccess.ReadWrite)] public Angle VerticalRotation = 0; - [ViewVariables(VVAccess.ReadWrite)] - public Angle HorizontalRotation = Angle.FromDegrees(90); + [ViewVariables(VVAccess.ReadWrite)] public Angle HorizontalRotation = DefaultRotation; [ViewVariables(VVAccess.ReadWrite)] public float AnimationTime = 0.125f;