using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Player;
namespace Robust.Shared.Audio
{
///
/// A static proxy class for interfacing with the AudioSystem.
///
public static class SoundSystem
{
///
/// Default max range at which the sound can be heard.
///
public static int DefaultSoundRange => GetAudio()?.DefaultSoundRange ?? 0;
///
/// Used in the PAS to designate the physics collision mask of occluders.
///
public static int OcclusionCollisionMask
{
get => GetAudio()?.OcclusionCollisionMask ?? 0;
set
{
var audio = GetAudio();
if (audio is null)
return;
audio.OcclusionCollisionMask = value;
}
}
private static IAudioSystem? GetAudio()
{
// There appears to be no way to get a System by interface.
var args = new QueryAudioSystem();
IoCManager.Resolve().EventBus.RaiseEvent(EventSource.Local, args);
return args.Audio;
}
///
/// Play an audio file globally, without position.
///
/// The set of players that will hear the sound.
/// The resource path to the OGG Vorbis file to play.
/// Audio parameters to apply when playing the sound.
public static IPlayingAudioStream? Play(Filter playerFilter, string filename, AudioParams? audioParams = null)
{
return GetAudio()?.Play(playerFilter, filename, audioParams);
}
///
/// Play an audio file following an entity.
///
/// The set of players that will hear the sound.
/// The resource path to the OGG Vorbis file to play.
/// The entity "emitting" the audio.
/// Audio parameters to apply when playing the sound.
public static IPlayingAudioStream? Play(Filter playerFilter, string filename, IEntity entity, AudioParams? audioParams = null)
{
return GetAudio()?.Play(playerFilter, filename, entity, audioParams);
}
///
/// Play an audio file at a static position.
///
/// The set of players that will hear the sound.
/// The resource path to the OGG Vorbis file to play.
/// The coordinates at which to play the audio.
/// Audio parameters to apply when playing the sound.
public static IPlayingAudioStream? Play(Filter playerFilter, string filename, EntityCoordinates coordinates, AudioParams? audioParams = null)
{
return GetAudio()?.Play(playerFilter, filename, coordinates, audioParams);
}
internal class QueryAudioSystem : EntityEventArgs
{
public IAudioSystem? Audio { get; set; }
}
}
}