Files
OldThink/Content.Client/_Amour/Vibrator/VibratorSystem.cs
2024-11-08 20:56:26 +03:00

65 lines
2.1 KiB
C#

using System.Numerics;
using Content.Shared._Amour.Vibrator;
using Robust.Client.Animations;
using Robust.Client.GameObjects;
using Robust.Shared.Animations;
namespace Content.Client._Amour.Vibrator;
public sealed class VibratorSystem : SharedVibratorSystem
{
[Dependency] private readonly AnimationPlayerSystem _animationSystem = default!;
private readonly string _vibration = "vibration";
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<VibratorComponent, AnimationCompletedEvent>(OnAnimationCompleted);
}
private void OnAnimationCompleted(EntityUid uid, VibratorComponent component, AnimationCompletedEvent args)
{
if (args.Key != _vibration || !component.IsVibrating)
return;
_animationSystem.Play(uid, GetAnimation(), _vibration);
}
public override void ToggleVibrate(EntityUid uid, VibratorComponent component)
{
if (component.IsVibrating)
_animationSystem.Play(uid, GetAnimation(), _vibration);
}
private Robust.Client.Animations.Animation GetAnimation()
{
return new Robust.Client.Animations.Animation
{
Length = TimeSpan.FromMilliseconds(100),
AnimationTracks =
{
new AnimationTrackComponentProperty
{
ComponentType = typeof(SpriteComponent),
Property = nameof(SpriteComponent.Offset),
InterpolationMode = AnimationInterpolationMode.Cubic,
KeyFrames =
{
new AnimationTrackProperty.KeyFrame(Vector2.Zero, 0f),
new AnimationTrackProperty.KeyFrame(new Vector2(0.1f, 0), 0.25f),
new AnimationTrackProperty.KeyFrame(Vector2.Zero, 0.25f),
new AnimationTrackProperty.KeyFrame(new Vector2(-0.1f, 0), 0.25f),
new AnimationTrackProperty.KeyFrame(Vector2.Zero, 0.25f),
}
}
}
};
}
}