ghost auto gen comp state (#15304)

Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
deltanedas
2023-04-14 19:46:17 +00:00
committed by GitHub
parent 5b09ee3102
commit 450de80993

View File

@@ -3,9 +3,11 @@ using Robust.Shared.Serialization;
namespace Content.Shared.Ghost
{
[NetworkedComponent()]
public abstract class SharedGhostComponent : Component
[NetworkedComponent]
[AutoGenerateComponentState]
public abstract partial class SharedGhostComponent : Component
{
// TODO: instead of this funny stuff just give it access and update in system dirtying when needed
[ViewVariables(VVAccess.ReadWrite)]
public bool CanGhostInteract
{
@@ -18,7 +20,7 @@ namespace Content.Shared.Ghost
}
}
[DataField("canInteract")]
[DataField("canInteract"), AutoNetworkedField]
private bool _canGhostInteract;
/// <summary>
@@ -37,41 +39,8 @@ namespace Content.Shared.Ghost
}
}
[DataField("canReturnToBody")]
[DataField("canReturnToBody"), AutoNetworkedField]
private bool _canReturnToBody;
public override ComponentState GetComponentState()
{
return new GhostComponentState(CanReturnToBody, CanGhostInteract);
}
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
{
base.HandleComponentState(curState, nextState);
if (curState is not GhostComponentState state)
{
return;
}
CanReturnToBody = state.CanReturnToBody;
CanGhostInteract = state.CanGhostInteract;
}
}
[Serializable, NetSerializable]
public sealed class GhostComponentState : ComponentState
{
public bool CanReturnToBody { get; }
public bool CanGhostInteract { get; }
public GhostComponentState(
bool canReturnToBody,
bool canGhostInteract)
{
CanReturnToBody = canReturnToBody;
CanGhostInteract = canGhostInteract;
}
}
}