Cleanup speech and emoting comps (#13194)

Networks speech and removes the shared prefix from emoting.
I have no idea if emoting is even being used or plan to be used in the interim.
This commit is contained in:
metalgearsloth
2022-12-28 04:03:25 +11:00
committed by GitHub
parent 2a8e5d9096
commit 0d7423c01d
8 changed files with 112 additions and 73 deletions

View File

@@ -1,4 +1,7 @@
namespace Content.Shared.Speech
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Speech
{
public sealed class SpeechSystem : EntitySystem
{
@@ -7,12 +10,51 @@
base.Initialize();
SubscribeLocalEvent<SpeakAttemptEvent>(OnSpeakAttempt);
SubscribeLocalEvent<SpeechComponent, ComponentGetState>(OnSpeechGetState);
SubscribeLocalEvent<SpeechComponent, ComponentHandleState>(OnSpeechHandleState);
}
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;
Dirty(component);
}
private void OnSpeechHandleState(EntityUid uid, SpeechComponent component, ref ComponentHandleState args)
{
if (args.Current is not SpeechComponentState state)
return;
component.Enabled = state.Enabled;
}
private void OnSpeechGetState(EntityUid uid, SpeechComponent component, ref ComponentGetState args)
{
args.State = new SpeechComponentState(component.Enabled);
}
private void OnSpeakAttempt(SpeakAttemptEvent args)
{
if (!TryComp(args.Uid, out SharedSpeechComponent? speech) || !speech.Enabled)
if (!TryComp(args.Uid, out SpeechComponent? speech) || !speech.Enabled)
args.Cancel();
}
[Serializable, NetSerializable]
private sealed class SpeechComponentState : ComponentState
{
public readonly bool Enabled;
public SpeechComponentState(bool enabled)
{
Enabled = enabled;
}
}
}
}