2021-09-07 18:47:23 +10:00
|
|
|
using Content.Server.Power.Components;
|
2021-09-30 10:09:16 +10:00
|
|
|
using Content.Server.Power.EntitySystems;
|
2021-09-07 18:47:23 +10:00
|
|
|
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);
|
2021-09-30 10:09:16 +10:00
|
|
|
SubscribeLocalEvent<AmbientOnPoweredComponent, PowerNetBatterySupplyEvent>(HandlePowerSupply);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandlePowerSupply(EntityUid uid, AmbientOnPoweredComponent component, PowerNetBatterySupplyEvent args)
|
|
|
|
|
{
|
2021-09-29 17:34:34 -07:00
|
|
|
if (!EntityManager.TryGetComponent<AmbientSoundComponent>(uid, out var ambientSound)) return;
|
2021-09-30 10:09:16 +10:00
|
|
|
if (ambientSound.Enabled == args.Supply) return;
|
|
|
|
|
ambientSound.Enabled = args.Supply;
|
2022-02-02 17:34:25 +11:00
|
|
|
Dirty(ambientSound);
|
2021-09-07 18:47:23 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandlePowerChange(EntityUid uid, AmbientOnPoweredComponent component, PowerChangedEvent args)
|
|
|
|
|
{
|
2021-09-28 13:35:29 +02:00
|
|
|
if (!EntityManager.TryGetComponent<AmbientSoundComponent>(uid, out var ambientSound)) return;
|
2021-09-07 18:47:23 +10:00
|
|
|
if (ambientSound.Enabled == args.Powered) return;
|
|
|
|
|
ambientSound.Enabled = args.Powered;
|
2022-02-02 17:34:25 +11:00
|
|
|
Dirty(ambientSound);
|
2021-09-07 18:47:23 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|