Jittering System Fix + Cleanup (#20921)
This commit is contained in:
@@ -1,13 +1,7 @@
|
||||
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
|
||||
@@ -15,6 +9,7 @@ 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";
|
||||
@@ -35,13 +30,13 @@ namespace Content.Client.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;
|
||||
@@ -52,9 +47,9 @@ namespace Content.Client.Jittering
|
||||
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)
|
||||
@@ -77,8 +72,10 @@ namespace Content.Client.Jittering
|
||||
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;
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace Content.Shared.Jittering
|
||||
var jitter = EnsureComp<JitteringComponent>(uid);
|
||||
jitter.Amplitude = amplitude;
|
||||
jitter.Frequency = frequency;
|
||||
Dirty(jitter);
|
||||
Dirty(uid, jitter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user