diff --git a/Content.Client/Animations/EntityPickupAnimationComponent.cs b/Content.Client/Animations/EntityPickupAnimationComponent.cs
new file mode 100644
index 0000000000..663ce628f6
--- /dev/null
+++ b/Content.Client/Animations/EntityPickupAnimationComponent.cs
@@ -0,0 +1,11 @@
+namespace Content.Client.Animations;
+
+///
+/// Applied to client-side clone entities to animate them approaching the player that
+/// picked up the original entity.
+///
+[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
index 0000000000..2ac51e6eba
--- /dev/null
+++ b/Content.Client/Animations/EntityPickupAnimationSystem.cs
@@ -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;
+
+///
+/// System that handles animating an entity that a player has picked up.
+///
+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(OnEntityPickupAnimationCompleted);
+ }
+
+ private void OnEntityPickupAnimationCompleted(EntityUid uid, EntityPickupAnimationComponent component, AnimationCompletedEvent args)
+ {
+ Del(uid);
+ }
+
+ ///
+ /// Animates a clone of an entity moving from one point to another before
+ /// being deleted.
+ /// Used when the player picks up an entity.
+ ///
+ 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(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(animatableClone);
+ sprite.CopyFrom(sprite0);
+ sprite.Visible = true;
+
+ var animations = Comp(animatableClone);
+
+ var despawn = EnsureComp(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
index 33e3eb25b4..0000000000
--- a/Content.Client/Animations/ReusableAnimations.cs
+++ /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(entity);
-
- if (entMan.IsPaused(entity, metadata))
- return;
-
- var animatableClone = entMan.SpawnEntity("clientsideclone", initialCoords);
- string val = entMan.GetComponent(entity).EntityName;
- entMan.System().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(entity).EntityName, nameof(SpriteComponent));
- return;
- }
- var sprite = entMan.GetComponent(animatableClone);
- sprite.CopyFrom(sprite0);
- sprite.Visible = true;
-
- var animations = entMan.GetComponent(animatableClone);
- animations.AnimationCompleted += (_) =>
- {
- entMan.DeleteEntity(animatableClone);
- };
-
- var despawn = entMan.EnsureComponent(animatableClone);
- despawn.Lifetime = 0.25f;
- entMan.System().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");
- }
- }
-}
diff --git a/Content.Client/Jittering/JitteringSystem.cs b/Content.Client/Jittering/JitteringSystem.cs
index 41f20634ab..079fd60a46 100644
--- a/Content.Client/Jittering/JitteringSystem.cs
+++ b/Content.Client/Jittering/JitteringSystem.cs
@@ -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(uid);
+ var animationPlayer = EnsureComp(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)
diff --git a/Content.Client/Light/Components/LightBehaviourComponent.cs b/Content.Client/Light/Components/LightBehaviourComponent.cs
index b594411c35..282df5c829 100644
--- a/Content.Client/Light/Components/LightBehaviourComponent.cs
+++ b/Content.Client/Light/Components/LightBehaviourComponent.cs
@@ -431,20 +431,23 @@ namespace Content.Client.Light.Components
///
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();
+
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
/// Should the light have its original settings applied?
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();
+ var animations = _entMan.System();
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
/// Whether at least one behaviour is running, false if none is.
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();
+ return Animations.Any(container => animations.HasRunningAnimation(uid, animation, KeyPrefix + container.Key));
}
///
diff --git a/Content.Client/Light/EntitySystems/RotatingLightSystem.cs b/Content.Client/Light/EntitySystems/RotatingLightSystem.cs
index dc70fb6312..842c13dedf 100644
--- a/Content.Client/Light/EntitySystems/RotatingLightSystem.cs
+++ b/Content.Client/Light/EntitySystems/RotatingLightSystem.cs
@@ -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);
}
}
}
diff --git a/Content.Client/Orbit/OrbitVisualsSystem.cs b/Content.Client/Orbit/OrbitVisualsSystem.cs
index 74dcdc7d2f..1799e8ecc8 100644
--- a/Content.Client/Orbit/OrbitVisualsSystem.cs
+++ b/Content.Client/Orbit/OrbitVisualsSystem.cs
@@ -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(uid);
- if (animationPlayer.HasRunningAnimation(_orbitAnimationKey))
+ var animationPlayer = EnsureComp(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(uid);
- if (animationPlayer.HasRunningAnimation(_orbitAnimationKey))
+ var animationPlayer = EnsureComp(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);
}
}
diff --git a/Content.Client/Storage/Systems/StorageSystem.cs b/Content.Client/Storage/Systems/StorageSystem.cs
index 7391e11b31..5b55c3c8d5 100644
--- a/Content.Client/Storage/Systems/StorageSystem.cs
+++ b/Content.Client/Storage/Systems/StorageSystem.cs
@@ -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? 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);
}
///
@@ -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]);
}
}
}