2024-06-05 14:31:21 +00:00
|
|
|
using Content.Shared._White.Animations;
|
|
|
|
|
using Robust.Client.Animations;
|
|
|
|
|
using Robust.Client.GameObjects;
|
|
|
|
|
using Robust.Shared.Animations;
|
|
|
|
|
using Robust.Shared.Timing;
|
|
|
|
|
|
|
|
|
|
namespace Content.Client._White.Animations;
|
|
|
|
|
|
2024-06-06 10:22:49 +00:00
|
|
|
public sealed class FlipOnHitSystem : SharedFlipOnHitSystem
|
2024-06-05 14:31:21 +00:00
|
|
|
{
|
|
|
|
|
[Dependency] private readonly AnimationPlayerSystem _animationSystem = default!;
|
|
|
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<FlippingComponent, AnimationCompletedEvent>(OnAnimationComplete);
|
2024-06-06 10:22:49 +00:00
|
|
|
SubscribeAllEvent<FlipOnHitEvent>(ev => PlayAnimation(GetEntity(ev.User)));
|
2024-06-05 14:31:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnAnimationComplete(Entity<FlippingComponent> ent, ref AnimationCompletedEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Key != EmoteAnimationSystem.AnimationKey)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
PlayAnimation(ent);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-06 10:22:49 +00:00
|
|
|
protected override void PlayAnimation(EntityUid user)
|
2024-06-05 14:31:21 +00:00
|
|
|
{
|
|
|
|
|
if (!_timing.IsFirstTimePredicted)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-06-26 11:56:29 +00:00
|
|
|
if (TerminatingOrDeleted(user))
|
|
|
|
|
return;
|
|
|
|
|
|
2024-06-06 10:22:49 +00:00
|
|
|
if (_animationSystem.HasRunningAnimation(user, EmoteAnimationSystem.AnimationKey))
|
2024-06-05 14:31:21 +00:00
|
|
|
{
|
2024-06-06 10:22:49 +00:00
|
|
|
EnsureComp<FlippingComponent>(user);
|
2024-06-05 14:31:21 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RemComp<FlippingComponent>(user);
|
|
|
|
|
|
|
|
|
|
var baseAngle = Angle.Zero;
|
|
|
|
|
if (EntityManager.TryGetComponent(user, out SpriteComponent? sprite))
|
|
|
|
|
baseAngle = sprite.Rotation;
|
|
|
|
|
|
|
|
|
|
var degrees = baseAngle.Degrees;
|
|
|
|
|
|
|
|
|
|
var animation = new Animation
|
|
|
|
|
{
|
|
|
|
|
Length = TimeSpan.FromMilliseconds(1600),
|
|
|
|
|
AnimationTracks =
|
|
|
|
|
{
|
|
|
|
|
new AnimationTrackComponentProperty
|
|
|
|
|
{
|
|
|
|
|
ComponentType = typeof(SpriteComponent),
|
|
|
|
|
Property = nameof(SpriteComponent.Rotation),
|
|
|
|
|
InterpolationMode = AnimationInterpolationMode.Linear,
|
|
|
|
|
KeyFrames =
|
|
|
|
|
{
|
|
|
|
|
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(degrees - 10), 0f),
|
|
|
|
|
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(degrees + 180), 0.2f),
|
|
|
|
|
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(degrees + 360), 0.2f),
|
|
|
|
|
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(degrees + 540), 0.2f),
|
|
|
|
|
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(degrees + 720), 0.2f),
|
|
|
|
|
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(degrees + 900), 0.2f),
|
|
|
|
|
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(degrees + 1080), 0.2f),
|
|
|
|
|
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(degrees + 1260), 0.2f),
|
|
|
|
|
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(degrees + 1440), 0.2f),
|
|
|
|
|
new AnimationTrackProperty.KeyFrame(Angle.FromDegrees(degrees), 0f)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_animationSystem.Play(user, animation, EmoteAnimationSystem.AnimationKey);
|
|
|
|
|
}
|
|
|
|
|
}
|