Remove obsolete usages of AnimationPlayerComponent (#20806)

This commit is contained in:
DrSmugleaf
2023-10-14 10:28:06 -07:00
committed by GitHub
parent 49a584f12c
commit 9e1ecdea76
8 changed files with 145 additions and 109 deletions

View File

@@ -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
{
}

View File

@@ -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");
}
}

View File

@@ -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");
}
}
}

View 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)

View 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>

View 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);
}
}
}

View 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);
}
}

View 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]);
}
}
}