using System.Numerics; using Robust.Shared.GameStates; using Robust.Shared.Serialization; namespace Content.Shared.Animation; /// /// When given to an entity, will create a sin wave offset of their sprite. /// Can do both axies and also rotate. /// [RegisterComponent, NetworkedComponent, AutoGenerateComponentState] public sealed partial class SineWaveAnimationComponent : Component { /// /// Length of the animation. /// [DataField, AutoNetworkedField] public TimeSpan AnimationLength = TimeSpan.FromSeconds(1); /// /// How many key frames should there in the animation? /// [DataField, AutoNetworkedField] public float KeyFrames = 60; /// /// If true, will reset the sprites offset back to its original value before the animation started when it finishes. /// [DataField, AutoNetworkedField] public bool ResetOffsetOnEnd = true; /// /// Saved offset from before the animation started. /// [ViewVariables(VVAccess.ReadWrite)] public Vector2 StartOffset; /// /// If true, will reset the sprites rotation back to its original value before the animation started when it finishes. /// [DataField, AutoNetworkedField] public bool ResetRotationOnEnd = true; /// /// Saved rotation from before the animation started. /// [ViewVariables(VVAccess.ReadWrite)] public Angle StartRotation; /// /// Should the animation repeat itself after being completed? /// [DataField, AutoNetworkedField] public bool Repeat = true; /// /// Definition of the sin wave being played on the x-axis. If null, nothing will play on this axis. /// [DataField, AutoNetworkedField] public SignWaveDefinition? XWave; /// /// Definition of the sin wave being played on the y-axis. If null, nothing will play on this axis. /// [DataField, AutoNetworkedField] public SignWaveDefinition? YWave; /// /// Stores the total time for the x wave spent doing then animation. Needed for smooth looping so it doesn't /// offset in an odd way when restarting. /// [ViewVariables(VVAccess.ReadWrite)] public TimeSpan TotalTimeX; /// /// Same as LastTimeX, but with Y. /// [ViewVariables(VVAccess.ReadWrite)] public TimeSpan TotalTimeY; } /// /// Definition of a sin wave. This is the equation that's used: /// /// Period = 1 / Frequency /// x = Amplitude * Sin((time + PhaseOffset) / Period) /// [Serializable, NetSerializable, DataDefinition] public partial struct SignWaveDefinition { /// /// Amplitude of the equation in distance (1 = 1 square offset at the peak) /// [DataField] public float Amplitude = 1; /// /// Frequency for the equation in Hz (1 = 1 cycle per second) /// [DataField] public float Frequency = 1; public TimeSpan Period => TimeSpan.FromSeconds(1 / Frequency); /// /// The time offset to start the animation. If set to null, it will be set to a random number /// between 0 and the Period (which is 1 / ). Set to 0 for no offset. /// [DataField] public TimeSpan? PhaseOffset = TimeSpan.Zero; /// /// If true, the sprite will also be rotated to follow the slope of the wave. /// [DataField] public bool RotateToFollowSlope = true; }