Ambient sound system (#4552)
* Ambient sound system Client-side system that plays audio from nearby objects that are randomly sampled. * Decent * Tweaks * Tweaks * Comment this out for now * reduce VM sound * Fix rolloff * Fixes * Volume tweak
This commit is contained in:
45
Content.Shared/Audio/SharedAmbientSoundSystem.cs
Normal file
45
Content.Shared/Audio/SharedAmbientSoundSystem.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Audio
|
||||
{
|
||||
public abstract class SharedAmbientSoundSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<AmbientSoundComponent, ComponentGetState>(GetCompState);
|
||||
SubscribeLocalEvent<AmbientSoundComponent, ComponentHandleState>(HandleCompState);
|
||||
}
|
||||
|
||||
public void SetAmbience(EntityUid uid, bool value)
|
||||
{
|
||||
// Reason I didn't make this eventbus for the callers is because it seemed a bit silly
|
||||
// trying to account for damageable + powered + toggle, plus we can't just check if it's powered.
|
||||
// So we'll just call it directly for whatever.
|
||||
if (!ComponentManager.TryGetComponent<AmbientSoundComponent>(uid, out var ambience) ||
|
||||
ambience.Enabled == value) return;
|
||||
|
||||
ambience.Enabled = value;
|
||||
ambience.Dirty();
|
||||
}
|
||||
|
||||
private void HandleCompState(EntityUid uid, AmbientSoundComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not AmbientSoundComponentState state) return;
|
||||
component.Enabled = state.Enabled;
|
||||
component.Range = state.Range;
|
||||
component.Volume = state.Volume;
|
||||
}
|
||||
|
||||
private void GetCompState(EntityUid uid, AmbientSoundComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new AmbientSoundComponentState
|
||||
{
|
||||
Enabled = component.Enabled,
|
||||
Range = component.Range,
|
||||
Volume = component.Volume,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user