ECS pilots (#8321)
This commit is contained in:
@@ -1,7 +1,5 @@
|
|||||||
using Content.Shared.ActionBlocker;
|
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Serialization;
|
|
||||||
|
|
||||||
namespace Content.Shared.Shuttles.Components
|
namespace Content.Shared.Shuttles.Components
|
||||||
{
|
{
|
||||||
@@ -12,9 +10,6 @@ namespace Content.Shared.Shuttles.Components
|
|||||||
[NetworkedComponent]
|
[NetworkedComponent]
|
||||||
public sealed class PilotComponent : Component
|
public sealed class PilotComponent : Component
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IEntitySystemManager _sysMan = default!;
|
|
||||||
[Dependency] private readonly IEntityManager _entMan = default!;
|
|
||||||
|
|
||||||
[ViewVariables] public SharedShuttleConsoleComponent? Console { get; set; }
|
[ViewVariables] public SharedShuttleConsoleComponent? Console { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -23,43 +18,5 @@ namespace Content.Shared.Shuttles.Components
|
|||||||
[ViewVariables] public EntityCoordinates? Position { get; set; }
|
[ViewVariables] public EntityCoordinates? Position { get; set; }
|
||||||
|
|
||||||
public const float BreakDistance = 0.25f;
|
public const float BreakDistance = 0.25f;
|
||||||
|
|
||||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
|
||||||
{
|
|
||||||
base.HandleComponentState(curState, nextState);
|
|
||||||
if (curState is not PilotComponentState state) return;
|
|
||||||
|
|
||||||
var console = state.Console.GetValueOrDefault();
|
|
||||||
if (!console.IsValid())
|
|
||||||
{
|
|
||||||
Console = null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!_entMan.TryGetComponent(console, out SharedShuttleConsoleComponent? shuttleConsoleComponent))
|
|
||||||
{
|
|
||||||
Logger.Warning($"Unable to set Helmsman console to {console}");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Console = shuttleConsoleComponent;
|
|
||||||
_sysMan.GetEntitySystem<ActionBlockerSystem>().UpdateCanMove(Owner);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override ComponentState GetComponentState()
|
|
||||||
{
|
|
||||||
return Console == null ? new PilotComponentState(null) : new PilotComponentState(Console.Owner);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
|
||||||
private sealed class PilotComponentState : ComponentState
|
|
||||||
{
|
|
||||||
public EntityUid? Console { get; }
|
|
||||||
|
|
||||||
public PilotComponentState(EntityUid? uid)
|
|
||||||
{
|
|
||||||
Console = uid;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using Content.Shared.ActionBlocker;
|
using Content.Shared.ActionBlocker;
|
||||||
using Content.Shared.Movement;
|
using Content.Shared.Movement;
|
||||||
using Content.Shared.Shuttles.Components;
|
using Content.Shared.Shuttles.Components;
|
||||||
|
using Robust.Shared.GameStates;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Shared.Shuttles
|
namespace Content.Shared.Shuttles
|
||||||
{
|
{
|
||||||
@@ -14,6 +16,45 @@ namespace Content.Shared.Shuttles
|
|||||||
SubscribeLocalEvent<PilotComponent, UpdateCanMoveEvent>(HandleMovementBlock);
|
SubscribeLocalEvent<PilotComponent, UpdateCanMoveEvent>(HandleMovementBlock);
|
||||||
SubscribeLocalEvent<PilotComponent, ComponentStartup>(OnStartup);
|
SubscribeLocalEvent<PilotComponent, ComponentStartup>(OnStartup);
|
||||||
SubscribeLocalEvent<PilotComponent, ComponentShutdown>(HandlePilotShutdown);
|
SubscribeLocalEvent<PilotComponent, ComponentShutdown>(HandlePilotShutdown);
|
||||||
|
SubscribeLocalEvent<PilotComponent, ComponentGetState>(OnGetState);
|
||||||
|
SubscribeLocalEvent<PilotComponent, ComponentHandleState>(OnHandleState);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnGetState(EntityUid uid, PilotComponent component, ref ComponentGetState args)
|
||||||
|
{
|
||||||
|
args.State = new PilotComponentState(component.Console?.Owner);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnHandleState(EntityUid uid, PilotComponent component, ref ComponentHandleState args)
|
||||||
|
{
|
||||||
|
if (args.Current is not PilotComponentState state) return;
|
||||||
|
|
||||||
|
var console = state.Console.GetValueOrDefault();
|
||||||
|
if (!console.IsValid())
|
||||||
|
{
|
||||||
|
component.Console = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TryComp<SharedShuttleConsoleComponent>(console, out var shuttleConsoleComponent))
|
||||||
|
{
|
||||||
|
Logger.Warning($"Unable to set Helmsman console to {console}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
component.Console = shuttleConsoleComponent;
|
||||||
|
ActionBlockerSystem.UpdateCanMove(uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
private sealed class PilotComponentState : ComponentState
|
||||||
|
{
|
||||||
|
public EntityUid? Console { get; }
|
||||||
|
|
||||||
|
public PilotComponentState(EntityUid? uid)
|
||||||
|
{
|
||||||
|
Console = uid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void HandlePilotShutdown(EntityUid uid, PilotComponent component, ComponentShutdown args)
|
protected virtual void HandlePilotShutdown(EntityUid uid, PilotComponent component, ComponentShutdown args)
|
||||||
|
|||||||
Reference in New Issue
Block a user