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:
14
Content.Server/Audio/AmbientOnPoweredComponent.cs
Normal file
14
Content.Server/Audio/AmbientOnPoweredComponent.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using Content.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Audio
|
||||
{
|
||||
/// <summary>
|
||||
/// Toggles <see cref="AmbientSoundComponent"/> on when powered and off when not powered.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class AmbientOnPoweredComponent : Component
|
||||
{
|
||||
public override string Name => "AmbientOnPowered";
|
||||
}
|
||||
}
|
||||
23
Content.Server/Audio/AmbientSoundSystem.cs
Normal file
23
Content.Server/Audio/AmbientSoundSystem.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.Audio
|
||||
{
|
||||
public sealed class AmbientSoundSystem : SharedAmbientSoundSystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<AmbientOnPoweredComponent, PowerChangedEvent>(HandlePowerChange);
|
||||
}
|
||||
|
||||
private void HandlePowerChange(EntityUid uid, AmbientOnPoweredComponent component, PowerChangedEvent args)
|
||||
{
|
||||
if (!ComponentManager.TryGetComponent<AmbientSoundComponent>(uid, out var ambientSound)) return;
|
||||
if (ambientSound.Enabled == args.Powered) return;
|
||||
ambientSound.Enabled = args.Powered;
|
||||
ambientSound.Dirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.UserInterface;
|
||||
using Content.Shared.Acts;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Gravity;
|
||||
using Content.Shared.Interaction;
|
||||
using Robust.Server.GameObjects;
|
||||
@@ -137,6 +138,7 @@ namespace Content.Server.Gravity
|
||||
private void MakeBroken()
|
||||
{
|
||||
_status = GravityGeneratorStatus.Broken;
|
||||
EntitySystem.Get<SharedAmbientSoundSystem>().SetAmbience(Owner.Uid, false);
|
||||
|
||||
_appearance?.SetData(GravityGeneratorVisuals.State, Status);
|
||||
_appearance?.SetData(GravityGeneratorVisuals.CoreVisible, false);
|
||||
@@ -145,6 +147,7 @@ namespace Content.Server.Gravity
|
||||
private void MakeUnpowered()
|
||||
{
|
||||
_status = GravityGeneratorStatus.Unpowered;
|
||||
EntitySystem.Get<SharedAmbientSoundSystem>().SetAmbience(Owner.Uid, false);
|
||||
|
||||
_appearance?.SetData(GravityGeneratorVisuals.State, Status);
|
||||
_appearance?.SetData(GravityGeneratorVisuals.CoreVisible, false);
|
||||
@@ -153,6 +156,7 @@ namespace Content.Server.Gravity
|
||||
private void MakeOff()
|
||||
{
|
||||
_status = GravityGeneratorStatus.Off;
|
||||
EntitySystem.Get<SharedAmbientSoundSystem>().SetAmbience(Owner.Uid, false);
|
||||
|
||||
_appearance?.SetData(GravityGeneratorVisuals.State, Status);
|
||||
_appearance?.SetData(GravityGeneratorVisuals.CoreVisible, false);
|
||||
@@ -161,6 +165,7 @@ namespace Content.Server.Gravity
|
||||
private void MakeOn()
|
||||
{
|
||||
_status = GravityGeneratorStatus.On;
|
||||
EntitySystem.Get<SharedAmbientSoundSystem>().SetAmbience(Owner.Uid, true);
|
||||
|
||||
_appearance?.SetData(GravityGeneratorVisuals.State, Status);
|
||||
_appearance?.SetData(GravityGeneratorVisuals.CoreVisible, true);
|
||||
|
||||
@@ -4,6 +4,7 @@ using Content.Server.Hands.Components;
|
||||
using Content.Server.Items;
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Temperature.Components;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Components;
|
||||
using Content.Shared.Interaction;
|
||||
@@ -226,7 +227,7 @@ namespace Content.Server.Light.Components
|
||||
|
||||
if (LightBulb == null) // No light bulb.
|
||||
{
|
||||
_currentLit = false;
|
||||
SetLight(false);
|
||||
powerReceiver.Load = 0;
|
||||
_appearance?.SetData(PoweredLightVisuals.BulbState, PoweredLightState.Empty);
|
||||
return;
|
||||
@@ -267,6 +268,7 @@ namespace Content.Server.Light.Components
|
||||
private void SetLight(bool value, Color? color = null)
|
||||
{
|
||||
_currentLit = value;
|
||||
EntitySystem.Get<SharedAmbientSoundSystem>().SetAmbience(Owner.Uid, value);
|
||||
|
||||
if (!Owner.TryGetComponent(out PointLightComponent? pointLight)) return;
|
||||
pointLight.Enabled = value;
|
||||
@@ -327,6 +329,6 @@ namespace Content.Server.Light.Components
|
||||
UpdateLight();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user