Partial buckling refactor (#29031)
* partial buckling refactor * git mv test * change test namespace * git mv test * Update test namespace * Add pulling test * Network BuckleTime * Add two more tests * smelly
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.Interaction;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
|
||||
namespace Content.Shared.Buckle.Components;
|
||||
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
|
||||
/// <summary>
|
||||
/// This component allows an entity to be buckled to an entity with a <see cref="StrapComponent"/>.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
[Access(typeof(SharedBuckleSystem))]
|
||||
public sealed partial class BuckleComponent : Component
|
||||
{
|
||||
@@ -14,31 +19,23 @@ public sealed partial class BuckleComponent : Component
|
||||
/// across a table two tiles away" problem.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float Range = SharedInteractionSystem.InteractionRange / 1.4f;
|
||||
|
||||
/// <summary>
|
||||
/// True if the entity is buckled, false otherwise.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[AutoNetworkedField]
|
||||
public bool Buckled;
|
||||
|
||||
[ViewVariables]
|
||||
[AutoNetworkedField]
|
||||
public EntityUid? LastEntityBuckledTo;
|
||||
[MemberNotNullWhen(true, nameof(BuckledTo))]
|
||||
public bool Buckled => BuckledTo != null;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not collisions should be possible with the entity we are strapped to
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField, AutoNetworkedField]
|
||||
[DataField]
|
||||
public bool DontCollide;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not we should be allowed to pull the entity we are strapped to
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField]
|
||||
public bool PullStrap;
|
||||
|
||||
@@ -47,20 +44,18 @@ public sealed partial class BuckleComponent : Component
|
||||
/// be able to unbuckle after recently buckling.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public TimeSpan Delay = TimeSpan.FromSeconds(0.25f);
|
||||
|
||||
/// <summary>
|
||||
/// The time that this entity buckled at.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public TimeSpan BuckleTime;
|
||||
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
|
||||
public TimeSpan? BuckleTime;
|
||||
|
||||
/// <summary>
|
||||
/// The strap that this component is buckled to.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[AutoNetworkedField]
|
||||
[DataField]
|
||||
public EntityUid? BuckledTo;
|
||||
|
||||
/// <summary>
|
||||
@@ -68,7 +63,6 @@ public sealed partial class BuckleComponent : Component
|
||||
/// <see cref="StrapComponent"/>.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int Size = 100;
|
||||
|
||||
/// <summary>
|
||||
@@ -77,11 +71,90 @@ public sealed partial class BuckleComponent : Component
|
||||
[ViewVariables] public int? OriginalDrawDepth;
|
||||
}
|
||||
|
||||
[ByRefEvent]
|
||||
public record struct BuckleAttemptEvent(EntityUid StrapEntity, EntityUid BuckledEntity, EntityUid UserEntity, bool Buckling, bool Cancelled = false);
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class BuckleState(NetEntity? buckledTo, bool dontCollide, TimeSpan? buckleTime) : ComponentState
|
||||
{
|
||||
public readonly NetEntity? BuckledTo = buckledTo;
|
||||
public readonly bool DontCollide = dontCollide;
|
||||
public readonly TimeSpan? BuckleTime = buckleTime;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Event raised directed at a strap entity before some entity gets buckled to it.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public readonly record struct BuckleChangeEvent(EntityUid StrapEntity, EntityUid BuckledEntity, bool Buckling);
|
||||
public record struct StrapAttemptEvent(
|
||||
Entity<StrapComponent> Strap,
|
||||
Entity<BuckleComponent> Buckle,
|
||||
EntityUid? User,
|
||||
bool Popup)
|
||||
{
|
||||
public bool Cancelled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event raised directed at a buckle entity before it gets buckled to some strap entity.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public record struct BuckleAttemptEvent(
|
||||
Entity<StrapComponent> Strap,
|
||||
Entity<BuckleComponent> Buckle,
|
||||
EntityUid? User,
|
||||
bool Popup)
|
||||
{
|
||||
public bool Cancelled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event raised directed at a strap entity before some entity gets unbuckled from it.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public record struct UnstrapAttemptEvent(
|
||||
Entity<StrapComponent> Strap,
|
||||
Entity<BuckleComponent> Buckle,
|
||||
EntityUid? User,
|
||||
bool Popup)
|
||||
{
|
||||
public bool Cancelled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event raised directed at a buckle entity before it gets unbuckled.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public record struct UnbuckleAttemptEvent(
|
||||
Entity<StrapComponent> Strap,
|
||||
Entity<BuckleComponent> Buckle,
|
||||
EntityUid? User,
|
||||
bool Popup)
|
||||
{
|
||||
public bool Cancelled;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event raised directed at a strap entity after something has been buckled to it.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public readonly record struct StrappedEvent(Entity<StrapComponent> Strap, Entity<BuckleComponent> Buckle);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised directed at a buckle entity after it has been buckled.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public readonly record struct BuckledEvent(Entity<StrapComponent> Strap, Entity<BuckleComponent> Buckle);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised directed at a strap entity after something has been unbuckled from it.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public readonly record struct UnstrappedEvent(Entity<StrapComponent> Strap, Entity<BuckleComponent> Buckle);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised directed at a buckle entity after it has been unbuckled from some strap entity.
|
||||
/// </summary>
|
||||
[ByRefEvent]
|
||||
public readonly record struct UnbuckledEvent(Entity<StrapComponent> Strap, Entity<BuckleComponent> Buckle);
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum BuckleVisuals
|
||||
|
||||
Reference in New Issue
Block a user