mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-10 02:41:18 +03:00
* IoC source gen compatibility Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter. * Missed a spot
50 lines
1.7 KiB
C#
50 lines
1.7 KiB
C#
using System.Numerics;
|
|
using Robust.Shared.Map;
|
|
|
|
namespace Content.Shared.Gravity;
|
|
|
|
/// <summary>
|
|
/// Handles offsetting a sprite when there is no gravity
|
|
/// </summary>
|
|
public abstract partial class SharedFloatingVisualizerSystem : EntitySystem
|
|
{
|
|
[Dependency] private SharedGravitySystem _gravity = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<FloatingVisualsComponent, ComponentStartup>(OnComponentStartup);
|
|
SubscribeLocalEvent<FloatingVisualsComponent, WeightlessnessChangedEvent>(OnWeightlessnessChanged);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Offsets a sprite with a linear interpolation animation
|
|
/// </summary>
|
|
public virtual void FloatAnimation(EntityUid uid, Vector2 offset, string animationKey, float animationTime, bool stop = false) { }
|
|
|
|
protected bool CanFloat(Entity<FloatingVisualsComponent> entity)
|
|
{
|
|
entity.Comp.CanFloat = _gravity.IsWeightless(entity.Owner);
|
|
Dirty(entity);
|
|
return entity.Comp.CanFloat;
|
|
}
|
|
|
|
private void OnComponentStartup(Entity<FloatingVisualsComponent> entity, ref ComponentStartup args)
|
|
{
|
|
if (CanFloat(entity))
|
|
FloatAnimation(entity, entity.Comp.Offset, entity.Comp.AnimationKey, entity.Comp.AnimationTime);
|
|
}
|
|
|
|
private void OnWeightlessnessChanged(Entity<FloatingVisualsComponent> entity, ref WeightlessnessChangedEvent args)
|
|
{
|
|
if (entity.Comp.CanFloat == args.Weightless)
|
|
return;
|
|
|
|
entity.Comp.CanFloat = CanFloat(entity);
|
|
Dirty(entity);
|
|
|
|
if (args.Weightless)
|
|
FloatAnimation(entity, entity.Comp.Offset, entity.Comp.AnimationKey, entity.Comp.AnimationTime);
|
|
}
|
|
}
|