]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Remove obsolete usages of AnimationPlayerComponent (#20806)
authorDrSmugleaf <DrSmugleaf@users.noreply.github.com>
Sat, 14 Oct 2023 17:28:06 +0000 (10:28 -0700)
committerGitHub <noreply@github.com>
Sat, 14 Oct 2023 17:28:06 +0000 (10:28 -0700)
Content.Client/Animations/EntityPickupAnimationComponent.cs [new file with mode: 0644]
Content.Client/Animations/EntityPickupAnimationSystem.cs [new file with mode: 0644]
Content.Client/Animations/ReusableAnimations.cs [deleted file]
Content.Client/Jittering/JitteringSystem.cs
Content.Client/Light/Components/LightBehaviourComponent.cs
Content.Client/Light/EntitySystems/RotatingLightSystem.cs
Content.Client/Orbit/OrbitVisualsSystem.cs
Content.Client/Storage/Systems/StorageSystem.cs

diff --git a/Content.Client/Animations/EntityPickupAnimationComponent.cs b/Content.Client/Animations/EntityPickupAnimationComponent.cs
new file mode 100644 (file)
index 0000000..663ce62
--- /dev/null
@@ -0,0 +1,11 @@
+namespace Content.Client.Animations;
+
+/// <summary>
+///     Applied to client-side clone entities to animate them approaching the player that
+///     picked up the original entity.
+/// </summary>
+[RegisterComponent]
+[Access(typeof(EntityPickupAnimationSystem))]
+public sealed partial class EntityPickupAnimationComponent : Component
+{
+}
diff --git a/Content.Client/Animations/EntityPickupAnimationSystem.cs b/Content.Client/Animations/EntityPickupAnimationSystem.cs
new file mode 100644 (file)
index 0000000..2ac51e6
--- /dev/null
@@ -0,0 +1,87 @@
+using System.Numerics;
+using Robust.Client.Animations;
+using Robust.Client.GameObjects;
+using Robust.Shared.Animations;
+using Robust.Shared.Map;
+using Robust.Shared.Spawners;
+using static Robust.Client.Animations.AnimationTrackProperty;
+
+namespace Content.Client.Animations;
+
+/// <summary>
+///     System that handles animating an entity that a player has picked up.
+/// </summary>
+public sealed class EntityPickupAnimationSystem : EntitySystem
+{
+    [Dependency] private readonly AnimationPlayerSystem _animations = default!;
+    [Dependency] private readonly MetaDataSystem _metaData = default!;
+    [Dependency] private readonly TransformSystem _transform = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<EntityPickupAnimationComponent, AnimationCompletedEvent>(OnEntityPickupAnimationCompleted);
+    }
+
+    private void OnEntityPickupAnimationCompleted(EntityUid uid, EntityPickupAnimationComponent component, AnimationCompletedEvent args)
+    {
+        Del(uid);
+    }
+
+    /// <summary>
+    ///     Animates a clone of an entity moving from one point to another before
+    ///     being deleted.
+    ///     Used when the player picks up an entity.
+    /// </summary>
+    public void AnimateEntityPickup(EntityUid uid, EntityCoordinates initial, Vector2 final, Angle initialAngle)
+    {
+        if (Deleted(uid) || !initial.IsValid(EntityManager))
+            return;
+
+        var metadata = MetaData(uid);
+
+        if (IsPaused(uid, metadata))
+            return;
+
+        var animatableClone = Spawn("clientsideclone", initial);
+        EnsureComp<EntityPickupAnimationComponent>(animatableClone);
+        var val = metadata.EntityName;
+        _metaData.SetEntityName(animatableClone, val);
+
+        if (!TryComp(uid, out SpriteComponent? sprite0))
+        {
+            Log.Error("Entity ({0}) couldn't be animated for pickup since it doesn't have a {1}!", metadata.EntityName, nameof(SpriteComponent));
+            return;
+        }
+
+        var sprite = Comp<SpriteComponent>(animatableClone);
+        sprite.CopyFrom(sprite0);
+        sprite.Visible = true;
+
+        var animations = Comp<AnimationPlayerComponent>(animatableClone);
+
+        var despawn = EnsureComp<TimedDespawnComponent>(animatableClone);
+        despawn.Lifetime = 0.25f;
+        _transform.SetLocalRotationNoLerp(animatableClone, initialAngle);
+
+        _animations.Play(animatableClone, animations, new Animation
+        {
+            Length = TimeSpan.FromMilliseconds(125),
+            AnimationTracks =
+            {
+                new AnimationTrackComponentProperty
+                {
+                    ComponentType = typeof(TransformComponent),
+                    Property = nameof(TransformComponent.LocalPosition),
+                    InterpolationMode = AnimationInterpolationMode.Linear,
+                    KeyFrames =
+                    {
+                        new KeyFrame(initial.Position, 0),
+                        new KeyFrame(final, 0.125f)
+                    }
+                },
+            }
+        }, "fancy_pickup_anim");
+    }
+}
diff --git a/Content.Client/Animations/ReusableAnimations.cs b/Content.Client/Animations/ReusableAnimations.cs
deleted file mode 100644 (file)
index 33e3eb2..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-using System.Numerics;
-using Robust.Shared.Spawners;
-using Robust.Client.Animations;
-using Robust.Client.GameObjects;
-using Robust.Shared.Animations;
-using Robust.Shared.Map;
-using TimedDespawnComponent = Robust.Shared.Spawners.TimedDespawnComponent;
-
-namespace Content.Client.Animations
-{
-    public static class ReusableAnimations
-    {
-        public static void AnimateEntityPickup(EntityUid entity, EntityCoordinates initialCoords, Vector2 finalPosition, Angle initialAngle, IEntityManager? entMan = null)
-        {
-            IoCManager.Resolve(ref entMan);
-
-            if (entMan.Deleted(entity) || !initialCoords.IsValid(entMan))
-                return;
-
-            var metadata = entMan.GetComponent<MetaDataComponent>(entity);
-
-            if (entMan.IsPaused(entity, metadata))
-                return;
-
-            var animatableClone = entMan.SpawnEntity("clientsideclone", initialCoords);
-            string val = entMan.GetComponent<MetaDataComponent>(entity).EntityName;
-            entMan.System<MetaDataSystem>().SetEntityName(animatableClone, val);
-
-            if (!entMan.TryGetComponent(entity, out SpriteComponent? sprite0))
-            {
-                Logger.Error("Entity ({0}) couldn't be animated for pickup since it doesn't have a {1}!", entMan.GetComponent<MetaDataComponent>(entity).EntityName, nameof(SpriteComponent));
-                return;
-            }
-            var sprite = entMan.GetComponent<SpriteComponent>(animatableClone);
-            sprite.CopyFrom(sprite0);
-            sprite.Visible = true;
-
-            var animations = entMan.GetComponent<AnimationPlayerComponent>(animatableClone);
-            animations.AnimationCompleted += (_) =>
-            {
-                entMan.DeleteEntity(animatableClone);
-            };
-
-            var despawn = entMan.EnsureComponent<TimedDespawnComponent>(animatableClone);
-            despawn.Lifetime = 0.25f;
-            entMan.System<SharedTransformSystem>().SetLocalRotationNoLerp(animatableClone, initialAngle);
-
-            animations.Play(new Animation
-            {
-                Length = TimeSpan.FromMilliseconds(125),
-                AnimationTracks =
-                {
-                    new AnimationTrackComponentProperty
-                    {
-                        ComponentType = typeof(TransformComponent),
-                        Property = nameof(TransformComponent.LocalPosition),
-                        InterpolationMode = AnimationInterpolationMode.Linear,
-                        KeyFrames =
-                        {
-                            new AnimationTrackProperty.KeyFrame(initialCoords.Position, 0),
-                            new AnimationTrackProperty.KeyFrame(finalPosition, 0.125f)
-                        }
-                    },
-                }
-            }, "fancy_pickup_anim");
-        }
-    }
-}
index 41f20634ab59c43228e618d4e4dd767ff1ca7924..079fd60a46d260a75151a9af1cada668afa86c2c 100644 (file)
@@ -25,20 +25,20 @@ namespace Content.Client.Jittering
 
         private void OnStartup(EntityUid uid, JitteringComponent jittering, ComponentStartup args)
         {
-            if (!EntityManager.TryGetComponent(uid, out SpriteComponent? sprite))
+            if (!TryComp(uid, out SpriteComponent? sprite))
                 return;
 
-            var animationPlayer = EntityManager.EnsureComponent<AnimationPlayerComponent>(uid);
+            var animationPlayer = EnsureComp<AnimationPlayerComponent>(uid);
 
-            _animationPlayer.Play(animationPlayer, GetAnimation(jittering, sprite), _jitterAnimationKey);
+            _animationPlayer.Play(uid, animationPlayer, GetAnimation(jittering, sprite), _jitterAnimationKey);
         }
 
         private void OnShutdown(EntityUid uid, JitteringComponent jittering, ComponentShutdown args)
         {
-            if (EntityManager.TryGetComponent(uid, out AnimationPlayerComponent? animationPlayer))
-                _animationPlayer.Stop(animationPlayer, _jitterAnimationKey);
+            if (TryComp(uid, out AnimationPlayerComponent? animationPlayer))
+                _animationPlayer.Stop(uid, animationPlayer, _jitterAnimationKey);
 
-            if (EntityManager.TryGetComponent(uid, out SpriteComponent? sprite))
+            if (TryComp(uid, out SpriteComponent? sprite))
                 sprite.Offset = Vector2.Zero;
         }
 
@@ -47,9 +47,9 @@ namespace Content.Client.Jittering
             if(args.Key != _jitterAnimationKey)
                 return;
 
-            if (EntityManager.TryGetComponent(uid, out AnimationPlayerComponent? animationPlayer)
-            && EntityManager.TryGetComponent(uid, out SpriteComponent? sprite))
-                _animationPlayer.Play(animationPlayer, GetAnimation(jittering, sprite), _jitterAnimationKey);
+            if (TryComp(uid, out AnimationPlayerComponent? animationPlayer)
+                && TryComp(uid, out SpriteComponent? sprite))
+                _animationPlayer.Play(uid, animationPlayer, GetAnimation(jittering, sprite), _jitterAnimationKey);
         }
 
         private Animation GetAnimation(JitteringComponent jittering, SpriteComponent sprite)
index b594411c352dab73358ec4c5d4bcd464bb03a869..282df5c8294b4aa2a09783f81336c97e2b6ed15d 100644 (file)
@@ -431,20 +431,23 @@ namespace Content.Client.Light.Components
         /// </summary>
         public void StartLightBehaviour(string id = "")
         {
-            if (!_entMan.TryGetComponent(Owner, out AnimationPlayerComponent? animation))
+            var uid = Owner;
+            if (!_entMan.TryGetComponent(uid, out AnimationPlayerComponent? animation))
             {
                 return;
             }
 
+            var animations = _entMan.System<AnimationPlayerSystem>();
+
             foreach (var container in Animations)
             {
                 if (container.LightBehaviour.ID == id || id == string.Empty)
                 {
-                    if (!animation.HasRunningAnimation(KeyPrefix + container.Key))
+                    if (!animations.HasRunningAnimation(uid, animation, KeyPrefix + container.Key))
                     {
                         CopyLightSettings(container.LightBehaviour.Property);
                         container.LightBehaviour.UpdatePlaybackValues(container.Animation);
-                        animation.Play(container.Animation, KeyPrefix + container.Key);
+                        animations.Play(uid, animation, container.Animation, KeyPrefix + container.Key);
                     }
                 }
             }
@@ -460,20 +463,22 @@ namespace Content.Client.Light.Components
         /// <param name="resetToOriginalSettings">Should the light have its original settings applied?</param>
         public void StopLightBehaviour(string id = "", bool removeBehaviour = false, bool resetToOriginalSettings = false)
         {
-            if (!_entMan.TryGetComponent(Owner, out AnimationPlayerComponent? animation))
+            var uid = Owner;
+            if (!_entMan.TryGetComponent(uid, out AnimationPlayerComponent? animation))
             {
                 return;
             }
 
             var toRemove = new List<AnimationContainer>();
+            var animations = _entMan.System<AnimationPlayerSystem>();
 
             foreach (var container in Animations)
             {
                 if (container.LightBehaviour.ID == id || id == string.Empty)
                 {
-                    if (animation.HasRunningAnimation(KeyPrefix + container.Key))
+                    if (animations.HasRunningAnimation(uid, animation, KeyPrefix + container.Key))
                     {
-                        animation.Stop(KeyPrefix + container.Key);
+                        animations.Stop(uid, animation, KeyPrefix + container.Key);
                     }
 
                     if (removeBehaviour)
@@ -488,7 +493,7 @@ namespace Content.Client.Light.Components
                 Animations.Remove(container);
             }
 
-            if (resetToOriginalSettings && _entMan.TryGetComponent(Owner, out PointLightComponent? light))
+            if (resetToOriginalSettings && _entMan.TryGetComponent(uid, out PointLightComponent? light))
             {
                 foreach (var (property, value) in _originalPropertyValues)
                 {
@@ -505,12 +510,14 @@ namespace Content.Client.Light.Components
         /// <returns>Whether at least one behaviour is running, false if none is.</returns>
         public bool HasRunningBehaviours()
         {
-            if (!_entMan.TryGetComponent(Owner, out AnimationPlayerComponent? animation))
+            var uid = Owner;
+            if (!_entMan.TryGetComponent(uid, out AnimationPlayerComponent? animation))
             {
                 return false;
             }
 
-            return Animations.Any(container => animation.HasRunningAnimation(KeyPrefix + container.Key));
+            var animations = _entMan.System<AnimationPlayerSystem>();
+            return Animations.Any(container => animations.HasRunningAnimation(uid, animation, KeyPrefix + container.Key));
         }
 
         /// <summary>
index dc70fb6312744e2b79f71d648ddabbc09e1c2132..842c13dedfe933014a181342c7fc260fb3a60255 100644 (file)
@@ -3,14 +3,13 @@ using Content.Shared.Light.Components;
 using Robust.Client.Animations;
 using Robust.Client.GameObjects;
 using Robust.Shared.Animations;
-using Robust.Shared.GameObjects;
-using Robust.Shared.GameStates;
-using Robust.Shared.Maths;
 
-namespace Content.Client.Light.Systems;
+namespace Content.Client.Light.EntitySystems;
 
 public sealed class RotatingLightSystem : SharedRotatingLightSystem
 {
+    [Dependency] private readonly AnimationPlayerSystem _animations = default!;
+
     private Animation GetAnimation(float speed)
     {
         var third = 120f / speed;
@@ -64,7 +63,7 @@ public sealed class RotatingLightSystem : SharedRotatingLightSystem
         }
         else
         {
-            player.Stop(AnimKey);
+            _animations.Stop(uid, player, AnimKey);
         }
     }
 
@@ -81,9 +80,9 @@ public sealed class RotatingLightSystem : SharedRotatingLightSystem
         if (!Resolve(uid, ref comp, ref player) || !comp.Enabled)
             return;
 
-        if (!player.HasRunningAnimation(AnimKey))
+        if (!_animations.HasRunningAnimation(uid, player, AnimKey))
         {
-            player.Play(GetAnimation(comp.Speed), AnimKey);
+            _animations.Play(uid, player, GetAnimation(comp.Speed), AnimKey);
         }
     }
 }
index 74dcdc7d2f524eee98adab0f9d2b33c1ff103334..1799e8ecc897a294dad8fb778e03f379c96722c5 100644 (file)
@@ -1,5 +1,4 @@
 using System.Numerics;
-using Content.Shared.Follower;
 using Content.Shared.Follower.Components;
 using Robust.Client.Animations;
 using Robust.Client.GameObjects;
@@ -11,6 +10,7 @@ namespace Content.Client.Orbit;
 public sealed class OrbitVisualsSystem : EntitySystem
 {
     [Dependency] private readonly IRobustRandom _robustRandom = default!;
+    [Dependency] private readonly AnimationPlayerSystem _animations = default!;
 
     private readonly string _orbitAnimationKey = "orbiting";
     private readonly string _orbitStopKey = "orbiting_stop";
@@ -37,16 +37,16 @@ public sealed class OrbitVisualsSystem : EntitySystem
             sprite.DirectionOverride = Direction.South;
         }
 
-        var animationPlayer = EntityManager.EnsureComponent<AnimationPlayerComponent>(uid);
-        if (animationPlayer.HasRunningAnimation(_orbitAnimationKey))
+        var animationPlayer = EnsureComp<AnimationPlayerComponent>(uid);
+        if (_animations.HasRunningAnimation(uid, animationPlayer, _orbitAnimationKey))
             return;
 
-        if (animationPlayer.HasRunningAnimation(_orbitStopKey))
+        if (_animations.HasRunningAnimation(uid, animationPlayer, _orbitStopKey))
         {
-            animationPlayer.Stop(_orbitStopKey);
+            _animations.Stop(uid, animationPlayer, _orbitStopKey);
         }
 
-        animationPlayer.Play(GetOrbitAnimation(component), _orbitAnimationKey);
+        _animations.Play(uid, animationPlayer, GetOrbitAnimation(component), _orbitAnimationKey);
     }
 
     private void OnComponentRemove(EntityUid uid, OrbitVisualsComponent component, ComponentRemove args)
@@ -56,15 +56,15 @@ public sealed class OrbitVisualsSystem : EntitySystem
 
         sprite.EnableDirectionOverride = false;
 
-        var animationPlayer = EntityManager.EnsureComponent<AnimationPlayerComponent>(uid);
-        if (animationPlayer.HasRunningAnimation(_orbitAnimationKey))
+        var animationPlayer = EnsureComp<AnimationPlayerComponent>(uid);
+        if (_animations.HasRunningAnimation(uid, animationPlayer, _orbitAnimationKey))
         {
-            animationPlayer.Stop(_orbitAnimationKey);
+            _animations.Stop(uid, animationPlayer, _orbitAnimationKey);
         }
 
-        if (!animationPlayer.HasRunningAnimation(_orbitStopKey))
+        if (!_animations.HasRunningAnimation(uid, animationPlayer, _orbitStopKey))
         {
-            animationPlayer.Play(GetStopAnimation(component, sprite), _orbitStopKey);
+            _animations.Play(uid, animationPlayer, GetStopAnimation(component, sprite), _orbitStopKey);
         }
     }
 
@@ -84,10 +84,9 @@ public sealed class OrbitVisualsSystem : EntitySystem
 
     private void OnAnimationCompleted(EntityUid uid, OrbitVisualsComponent component, AnimationCompletedEvent args)
     {
-        if (args.Key == _orbitAnimationKey)
+        if (args.Key == _orbitAnimationKey && TryComp(uid, out AnimationPlayerComponent? animationPlayer))
         {
-            if(EntityManager.TryGetComponent(uid, out AnimationPlayerComponent? animationPlayer))
-                animationPlayer.Play(GetOrbitAnimation(component), _orbitAnimationKey);
+            _animations.Play(uid, animationPlayer, GetOrbitAnimation(component), _orbitAnimationKey);
         }
     }
 
index 7391e11b3160b55a65a78b72a962be0cfb648c60..5b55c3c8d57ab6714754aa67fa413335bc37988c 100644 (file)
@@ -11,6 +11,7 @@ namespace Content.Client.Storage.Systems;
 public sealed class StorageSystem : SharedStorageSystem
 {
     [Dependency] private readonly IGameTiming _timing = default!;
+    [Dependency] private readonly EntityPickupAnimationSystem _entityPickupAnimation = default!;
 
     public event Action<EntityUid, StorageComponent>? StorageUpdated;
 
@@ -57,7 +58,7 @@ public sealed class StorageSystem : SharedStorageSystem
         var finalMapPos = finalCoords.ToMapPos(EntityManager, _transform);
         var finalPos = _transform.GetInvWorldMatrix(initialCoords.EntityId).Transform(finalMapPos);
 
-        ReusableAnimations.AnimateEntityPickup(item, initialCoords, finalPos, initialAngle);
+        _entityPickupAnimation.AnimateEntityPickup(item, initialCoords, finalPos, initialAngle);
     }
 
     /// <summary>
@@ -75,7 +76,7 @@ public sealed class StorageSystem : SharedStorageSystem
             var initialPosition = msg.EntityPositions[i];
             if (EntityManager.EntityExists(entity) && transformComp != null)
             {
-                ReusableAnimations.AnimateEntityPickup(entity, GetCoordinates(initialPosition), transformComp.LocalPosition, msg.EntityAngles[i], EntityManager);
+                _entityPickupAnimation.AnimateEntityPickup(entity, GetCoordinates(initialPosition), transformComp.LocalPosition, msg.EntityAngles[i]);
             }
         }
     }