-using System;
-using System.Collections.Immutable;
using System.Numerics;
using Content.Shared.Jittering;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
-using Robust.Shared.Animations;
-using Robust.Shared.GameObjects;
-using Robust.Shared.IoC;
-using Robust.Shared.Maths;
using Robust.Shared.Random;
namespace Content.Client.Jittering
public sealed class JitteringSystem : SharedJitteringSystem
{
[Dependency] private readonly IRobustRandom _random = default!;
+ [Dependency] private readonly AnimationPlayerSystem _animationPlayer = default!;
private readonly float[] _sign = { -1, 1 };
private readonly string _jitterAnimationKey = "jittering";
var animationPlayer = EntityManager.EnsureComponent<AnimationPlayerComponent>(uid);
- animationPlayer.Play(GetAnimation(jittering, sprite), _jitterAnimationKey);
+ _animationPlayer.Play(animationPlayer, GetAnimation(jittering, sprite), _jitterAnimationKey);
}
private void OnShutdown(EntityUid uid, JitteringComponent jittering, ComponentShutdown args)
{
if (EntityManager.TryGetComponent(uid, out AnimationPlayerComponent? animationPlayer))
- animationPlayer.Stop(_jitterAnimationKey);
+ _animationPlayer.Stop(animationPlayer, _jitterAnimationKey);
if (EntityManager.TryGetComponent(uid, out SpriteComponent? sprite))
sprite.Offset = Vector2.Zero;
if(args.Key != _jitterAnimationKey)
return;
- if(EntityManager.TryGetComponent(uid, out AnimationPlayerComponent? animationPlayer)
+ if (EntityManager.TryGetComponent(uid, out AnimationPlayerComponent? animationPlayer)
&& EntityManager.TryGetComponent(uid, out SpriteComponent? sprite))
- animationPlayer.Play(GetAnimation(jittering, sprite), _jitterAnimationKey);
+ _animationPlayer.Play(animationPlayer, GetAnimation(jittering, sprite), _jitterAnimationKey);
}
private Animation GetAnimation(JitteringComponent jittering, SpriteComponent sprite)
offset.Y *= -1;
}
- // Animation length shouldn't be too high so we will cap it at 2 seconds...
- var length = Math.Min((1f/jittering.Frequency), 2f);
+ var length = 0f;
+ // avoid dividing by 0 so animations don't try to be infinitely long
+ if (jittering.Frequency > 0)
+ length = 1f / jittering.Frequency;
jittering.LastJitter = offset;