2022-12-28 04:03:25 +11:00
|
|
|
|
using Robust.Shared.GameStates;
|
|
|
|
|
|
using Robust.Shared.Serialization;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Content.Shared.Emoting
|
2021-06-19 10:03:24 +02:00
|
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class EmoteSystem : EntitySystem
|
2021-06-19 10:03:24 +02:00
|
|
|
|
{
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
2022-01-08 00:57:20 +13:00
|
|
|
|
SubscribeLocalEvent<EmoteAttemptEvent>(OnEmoteAttempt);
|
2022-12-28 04:03:25 +11:00
|
|
|
|
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);
|
2021-06-19 10:03:24 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-01-08 00:57:20 +13:00
|
|
|
|
private void OnEmoteAttempt(EmoteAttemptEvent args)
|
2021-06-19 10:03:24 +02:00
|
|
|
|
{
|
2022-12-28 04:03:25 +11:00
|
|
|
|
if (!TryComp(args.Uid, out EmotingComponent? emote) || !emote.Enabled)
|
2022-01-08 00:57:20 +13:00
|
|
|
|
args.Cancel();
|
2021-06-19 10:03:24 +02:00
|
|
|
|
}
|
2022-12-28 04:03:25 +11:00
|
|
|
|
|
|
|
|
|
|
[Serializable, NetSerializable]
|
|
|
|
|
|
private sealed class EmotingComponentState : ComponentState
|
|
|
|
|
|
{
|
|
|
|
|
|
public bool Enabled { get; }
|
|
|
|
|
|
|
|
|
|
|
|
public EmotingComponentState(bool enabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
Enabled = enabled;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-06-19 10:03:24 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|