Surveillance camera listening/speaking (#11640)

This commit is contained in:
Flipp Syder
2022-10-16 10:44:14 -07:00
committed by GitHub
parent 7003a35cb9
commit 6e108bd400
12 changed files with 219 additions and 5 deletions

View File

@@ -0,0 +1,47 @@
using Content.Server.Radio.Components;
using Content.Shared.Interaction;
using Content.Shared.Radio;
using Content.Shared.Whitelist;
namespace Content.Server.SurveillanceCamera;
/// <summary>
/// Component that allows surveillance cameras to listen to the local
/// environment. All surveillance camera monitors have speakers for this.
/// </summary>
[RegisterComponent]
[ComponentReference(typeof(IListen))]
public sealed class SurveillanceCameraMicrophoneComponent : Component, IListen
{
public bool Enabled { get; set; } = true;
/// <summary>
/// Components that the microphone checks for to avoid transmitting
/// messages from these entities over the surveillance camera.
/// Used to avoid things like feedback loops, or radio spam.
/// </summary>
[DataField("blacklist")]
public EntityWhitelist BlacklistedComponents { get; } = new();
// TODO: Once IListen is removed, **REMOVE THIS**
private SurveillanceCameraMicrophoneSystem? _microphoneSystem;
protected override void Initialize()
{
base.Initialize();
_microphoneSystem = EntitySystem.Get<SurveillanceCameraMicrophoneSystem>();
}
public int ListenRange { get; } = 10;
public bool CanListen(string message, EntityUid source, RadioChannelPrototype? channelPrototype)
{
return _microphoneSystem != null
&& _microphoneSystem.CanListen(Owner, source, this);
}
public void Listen(string message, EntityUid speaker, RadioChannelPrototype? channel)
{
_microphoneSystem?.RelayEntityMessage(Owner, speaker, message);
}
}

View File

@@ -0,0 +1,18 @@
namespace Content.Server.SurveillanceCamera;
/// <summary>
/// This allows surveillance cameras to speak, if the camera in question
/// has a microphone that listens to speech.
/// </summary>
[RegisterComponent]
public sealed class SurveillanceCameraSpeakerComponent : Component
{
// mostly copied from Speech
[DataField("speechEnabled")] public bool SpeechEnabled = true;
[ViewVariables] public float SpeechSoundCooldown = 0.5f;
[ViewVariables] public readonly Queue<string> LastSpokenNames = new();
public TimeSpan LastSoundPlayed = TimeSpan.Zero;
}