Janitor trashbag upgrade + FANCY ANIMATIONS (#3058)
* Janitor trashbag upgrade + FANCY ANIMATIONS * Review, Bug fixes and Sounds - Fixed hand-pickup animation playing if the entity originated from inside a container (e.g. bag on the ground) or from inside ourselves (e.g. something in our own inventory) * Fix/Change. Just log if AnimateEntityPickup is called with an entity that has no SpriteComponent. * More explicit log message. Error log. * Merge. Fix.
This commit is contained in:
56
Content.Client/Animations/ReusableAnimations.cs
Normal file
56
Content.Client/Animations/ReusableAnimations.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using Robust.Client.Animations;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.GameObjects.Components.Animations;
|
||||
using Robust.Shared.Animations;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using System;
|
||||
|
||||
namespace Content.Client.Animations
|
||||
{
|
||||
public static class ReusableAnimations
|
||||
{
|
||||
|
||||
public static void AnimateEntityPickup(IEntity entity, EntityCoordinates initialPosition, Vector2 finalPosition)
|
||||
{
|
||||
var animatableClone = entity.EntityManager.SpawnEntity("clientsideclone", initialPosition);
|
||||
animatableClone.Name = entity.Name;
|
||||
|
||||
if(!entity.TryGetComponent(out SpriteComponent sprite0))
|
||||
{
|
||||
Logger.Error($"Entity ({0}) couldn't be animated for pickup since it doesn't have a {1}!", entity.Name, nameof(SpriteComponent));
|
||||
return;
|
||||
}
|
||||
var sprite = animatableClone.GetComponent<SpriteComponent>();
|
||||
sprite.CopyFrom(sprite0);
|
||||
|
||||
var animations = animatableClone.GetComponent<AnimationPlayerComponent>();
|
||||
animations.AnimationCompleted += (s) => {
|
||||
animatableClone.Delete();
|
||||
};
|
||||
|
||||
animations.Play(new Animation
|
||||
{
|
||||
Length = TimeSpan.FromMilliseconds(125),
|
||||
AnimationTracks =
|
||||
{
|
||||
new AnimationTrackComponentProperty
|
||||
{
|
||||
ComponentType = typeof(ITransformComponent),
|
||||
Property = nameof(ITransformComponent.WorldPosition),
|
||||
InterpolationMode = AnimationInterpolationMode.Linear,
|
||||
KeyFrames =
|
||||
{
|
||||
new AnimationTrackComponentProperty.KeyFrame(initialPosition.Position, 0),
|
||||
new AnimationTrackComponentProperty.KeyFrame(finalPosition, 0.125f)
|
||||
}
|
||||
}
|
||||
}
|
||||
}, "fancy_pickup_anim");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user