Files
crystall-punk-14/Content.Client/Animations/ReusableAnimations.cs

68 lines
2.7 KiB
C#
Raw Normal View History

using System.Numerics;
2023-07-18 21:44:00 +10:00
using Content.Shared.Spawners.Components;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Shared.Animations;
using Robust.Shared.Map;
namespace Content.Client.Animations
{
public static class ReusableAnimations
{
2023-09-12 22:34:04 +10:00
public static void AnimateEntityPickup(EntityUid entity, EntityCoordinates initialCoords, Vector2 finalPosition, Angle initialAngle, IEntityManager? entMan = null)
{
2021-12-08 11:37:10 +01:00
IoCManager.Resolve(ref entMan);
2021-12-11 15:29:16 +01:00
2023-09-12 22:34:04 +10:00
if (entMan.Deleted(entity) || !initialCoords.IsValid(entMan))
return;
var metadata = entMan.GetComponent<MetaDataComponent>(entity);
if (entMan.IsPaused(entity, metadata))
2021-12-11 15:29:16 +01:00
return;
2023-09-12 22:34:04 +10:00
var animatableClone = entMan.SpawnEntity("clientsideclone", initialCoords);
2021-12-08 11:37:10 +01:00
string val = entMan.GetComponent<MetaDataComponent>(entity).EntityName;
entMan.System<MetaDataSystem>().SetEntityName(animatableClone, val);
2021-12-08 11:37:10 +01:00
if (!entMan.TryGetComponent(entity, out SpriteComponent? sprite0))
{
2021-12-08 11:37:10 +01:00
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;
}
2021-12-08 11:37:10 +01:00
var sprite = entMan.GetComponent<SpriteComponent>(animatableClone);
sprite.CopyFrom(sprite0);
sprite.Visible = true;
2021-12-08 11:37:10 +01:00
var animations = entMan.GetComponent<AnimationPlayerComponent>(animatableClone);
2023-09-12 22:34:04 +10:00
animations.AnimationCompleted += (_) =>
{
2021-12-08 11:37:10 +01:00
entMan.DeleteEntity(animatableClone);
};
2023-07-18 21:44:00 +10:00
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 =
{
2023-09-12 22:34:04 +10:00
new AnimationTrackProperty.KeyFrame(initialCoords.Position, 0),
new AnimationTrackProperty.KeyFrame(finalPosition, 0.125f)
}
2023-07-18 21:44:00 +10:00
},
}
}, "fancy_pickup_anim");
}
}
}