From 9733d35de712a34616dbb09369fb51a1748f6c0f Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Wed, 15 Sep 2021 16:17:09 +0200 Subject: [PATCH] Fix/ECS SharedEmotingComponent. IActionBlocker -> events Fix networking. --- Content.Shared/Emoting/EmoteSystem.cs | 8 ++-- .../Emoting/SharedEmotingComponent.cs | 39 ++++++++++++++++--- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/Content.Shared/Emoting/EmoteSystem.cs b/Content.Shared/Emoting/EmoteSystem.cs index ef97cbf500..1aee5508eb 100644 --- a/Content.Shared/Emoting/EmoteSystem.cs +++ b/Content.Shared/Emoting/EmoteSystem.cs @@ -8,15 +8,13 @@ namespace Content.Shared.Emoting { base.Initialize(); - SubscribeLocalEvent(OnEmoteAttempt); + SubscribeLocalEvent(OnEmoteAttempt); } - private void OnEmoteAttempt(EmoteAttemptEvent ev) + private void OnEmoteAttempt(EntityUid entity, SharedEmotingComponent component, EmoteAttemptEvent ev) { - if (!ev.Entity.HasComponent()) - { + if (!component.Enabled) ev.Cancel(); - } } } } diff --git a/Content.Shared/Emoting/SharedEmotingComponent.cs b/Content.Shared/Emoting/SharedEmotingComponent.cs index 48972b5628..d9cfbd058b 100644 --- a/Content.Shared/Emoting/SharedEmotingComponent.cs +++ b/Content.Shared/Emoting/SharedEmotingComponent.cs @@ -1,26 +1,55 @@ -using Content.Shared.ActionBlocker; +using System; using Robust.Shared.GameObjects; +using Robust.Shared.GameStates; +using Robust.Shared.Players; using Robust.Shared.Serialization.Manager.Attributes; +using Robust.Shared.Serialization; +using Robust.Shared.ViewVariables; namespace Content.Shared.Emoting { - [RegisterComponent] - public class SharedEmotingComponent : Component, IActionBlocker + [RegisterComponent, NetworkedComponent] + public class SharedEmotingComponent : Component { [DataField("enabled")] private bool _enabled = true; public override string Name => "Emoting"; + [ViewVariables(VVAccess.ReadWrite)] public bool Enabled { get => _enabled; set { - if (_enabled == value) return; + if (_enabled == value) + return; + _enabled = value; Dirty(); } } - bool IActionBlocker.CanEmote() => Enabled; + public override ComponentState GetComponentState(ICommonSession player) + { + 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; + } + } } }