Fix/ECS SharedEmotingComponent.
IActionBlocker -> events Fix networking.
This commit is contained in:
@@ -8,15 +8,13 @@ namespace Content.Shared.Emoting
|
|||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeLocalEvent<EmoteAttemptEvent>(OnEmoteAttempt);
|
SubscribeLocalEvent<SharedEmotingComponent, EmoteAttemptEvent>(OnEmoteAttempt);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEmoteAttempt(EmoteAttemptEvent ev)
|
private void OnEmoteAttempt(EntityUid entity, SharedEmotingComponent component, EmoteAttemptEvent ev)
|
||||||
{
|
|
||||||
if (!ev.Entity.HasComponent<SharedEmotingComponent>())
|
|
||||||
{
|
{
|
||||||
|
if (!component.Enabled)
|
||||||
ev.Cancel();
|
ev.Cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,26 +1,55 @@
|
|||||||
using Content.Shared.ActionBlocker;
|
using System;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.GameStates;
|
||||||
|
using Robust.Shared.Players;
|
||||||
using Robust.Shared.Serialization.Manager.Attributes;
|
using Robust.Shared.Serialization.Manager.Attributes;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
|
using Robust.Shared.ViewVariables;
|
||||||
|
|
||||||
namespace Content.Shared.Emoting
|
namespace Content.Shared.Emoting
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent, NetworkedComponent]
|
||||||
public class SharedEmotingComponent : Component, IActionBlocker
|
public class SharedEmotingComponent : Component
|
||||||
{
|
{
|
||||||
[DataField("enabled")] private bool _enabled = true;
|
[DataField("enabled")] private bool _enabled = true;
|
||||||
public override string Name => "Emoting";
|
public override string Name => "Emoting";
|
||||||
|
|
||||||
|
[ViewVariables(VVAccess.ReadWrite)]
|
||||||
public bool Enabled
|
public bool Enabled
|
||||||
{
|
{
|
||||||
get => _enabled;
|
get => _enabled;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (_enabled == value) return;
|
if (_enabled == value)
|
||||||
|
return;
|
||||||
|
|
||||||
_enabled = value;
|
_enabled = value;
|
||||||
Dirty();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user