Component ECS (#17991)
This commit is contained in:
@@ -1,55 +1,15 @@
|
||||
using Content.Shared.Item;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Hands.Components
|
||||
namespace Content.Shared.Hands.Components;
|
||||
|
||||
[RegisterComponent]
|
||||
[NetworkedComponent]
|
||||
[AutoGenerateComponentState(true)]
|
||||
public sealed partial class HandVirtualItemComponent : Component
|
||||
{
|
||||
[RegisterComponent]
|
||||
[NetworkedComponent]
|
||||
public sealed class HandVirtualItemComponent : Component
|
||||
{
|
||||
private EntityUid _blockingEntity;
|
||||
|
||||
/// <summary>
|
||||
/// The entity blocking this hand.
|
||||
/// </summary>
|
||||
public EntityUid BlockingEntity
|
||||
{
|
||||
get => _blockingEntity;
|
||||
set
|
||||
{
|
||||
_blockingEntity = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
return new VirtualItemComponentState(BlockingEntity);
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
if (curState is not VirtualItemComponentState pullState)
|
||||
return;
|
||||
|
||||
_blockingEntity = pullState.BlockingEntity;
|
||||
|
||||
// update hands GUI with new entity.
|
||||
if (Owner.TryGetContainer(out _))
|
||||
EntitySystem.Get<SharedItemSystem>().VisualsChanged(Owner);
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class VirtualItemComponentState : ComponentState
|
||||
{
|
||||
public readonly EntityUid BlockingEntity;
|
||||
|
||||
public VirtualItemComponentState(EntityUid blockingEntity)
|
||||
{
|
||||
BlockingEntity = blockingEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// The entity blocking this hand.
|
||||
/// </summary>
|
||||
[DataField("blockingEntity"), AutoNetworkedField]
|
||||
public EntityUid BlockingEntity;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using Content.Shared.Hands.Components;
|
||||
|
||||
namespace Content.Shared.Hands.EntitySystems;
|
||||
|
||||
public abstract partial class SharedHandsSystem
|
||||
{
|
||||
private void InitializeVirtual()
|
||||
{
|
||||
SubscribeLocalEvent<HandVirtualItemComponent, AfterAutoHandleStateEvent>(OnVirtualAfter);
|
||||
}
|
||||
|
||||
private void OnVirtualAfter(EntityUid uid, HandVirtualItemComponent component, ref AfterAutoHandleStateEvent args)
|
||||
{
|
||||
// update hands GUI with new entity.
|
||||
if (_containerSystem.IsEntityInContainer(uid))
|
||||
_items.VisualsChanged(uid);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Administration.Logs;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Item;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Input.Binding;
|
||||
|
||||
@@ -12,9 +13,10 @@ namespace Content.Shared.Hands.EntitySystems;
|
||||
public abstract partial class SharedHandsSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
||||
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
||||
[Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
|
||||
[Dependency] private readonly SharedItemSystem _items = default!;
|
||||
|
||||
protected event Action<HandsComponent?>? OnHandSetActive;
|
||||
|
||||
@@ -25,6 +27,7 @@ public abstract partial class SharedHandsSystem : EntitySystem
|
||||
InitializeInteractions();
|
||||
InitializeDrop();
|
||||
InitializePickup();
|
||||
InitializeVirtual();
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
|
||||
@@ -37,6 +37,7 @@ public abstract class SharedHandVirtualItemSystem : EntitySystem
|
||||
virtualItem = Spawn("HandVirtualItem", pos);
|
||||
var virtualItemComp = EntityManager.GetComponent<HandVirtualItemComponent>(virtualItem.Value);
|
||||
virtualItemComp.BlockingEntity = blockingEnt;
|
||||
Dirty(virtualItemComp);
|
||||
_hands.DoPickup(user, hand, virtualItem.Value);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user