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,4 +1,5 @@
using Content.Client.Buckle.Strap; using Content.Client.Buckle.Strap;
using Content.Client.Rotation;
using Content.Shared.ActionBlocker; using Content.Shared.ActionBlocker;
using Content.Shared.Buckle; using Content.Shared.Buckle;
using Content.Shared.Buckle.Components; using Content.Shared.Buckle.Components;
@@ -11,14 +12,16 @@ namespace Content.Client.Buckle
internal sealed class BuckleSystem : SharedBuckleSystem internal sealed class BuckleSystem : SharedBuckleSystem
{ {
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!; [Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
[Dependency] private readonly AppearanceSystem AppearanceSystem = default!;
[Dependency] private readonly RotationVisualizerSystem RotationVisualizerSystem = default!;
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<BuckleComponent, ComponentHandleState>(OnBuckleHandleState); SubscribeLocalEvent<BuckleComponent, ComponentHandleState>(OnBuckleHandleState);
SubscribeLocalEvent<StrapComponent, ComponentHandleState>(OnStrapHandleState); SubscribeLocalEvent<StrapComponent, ComponentHandleState>(OnStrapHandleState);
SubscribeLocalEvent<BuckleComponent, AppearanceChangeEvent>(OnAppearanceChange);
} }
private void OnBuckleHandleState(EntityUid uid, BuckleComponent buckle, ref ComponentHandleState args) private void OnBuckleHandleState(EntityUid uid, BuckleComponent buckle, ref ComponentHandleState args)
@@ -73,5 +76,19 @@ namespace Content.Client.Buckle
component.BuckledEntities.UnionWith(state.BuckledEntities); component.BuckledEntities.UnionWith(state.BuckledEntities);
component.MaxBuckleDistance = state.MaxBuckleDistance; component.MaxBuckleDistance = state.MaxBuckleDistance;
} }
private void OnAppearanceChange(EntityUid uid, BuckleComponent component, ref AppearanceChangeEvent args)
{
if (!AppearanceSystem.TryGetData<int>(uid, StrapVisuals.RotationAngle, out var angle, args.Component) ||
!AppearanceSystem.TryGetData<bool>(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);
}
} }
} }

View File

@@ -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<BuckleComponent>
{
protected override void OnAppearanceChange(EntityUid uid, BuckleComponent component, ref AppearanceChangeEvent args)
{
if (!args.Component.TryGetData<int>(StrapVisuals.RotationAngle, out var angle) ||
!args.Component.TryGetData<bool>(BuckleVisuals.Buckled, out var buckled) ||
!buckled ||
args.Sprite == null)
{
return;
}
EntityManager.System<RotationVisualizerSystem>()
.AnimateSpriteRotation(args.Sprite, Angle.FromDegrees(angle), 0.125f);
}
}

View File

@@ -1,6 +1,6 @@
using Robust.Client.GameObjects;
using Robust.Client.Animations;
using Content.Shared.Rotation; using Content.Shared.Rotation;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Shared.Animations; using Robust.Shared.Animations;
namespace Content.Client.Rotation; namespace Content.Client.Rotation;
@@ -11,10 +11,11 @@ public sealed class RotationVisualizerSystem : VisualizerSystem<RotationVisualsC
{ {
base.OnAppearanceChange(uid, component, ref args); 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. return;
args.Component.TryGetData<RotationState>(RotationVisuals.RotationState, out var state); }
switch (state) switch (state)
{ {
@@ -26,32 +27,27 @@ public sealed class RotationVisualizerSystem : VisualizerSystem<RotationVisualsC
break; break;
} }
} }
}
/// <summary> /// <summary>
/// Rotates a sprite between two animated keyframes given a certain time. /// Rotates a sprite between two animated keyframes given a certain time.
/// </summary> /// </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 (spriteComp.Rotation.Equals(rotation))
if (sprite.Rotation.Equals(rotation))
{ {
return; 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; AnimationSystem.Stop(animationComp, animationKey);
return;
} }
spriteComp.Rotation = rotation;
if (animation.HasRunningAnimation("rotate")) var animation = new Animation
{
animation.Stop("rotate");
}
animation.Play(new Animation
{ {
Length = TimeSpan.FromSeconds(animationTime), Length = TimeSpan.FromSeconds(animationTime),
AnimationTracks = AnimationTracks =
@@ -63,11 +59,13 @@ public sealed class RotationVisualizerSystem : VisualizerSystem<RotationVisualsC
InterpolationMode = AnimationInterpolationMode.Linear, InterpolationMode = AnimationInterpolationMode.Linear,
KeyFrames = KeyFrames =
{ {
new AnimationTrackProperty.KeyFrame(sprite.Rotation, 0), new AnimationTrackProperty.KeyFrame(spriteComp.Rotation, 0),
new AnimationTrackProperty.KeyFrame(rotation, animationTime) new AnimationTrackProperty.KeyFrame(rotation, animationTime)
} }
} }
} }
}, "rotate"); };
AnimationSystem.Play(animationComp, animation, animationKey);
} }
} }