Fix bed strapping flip flop (#13094)

This commit is contained in:
AJCM-git
2022-12-20 18:24:50 -04:00
committed by GitHub
parent ba8276dd40
commit 38a31db13f
3 changed files with 45 additions and 53 deletions

View File

@@ -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<RotationVisualsC
{
base.OnAppearanceChange(uid, component, ref args);
if (args.Sprite != null)
if (!AppearanceSystem.TryGetData<RotationState>(uid, RotationVisuals.RotationState, out var state, args.Component) ||
args.Sprite == null)
{
// if TryGetData fails, state defaults to RotationState.Vertical.
args.Component.TryGetData<RotationState>(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;
}
}
/// <summary>
/// Rotates a sprite between two animated keyframes given a certain time.
/// </summary>
public void AnimateSpriteRotation(SpriteComponent sprite, Angle rotation, float animationTime)
public void AnimateSpriteRotation(SpriteComponent spriteComp, Angle rotation, float animationTime)
{
var entMan = IoCManager.Resolve<IEntityManager>();
if (sprite.Rotation.Equals(rotation))
if (spriteComp.Rotation.Equals(rotation))
{
return;
}
if (!entMan.TryGetComponent(sprite.Owner, out AnimationPlayerComponent? animation))
var animationComp = EnsureComp<AnimationPlayerComponent>(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<RotationVisualsC
InterpolationMode = AnimationInterpolationMode.Linear,
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(sprite.Rotation, 0),
new AnimationTrackProperty.KeyFrame(spriteComp.Rotation, 0),
new AnimationTrackProperty.KeyFrame(rotation, animationTime)
}
}
}
}, "rotate");
};
AnimationSystem.Play(animationComp, animation, animationKey);
}
}