using System; using Robust.Shared.Audio; using Robust.Shared.GameObjects; using Robust.Shared.GameStates; using Robust.Shared.Serialization; using Robust.Shared.Serialization.Manager.Attributes; namespace Content.Shared.Sound { [NetworkedComponent()] public class SharedLoopingSoundComponent : Component { public override string Name => "LoopingSound"; /// /// Stops all sounds. /// public virtual void StopAllSounds() {} /// /// Stops a certain scheduled sound from playing. /// public virtual void StopScheduledSound(string filename) {} /// /// Adds an scheduled sound to be played. /// public virtual void AddScheduledSound(ScheduledSound scheduledSound) {} /// /// Play an audio file following the entity. /// /// The resource path to the OGG Vorbis file to play. public void Play(string filename, AudioParams? audioParams = null) { AddScheduledSound(new ScheduledSound() { Filename = filename, AudioParams = audioParams, }); } } [NetSerializable, Serializable] public class ScheduledSoundMessage : ComponentMessage { public ScheduledSound Schedule = new(); public ScheduledSoundMessage() { Directed = true; } } [NetSerializable, Serializable] public class StopSoundScheduleMessage : ComponentMessage { public string Filename = string.Empty; public StopSoundScheduleMessage() { Directed = true; } } [NetSerializable, Serializable] public class StopAllSoundsMessage : ComponentMessage { public StopAllSoundsMessage() { Directed = true; } } [Serializable, NetSerializable] [DataDefinition] public class ScheduledSound { [DataField("fileName")] public string Filename = string.Empty; /// /// The parameters to play the sound with. /// [DataField("audioparams")] public AudioParams? AudioParams; /// /// Delay in milliseconds before playing the sound, /// and delay between repetitions if Times is not 0. /// [DataField("delay")] public uint Delay; /// /// Maximum number of milliseconds to add to the delay randomly. /// Useful for random ambience noises. Generated value differs from client to client. /// [DataField("randomdelay")] public uint RandomDelay; /// /// How many times to repeat the sound. If it's 0, it will play the sound once. /// If it's less than 0, it will repeat the sound indefinitely. /// If it's greater than 0, it will play the sound n+1 times. /// [DataField("times")] public int Times; /// /// Whether the sound will play or not. /// public bool Play = true; } }