* 1 warning in KudzuVisualizerSystem * 2 warnings in ChameleonProjectorSystem * 1 warning in MarkerSystem * 2 warnings in ItemSystem * 1 warning in GhostToggleSelfVisibility * 1 warning in FoamVisualizerSystem * 1 warning in ClickableTest * 1 warning in ThrownItemVisualizerSystem * 2 warnings in InfantSystem * 1 warning in ChasmFallingVisualsSystem * 1 warning in PotencyVisualsSystem * 2 warnings in OrbitVisualsSystem * 2 warnings in BeamSystem * 1 warning in JitteringSystem * 1 warning in CardboardBoxSystem * 2 warnings in StationAiSystem * 2 warnings in FirelockSystem * 2 warnings in CargoSystem.Telepad * 1 warning in StasisBedSystem * 2 warnings in WeldableVisualizerSystem * 2 warnings in DeliveryVisualizerSystem * 1 warning in TimerTriggerVisualizerSystem * 1 warning in StorageFillVisualizerSystem * 2 warnings in RadiationCollectorSystem * 2 warnings in BorgSwitchableTypeSystem * 1 warning in TurnstileSystem * 1 warning in SurveillanceCameraVisualsSystem * 1 warning in BurnStateVisualizerSystem * 2 warnings in CableVisualizerSystem * 1 warning in JetpackSystem
83 lines
2.6 KiB
C#
83 lines
2.6 KiB
C#
using Content.Shared.Chasm;
|
|
using Robust.Client.Animations;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Shared.Animations;
|
|
|
|
namespace Content.Client.Chasm;
|
|
|
|
/// <summary>
|
|
/// Handles the falling animation for entities that fall into a chasm.
|
|
/// </summary>
|
|
public sealed class ChasmFallingVisualsSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly AnimationPlayerSystem _anim = default!;
|
|
[Dependency] private readonly SpriteSystem _sprite = default!;
|
|
|
|
private readonly string _chasmFallAnimationKey = "chasm_fall";
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<ChasmFallingComponent, ComponentInit>(OnComponentInit);
|
|
SubscribeLocalEvent<ChasmFallingComponent, ComponentRemove>(OnComponentRemove);
|
|
}
|
|
|
|
private void OnComponentInit(EntityUid uid, ChasmFallingComponent component, ComponentInit args)
|
|
{
|
|
if (!TryComp<SpriteComponent>(uid, out var sprite) ||
|
|
TerminatingOrDeleted(uid))
|
|
{
|
|
return;
|
|
}
|
|
|
|
component.OriginalScale = sprite.Scale;
|
|
|
|
if (!TryComp<AnimationPlayerComponent>(uid, out var player))
|
|
return;
|
|
|
|
if (_anim.HasRunningAnimation(player, _chasmFallAnimationKey))
|
|
return;
|
|
|
|
_anim.Play((uid, player), GetFallingAnimation(component), _chasmFallAnimationKey);
|
|
}
|
|
|
|
private void OnComponentRemove(EntityUid uid, ChasmFallingComponent component, ComponentRemove args)
|
|
{
|
|
if (!TryComp<SpriteComponent>(uid, out var sprite))
|
|
return;
|
|
|
|
_sprite.SetScale((uid, sprite), component.OriginalScale);
|
|
|
|
if (!TryComp<AnimationPlayerComponent>(uid, out var player))
|
|
return;
|
|
|
|
if (_anim.HasRunningAnimation(player, _chasmFallAnimationKey))
|
|
_anim.Stop((uid, player), _chasmFallAnimationKey);
|
|
}
|
|
|
|
private Animation GetFallingAnimation(ChasmFallingComponent component)
|
|
{
|
|
var length = component.AnimationTime;
|
|
|
|
return new Animation()
|
|
{
|
|
Length = length,
|
|
AnimationTracks =
|
|
{
|
|
new AnimationTrackComponentProperty()
|
|
{
|
|
ComponentType = typeof(SpriteComponent),
|
|
Property = nameof(SpriteComponent.Scale),
|
|
KeyFrames =
|
|
{
|
|
new AnimationTrackProperty.KeyFrame(component.OriginalScale, 0.0f),
|
|
new AnimationTrackProperty.KeyFrame(component.AnimationScale, length.Seconds),
|
|
},
|
|
InterpolationMode = AnimationInterpolationMode.Cubic
|
|
}
|
|
}
|
|
};
|
|
}
|
|
}
|