Files
tbd-station-14/Content.Shared/Audio/SharedAmbientSoundSystem.cs
metalgearsloth ff40a7665d 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
2021-09-07 18:47:23 +10:00

46 lines
1.7 KiB
C#

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,
};
}
}
}