Files
tbd-station-14/Content.Shared/GameObjects/Components/Sound/SharedLoopingSoundComponent.cs
Visne 9b94d5c195 Added nullable to most Content.Shared files (#3238)
* Add nullable to some Content.Shared files.

* Use [NotNullWhen(true)]

* Undo adding now redundant !'s

* Forgot one

* Add a ton more nullable

* You can guess

* Fix some issues

* It actually compiles now

* Auto stash before merge of "null2" and "origin/master"

* I lied

* enable annotations -> enable

* Revert ActionBlockerSystem.cs to original

* Fix ActionBlockerSystem.cs

* More nullable

* Undo some added exclamation marks

* Fix issues

* Update Content.Shared/Maps/ContentTileDefinition.cs

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>

* Resolve some issues

* Remove unused method

* Fix more issues

* Fix more issues

* Fix more issues

* Fix more issues

* Fix issue, rollback SharedGhostComponent.cs

* Update submodule

* Fix issue, invert some if-statements to reduce nesting

* Revert RobustToolbox

* FIx things broken by merge

* Some fixes

- Replaced with string.Empty
- Remove some exclamation marks
- Revert file

* Some fixes

* Trivial #nullable enable

* Fix null ables

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
2021-02-27 14:12:09 +11:00

122 lines
3.6 KiB
C#

#nullable enable
using System;
using Robust.Shared.Audio;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization;
namespace Content.Shared.GameObjects.Components.Sound
{
public class SharedLoopingSoundComponent : Component
{
public override string Name => "LoopingSound";
public override uint? NetID => ContentNetIDs.SOUND;
/// <summary>
/// Stops all sounds.
/// </summary>
public virtual void StopAllSounds()
{}
/// <summary>
/// Stops a certain scheduled sound from playing.
/// </summary>
public virtual void StopScheduledSound(string filename)
{}
/// <summary>
/// Adds an scheduled sound to be played.
/// </summary>
public virtual void AddScheduledSound(ScheduledSound scheduledSound)
{}
/// <summary>
/// Play an audio file following the entity.
/// </summary>
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
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]
public class ScheduledSound : IExposeData
{
public string Filename = "";
/// <summary>
/// The parameters to play the sound with.
/// </summary>
public AudioParams? AudioParams;
/// <summary>
/// Delay in milliseconds before playing the sound,
/// and delay between repetitions if Times is not 0.
/// </summary>
public uint Delay = 0;
/// <summary>
/// Maximum number of milliseconds to add to the delay randomly.
/// Useful for random ambience noises. Generated value differs from client to client.
/// </summary>
public uint RandomDelay = 0;
/// <summary>
/// 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.
/// </summary>
public int Times = 0;
/// <summary>
/// Whether the sound will play or not.
/// </summary>
public bool Play = true;
void IExposeData.ExposeData(ObjectSerializer serializer)
{
if (serializer.Writing)
return;
Filename = serializer.ReadDataField("filename", "");
Delay = serializer.ReadDataField("delay", 0u);
RandomDelay = serializer.ReadDataField("randomdelay", 0u);
Times = serializer.ReadDataField("times", 0);
AudioParams = serializer.ReadDataField("audioparams", Robust.Shared.Audio.AudioParams.Default);
}
}
}