2022-12-28 04:03:25 +11:00
|
|
|
namespace Content.Shared.Speech
|
2021-06-19 10:03:24 +02:00
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class SpeechSystem : EntitySystem
|
2021-06-19 10:03:24 +02:00
|
|
|
{
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2022-01-08 00:57:20 +13:00
|
|
|
SubscribeLocalEvent<SpeakAttemptEvent>(OnSpeakAttempt);
|
2022-12-28 04:03:25 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetSpeech(EntityUid uid, bool value, SpeechComponent? component = null)
|
|
|
|
|
{
|
|
|
|
|
if (value && !Resolve(uid, ref component))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
component = EnsureComp<SpeechComponent>(uid);
|
|
|
|
|
|
|
|
|
|
if (component.Enabled == value)
|
|
|
|
|
return;
|
|
|
|
|
|
2024-01-12 03:03:02 -05:00
|
|
|
component.Enabled = value;
|
|
|
|
|
|
|
|
|
|
Dirty(uid, component);
|
2022-12-28 04:03:25 +11:00
|
|
|
}
|
|
|
|
|
|
2022-01-08 00:57:20 +13:00
|
|
|
private void OnSpeakAttempt(SpeakAttemptEvent args)
|
2021-06-19 10:03:24 +02:00
|
|
|
{
|
2022-12-28 04:03:25 +11:00
|
|
|
if (!TryComp(args.Uid, out SpeechComponent? speech) || !speech.Enabled)
|
2021-10-21 13:03:14 +11:00
|
|
|
args.Cancel();
|
2021-06-19 10:03:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|