mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-17 13:37:47 +03:00
## Mirror of PR #24936: [Pulling rework v2](https://github.com/space-wizards/space-station-14/pull/24936) from <img src="https://avatars.githubusercontent.com/u/10567778?v=4" alt="space-wizards" width="22"/> [space-wizards](https://github.com/space-wizards)/[space-station-14](https://github.com/space-wizards/space-station-14) ###### `c584f6444a85cc53edb060230f7e7b2b76cc87bf` PR opened by <img src="https://avatars.githubusercontent.com/u/31366439?v=4" width="16"/><a href="https://github.com/metalgearsloth"> metalgearsloth</a> at 2024-02-04 01:43:17 UTC --- PR changed 53 files with 796 additions and 1356 deletions. The PR had the following labels: - Status: Needs Review --- <details open="true"><summary><h1>Original Body</h1></summary> > Health v2 moment > > Fixes https://github.com/space-wizards/space-station-14/issues/24900 > > - Fixes container changes. > - Fixes keybind. > - Fixes multi-pull. > - Fixes alerts cleanup for non-predicted pull stops. > > I'm awake now for any issues. </details> --------- Co-authored-by: SimpleStation14 <Unknown> Co-authored-by: Danger Revolution! <142105406+DangerRevolution@users.noreply.github.com> Co-authored-by: VMSolidus <evilexecutive@gmail.com>
88 lines
2.8 KiB
C#
88 lines
2.8 KiB
C#
using Content.Shared.Throwing;
|
|
using Robust.Client.Animations;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Shared.Animations;
|
|
|
|
namespace Content.Client.Throwing;
|
|
|
|
/// <summary>
|
|
/// Handles animating thrown items.
|
|
/// </summary>
|
|
public sealed class ThrownItemVisualizerSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly AnimationPlayerSystem _anim = default!;
|
|
|
|
private const string AnimationKey = "thrown-item";
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<ThrownItemComponent, AfterAutoHandleStateEvent>(OnAutoHandleState);
|
|
SubscribeLocalEvent<ThrownItemComponent, ComponentShutdown>(OnShutdown);
|
|
}
|
|
|
|
private void OnAutoHandleState(EntityUid uid, ThrownItemComponent component, ref AfterAutoHandleStateEvent args)
|
|
{
|
|
if (!TryComp<SpriteComponent>(uid, out var sprite) || !component.Animate)
|
|
return;
|
|
|
|
var animationPlayer = EnsureComp<AnimationPlayerComponent>(uid);
|
|
|
|
if (_anim.HasRunningAnimation(uid, animationPlayer, AnimationKey))
|
|
return;
|
|
|
|
var anim = GetAnimation((uid, component, sprite));
|
|
if (anim == null)
|
|
return;
|
|
|
|
component.OriginalScale = sprite.Scale;
|
|
_anim.Play((uid, animationPlayer), anim, AnimationKey);
|
|
}
|
|
|
|
private void OnShutdown(EntityUid uid, ThrownItemComponent component, ComponentShutdown args)
|
|
{
|
|
if (!_anim.HasRunningAnimation(uid, AnimationKey))
|
|
return;
|
|
|
|
if (TryComp<SpriteComponent>(uid, out var sprite) && component.OriginalScale != null)
|
|
sprite.Scale = component.OriginalScale.Value;
|
|
|
|
_anim.Stop(uid, AnimationKey);
|
|
}
|
|
|
|
private static Animation? GetAnimation(Entity<ThrownItemComponent, SpriteComponent> ent)
|
|
{
|
|
if (ent.Comp1.LandTime - ent.Comp1.ThrownTime is not { } length)
|
|
return null;
|
|
|
|
if (length <= TimeSpan.Zero)
|
|
return null;
|
|
|
|
length += TimeSpan.FromSeconds(ThrowingSystem.FlyTime);
|
|
var scale = ent.Comp2.Scale;
|
|
var lenFloat = (float) length.TotalSeconds;
|
|
|
|
// TODO use like actual easings here
|
|
return new Animation
|
|
{
|
|
Length = length,
|
|
AnimationTracks =
|
|
{
|
|
new AnimationTrackComponentProperty
|
|
{
|
|
ComponentType = typeof(SpriteComponent),
|
|
Property = nameof(SpriteComponent.Scale),
|
|
KeyFrames =
|
|
{
|
|
new AnimationTrackProperty.KeyFrame(scale, 0.0f),
|
|
new AnimationTrackProperty.KeyFrame(scale * 1.4f, lenFloat * 0.25f),
|
|
new AnimationTrackProperty.KeyFrame(scale, lenFloat * 0.75f)
|
|
},
|
|
InterpolationMode = AnimationInterpolationMode.Linear
|
|
}
|
|
}
|
|
};
|
|
}
|
|
}
|