Makes mobs visually float when weightless (#13391)

This commit is contained in:
AJCM-git
2023-01-17 18:01:53 -04:00
committed by GitHub
parent 21db0ab35b
commit 67ed59a50d
8 changed files with 217 additions and 46 deletions

View File

@@ -1,53 +1,17 @@
using Content.Client.Pointing.Components;
using Content.Client.Gravity;
using Content.Shared.Mobs.Systems;
using Content.Shared.Pointing;
using Content.Shared.Verbs;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Shared.Animations;
using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
namespace Content.Client.Pointing;
public sealed class PointingSystem : SharedPointingSystem
{
[Dependency] private readonly AnimationPlayerSystem _player = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
private const string AnimationKey = "pointingarrow";
/// <summary>
/// How far it goes in any direction.
/// </summary>
private const float Offset = 0.25f;
/// <summary>
/// How long it takes to go from the bottom of the animation to the top.
/// </summary>
private const float UpTime = 0.5f;
/// <summary>
/// Starts at the bottom then goes up and comes back down. Seems to look nicer than starting in the middle.
/// </summary>
private static readonly Animation PointingAnimation = new Animation()
{
Length = TimeSpan.FromSeconds(2 * UpTime),
AnimationTracks =
{
new AnimationTrackComponentProperty()
{
ComponentType = typeof(SpriteComponent),
Property = nameof(SpriteComponent.Offset),
InterpolationMode = AnimationInterpolationMode.Linear,
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(Vector2.Zero, 0f),
new AnimationTrackProperty.KeyFrame(new Vector2(0f, Offset), UpTime),
new AnimationTrackProperty.KeyFrame(Vector2.Zero, UpTime),
}
}
}
};
[Dependency] private readonly FloatingVisualizerSystem _floatingSystem = default!;
public override void Initialize()
{
@@ -61,7 +25,7 @@ public sealed class PointingSystem : SharedPointingSystem
private void OnArrowAnimation(EntityUid uid, PointingArrowComponent component, AnimationCompletedEvent args)
{
_player.Play(uid, PointingAnimation, AnimationKey);
_floatingSystem.FloatAnimation(uid, component.Offset, component.AnimationKey, component.AnimationTime);
}
private void AddPointingVerb(GetVerbsEvent<Verb> args)
@@ -98,19 +62,19 @@ public sealed class PointingSystem : SharedPointingSystem
args.Verbs.Add(verb);
}
private void OnArrowStartup(EntityUid uid, PointingArrowComponent arrow, ComponentStartup args)
private void OnArrowStartup(EntityUid uid, PointingArrowComponent component, ComponentStartup args)
{
if (EntityManager.TryGetComponent(uid, out SpriteComponent? sprite))
if (TryComp<SpriteComponent>(uid, out var sprite))
{
sprite.DrawDepth = (int) DrawDepth.Overlays;
}
_player.Play(uid, PointingAnimation, AnimationKey);
_floatingSystem.FloatAnimation(uid, component.Offset, component.AnimationKey, component.AnimationTime);
}
private void OnRogueArrowStartup(EntityUid uid, RoguePointingArrowComponent arrow, ComponentStartup args)
{
if (EntityManager.TryGetComponent(uid, out SpriteComponent? sprite))
if (TryComp<SpriteComponent>(uid, out var sprite))
{
sprite.DrawDepth = (int) DrawDepth.Overlays;
sprite.NoRotation = false;