]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Jittering System Fix + Cleanup (#20921)
authorPsychpsyo <60073468+Psychpsyo@users.noreply.github.com>
Wed, 11 Oct 2023 22:57:09 +0000 (00:57 +0200)
committerGitHub <noreply@github.com>
Wed, 11 Oct 2023 22:57:09 +0000 (15:57 -0700)
Content.Client/Jittering/JitteringSystem.cs
Content.Shared/Jittering/SharedJitteringSystem.cs

index 032eb3e18f2c525c2f09ac444e50ffcde62de53f..41f20634ab59c43228e618d4e4dd767ff1ca7924 100644 (file)
@@ -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;
 
index 327a45217520001518e3d73acbd76391c55e60ac..1ac8413375e60c7081aa705c0314a6a39a9d7000 100644 (file)
@@ -72,7 +72,7 @@ namespace Content.Shared.Jittering
             var jitter = EnsureComp<JitteringComponent>(uid);
             jitter.Amplitude = amplitude;
             jitter.Frequency = frequency;
-            Dirty(jitter);
+            Dirty(uid, jitter);
         }
     }
 }