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:
@@ -54,8 +54,8 @@ namespace Content.Server.Mind.Commands
|
||||
|
||||
if (allowSpeech)
|
||||
{
|
||||
entityManager.EnsureComponent<SharedSpeechComponent>(uid);
|
||||
entityManager.EnsureComponent<SharedEmotingComponent>(uid);
|
||||
entityManager.EnsureComponent<SpeechComponent>(uid);
|
||||
entityManager.EnsureComponent<EmotingComponent>(uid);
|
||||
}
|
||||
|
||||
entityManager.EnsureComponent<ExaminerComponent>(uid);
|
||||
|
||||
@@ -19,10 +19,10 @@ namespace Content.Server.Speech
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SharedSpeechComponent, EntitySpokeEvent>(OnEntitySpoke);
|
||||
SubscribeLocalEvent<SpeechComponent, EntitySpokeEvent>(OnEntitySpoke);
|
||||
}
|
||||
|
||||
private void OnEntitySpoke(EntityUid uid, SharedSpeechComponent component, EntitySpokeEvent args)
|
||||
private void OnEntitySpoke(EntityUid uid, SpeechComponent component, EntitySpokeEvent args)
|
||||
{
|
||||
if (component.SpeechSounds == null) return;
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ public sealed class SurveillanceCameraSpeakerSystem : EntitySystem
|
||||
|
||||
// this part's mostly copied from speech
|
||||
if (time - component.LastSoundPlayed < cd
|
||||
&& TryComp<SharedSpeechComponent>(args.Speaker, out var speech)
|
||||
&& TryComp<SpeechComponent>(args.Speaker, out var speech)
|
||||
&& speech.SpeechSounds != null
|
||||
&& _prototypeManager.TryIndex(speech.SpeechSounds, out SpeechSoundsPrototype? speechProto))
|
||||
{
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
namespace Content.Shared.Emoting
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Emoting
|
||||
{
|
||||
public sealed class EmoteSystem : EntitySystem
|
||||
{
|
||||
@@ -7,12 +10,51 @@
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<EmoteAttemptEvent>(OnEmoteAttempt);
|
||||
SubscribeLocalEvent<EmotingComponent, ComponentGetState>(OnEmotingGetState);
|
||||
SubscribeLocalEvent<EmotingComponent, ComponentHandleState>(OnEmotingHandleState);
|
||||
}
|
||||
|
||||
public void SetEmoting(EntityUid uid, bool value, EmotingComponent? component = null)
|
||||
{
|
||||
if (value && !Resolve(uid, ref component))
|
||||
return;
|
||||
|
||||
component = EnsureComp<EmotingComponent>(uid);
|
||||
|
||||
if (component.Enabled == value)
|
||||
return;
|
||||
|
||||
Dirty(component);
|
||||
}
|
||||
|
||||
private void OnEmotingHandleState(EntityUid uid, EmotingComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not EmotingComponentState state)
|
||||
return;
|
||||
|
||||
component.Enabled = state.Enabled;
|
||||
}
|
||||
|
||||
private void OnEmotingGetState(EntityUid uid, EmotingComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new EmotingComponentState(component.Enabled);
|
||||
}
|
||||
|
||||
private void OnEmoteAttempt(EmoteAttemptEvent args)
|
||||
{
|
||||
if (!TryComp(args.Uid, out SharedEmotingComponent? emote) || !emote.Enabled)
|
||||
if (!TryComp(args.Uid, out EmotingComponent? emote) || !emote.Enabled)
|
||||
args.Cancel();
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
private sealed class EmotingComponentState : ComponentState
|
||||
{
|
||||
public bool Enabled { get; }
|
||||
|
||||
public EmotingComponentState(bool enabled)
|
||||
{
|
||||
Enabled = enabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
12
Content.Shared/Emoting/EmotingComponent.cs
Normal file
12
Content.Shared/Emoting/EmotingComponent.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Emoting
|
||||
{
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed class EmotingComponent : Component
|
||||
{
|
||||
[DataField("enabled"), Access(typeof(EmoteSystem),
|
||||
Friend = AccessPermissions.ReadWrite,
|
||||
Other = AccessPermissions.Read)] public bool Enabled = true;
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Emoting
|
||||
{
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed class SharedEmotingComponent : Component
|
||||
{
|
||||
[DataField("enabled")] private bool _enabled = true;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public bool Enabled
|
||||
{
|
||||
get => _enabled;
|
||||
set
|
||||
{
|
||||
if (_enabled == value)
|
||||
return;
|
||||
|
||||
_enabled = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
return new EmotingComponentState(Enabled);
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
if (curState is not EmotingComponentState emoting)
|
||||
return;
|
||||
|
||||
_enabled = emoting.Enabled;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
private sealed class EmotingComponentState : ComponentState
|
||||
{
|
||||
public bool Enabled { get; }
|
||||
|
||||
public EmotingComponentState(bool enabled)
|
||||
{
|
||||
Enabled = enabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Speech
|
||||
{
|
||||
@@ -7,11 +8,13 @@ namespace Content.Shared.Speech
|
||||
/// Component required for entities to be able to speak. (TODO: Entities can speak fine without this, this only forbids them speak if they have it and enabled is false.)
|
||||
/// Contains the option to let entities make noise when speaking, datafields for the sounds in question, and relevant AudioParams.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class SharedSpeechComponent : Component
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
public sealed class SpeechComponent : Component
|
||||
{
|
||||
[DataField("enabled")]
|
||||
private bool _enabled = true;
|
||||
[DataField("enabled"), Access(typeof(SpeechSystem),
|
||||
Friend = AccessPermissions.ReadWrite,
|
||||
Other = AccessPermissions.Read)]
|
||||
public bool Enabled = true;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("speechSounds", customTypeSerializer:typeof(PrototypeIdSerializer<SpeechSoundsPrototype>))]
|
||||
@@ -25,16 +28,5 @@ namespace Content.Shared.Speech
|
||||
public float SoundCooldownTime { get; set; } = 0.5f;
|
||||
|
||||
public TimeSpan LastTimeSoundPlayed = TimeSpan.Zero;
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
get => _enabled;
|
||||
set
|
||||
{
|
||||
if (_enabled == value) return;
|
||||
_enabled = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user