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:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user