mirror of
https://github.com/space-wizards/RobustToolbox.git
synced 2026-09-15 14:52:35 +02:00
* Added new ComponentEventBus, combined it with IEventBus. * Removed all traces of IEntity from ComponentDependencies. Removed IEntityManager dependency from ComponentManager. * Added entity create/delete events to IEntityManager. * ComponentEvents now use EntitySystemMessages instead of their custom ComponentEvent class. * Component events are now just overloads of entity events. * Removed obsolete EntitySystemMessage, now everything uses the base EntityEventArgs. * Add a bool argument for if the message should be broadcast as well as directed. Fix ordering and init issues of events in EntityManager. * Changed names from Component/Entity events to Directed/Broadcast. * Fix bugs and unit tests.
83 lines
3.3 KiB
C#
83 lines
3.3 KiB
C#
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Player;
|
|
|
|
namespace Robust.Shared.Audio
|
|
{
|
|
/// <summary>
|
|
/// A static proxy class for interfacing with the AudioSystem.
|
|
/// </summary>
|
|
public static class SoundSystem
|
|
{
|
|
/// <summary>
|
|
/// Default max range at which the sound can be heard.
|
|
/// </summary>
|
|
public static int DefaultSoundRange => GetAudio()?.DefaultSoundRange ?? 0;
|
|
|
|
/// <summary>
|
|
/// Used in the PAS to designate the physics collision mask of occluders.
|
|
/// </summary>
|
|
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<IEntityManager>().EventBus.RaiseEvent(EventSource.Local, args);
|
|
return args.Audio;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Play an audio file globally, without position.
|
|
/// </summary>
|
|
/// <param name="playerFilter">The set of players that will hear the sound.</param>
|
|
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
|
|
/// <param name="audioParams">Audio parameters to apply when playing the sound.</param>
|
|
public static IPlayingAudioStream? Play(Filter playerFilter, string filename, AudioParams? audioParams = null)
|
|
{
|
|
return GetAudio()?.Play(playerFilter, filename, audioParams);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Play an audio file following an entity.
|
|
/// </summary>
|
|
/// <param name="playerFilter">The set of players that will hear the sound.</param>
|
|
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
|
|
/// <param name="entity">The entity "emitting" the audio.</param>
|
|
/// <param name="audioParams">Audio parameters to apply when playing the sound.</param>
|
|
public static IPlayingAudioStream? Play(Filter playerFilter, string filename, IEntity entity, AudioParams? audioParams = null)
|
|
{
|
|
return GetAudio()?.Play(playerFilter, filename, entity, audioParams);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Play an audio file at a static position.
|
|
/// </summary>
|
|
/// <param name="playerFilter">The set of players that will hear the sound.</param>
|
|
/// <param name="filename">The resource path to the OGG Vorbis file to play.</param>
|
|
/// <param name="coordinates">The coordinates at which to play the audio.</param>
|
|
/// <param name="audioParams">Audio parameters to apply when playing the sound.</param>
|
|
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; }
|
|
}
|
|
}
|
|
}
|