From 38a31db13fc9681578b4b49bffa54af4f6316658 Mon Sep 17 00:00:00 2001 From: AJCM-git <60196617+AJCM-git@users.noreply.github.com> Date: Tue, 20 Dec 2022 18:24:50 -0400 Subject: [PATCH] Fix bed strapping flip flop (#13094) --- Content.Client/Buckle/BuckleSystem.cs | 19 ++++++- .../Buckle/BuckleVisualizerSystem.cs | 23 -------- .../Rotation/RotationVisualizerSystem.cs | 56 +++++++++---------- 3 files changed, 45 insertions(+), 53 deletions(-) delete mode 100644 Content.Client/Buckle/BuckleVisualizerSystem.cs diff --git a/Content.Client/Buckle/BuckleSystem.cs b/Content.Client/Buckle/BuckleSystem.cs index 7d7f591718..0279001d10 100644 --- a/Content.Client/Buckle/BuckleSystem.cs +++ b/Content.Client/Buckle/BuckleSystem.cs @@ -1,4 +1,5 @@ using Content.Client.Buckle.Strap; +using Content.Client.Rotation; using Content.Shared.ActionBlocker; using Content.Shared.Buckle; using Content.Shared.Buckle.Components; @@ -11,14 +12,16 @@ namespace Content.Client.Buckle internal sealed class BuckleSystem : SharedBuckleSystem { [Dependency] private readonly ActionBlockerSystem _actionBlocker = default!; + [Dependency] private readonly AppearanceSystem AppearanceSystem = default!; + [Dependency] private readonly RotationVisualizerSystem RotationVisualizerSystem = default!; public override void Initialize() { base.Initialize(); SubscribeLocalEvent(OnBuckleHandleState); - SubscribeLocalEvent(OnStrapHandleState); + SubscribeLocalEvent(OnAppearanceChange); } private void OnBuckleHandleState(EntityUid uid, BuckleComponent buckle, ref ComponentHandleState args) @@ -73,5 +76,19 @@ namespace Content.Client.Buckle component.BuckledEntities.UnionWith(state.BuckledEntities); component.MaxBuckleDistance = state.MaxBuckleDistance; } + + private void OnAppearanceChange(EntityUid uid, BuckleComponent component, ref AppearanceChangeEvent args) + { + 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) + { + return; + } + + // Animate strapping yourself to something at a given angle + RotationVisualizerSystem.AnimateSpriteRotation(args.Sprite, Angle.FromDegrees(angle), 0.125f); + } } } diff --git a/Content.Client/Buckle/BuckleVisualizerSystem.cs b/Content.Client/Buckle/BuckleVisualizerSystem.cs deleted file mode 100644 index f5531ced44..0000000000 --- a/Content.Client/Buckle/BuckleVisualizerSystem.cs +++ /dev/null @@ -1,23 +0,0 @@ -using Content.Shared.Buckle.Components; -using Content.Client.Rotation; -using Robust.Client.GameObjects; - -namespace Content.Client.Buckle; - -public sealed class BuckleVisualizer : VisualizerSystem -{ - protected override void OnAppearanceChange(EntityUid uid, BuckleComponent component, ref AppearanceChangeEvent args) - { - if (!args.Component.TryGetData(StrapVisuals.RotationAngle, out var angle) || - !args.Component.TryGetData(BuckleVisuals.Buckled, out var buckled) || - !buckled || - args.Sprite == null) - { - return; - } - - EntityManager.System() - .AnimateSpriteRotation(args.Sprite, Angle.FromDegrees(angle), 0.125f); - } -} - diff --git a/Content.Client/Rotation/RotationVisualizerSystem.cs b/Content.Client/Rotation/RotationVisualizerSystem.cs index d67ca67615..a309e1afa7 100644 --- a/Content.Client/Rotation/RotationVisualizerSystem.cs +++ b/Content.Client/Rotation/RotationVisualizerSystem.cs @@ -1,6 +1,6 @@ -using Robust.Client.GameObjects; -using Robust.Client.Animations; using Content.Shared.Rotation; +using Robust.Client.Animations; +using Robust.Client.GameObjects; using Robust.Shared.Animations; namespace Content.Client.Rotation; @@ -11,47 +11,43 @@ public sealed class RotationVisualizerSystem : VisualizerSystem(uid, RotationVisuals.RotationState, out var state, args.Component) || + args.Sprite == null) { - // if TryGetData fails, state defaults to RotationState.Vertical. - args.Component.TryGetData(RotationVisuals.RotationState, out var state); + return; + } - switch (state) - { - case RotationState.Vertical: - AnimateSpriteRotation(args.Sprite, component.VerticalRotation, component.AnimationTime); - break; - case RotationState.Horizontal: - AnimateSpriteRotation(args.Sprite, component.HorizontalRotation, component.AnimationTime); - break; - } + switch (state) + { + case RotationState.Vertical: + AnimateSpriteRotation(args.Sprite, component.VerticalRotation, component.AnimationTime); + break; + case RotationState.Horizontal: + AnimateSpriteRotation(args.Sprite, component.HorizontalRotation, component.AnimationTime); + break; } } /// /// Rotates a sprite between two animated keyframes given a certain time. /// - public void AnimateSpriteRotation(SpriteComponent sprite, Angle rotation, float animationTime) + public void AnimateSpriteRotation(SpriteComponent spriteComp, Angle rotation, float animationTime) { - var entMan = IoCManager.Resolve(); - - if (sprite.Rotation.Equals(rotation)) + if (spriteComp.Rotation.Equals(rotation)) { return; } - if (!entMan.TryGetComponent(sprite.Owner, out AnimationPlayerComponent? animation)) + var animationComp = EnsureComp(spriteComp.Owner); + const string animationKey = "rotate"; + // Stop the current rotate animation and then start a new one + if (AnimationSystem.HasRunningAnimation(animationComp, animationKey)) { - sprite.Rotation = rotation; - return; + AnimationSystem.Stop(animationComp, animationKey); } + spriteComp.Rotation = rotation; - if (animation.HasRunningAnimation("rotate")) - { - animation.Stop("rotate"); - } - - animation.Play(new Animation + var animation = new Animation { Length = TimeSpan.FromSeconds(animationTime), AnimationTracks = @@ -63,11 +59,13 @@ public sealed class RotationVisualizerSystem : VisualizerSystem