Update trivial components to use auto comp states (#20539)
This commit is contained in:
@@ -4,7 +4,7 @@ using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Buckle.Components;
|
||||
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState(true)]
|
||||
[Access(typeof(SharedBuckleSystem))]
|
||||
public sealed partial class BuckleComponent : Component
|
||||
{
|
||||
@@ -13,7 +13,7 @@ public sealed partial class BuckleComponent : Component
|
||||
/// Separated from normal interaction range to fix the "someone buckled to a strap
|
||||
/// across a table two tiles away" problem.
|
||||
/// </summary>
|
||||
[DataField("range")]
|
||||
[DataField]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float Range = SharedInteractionSystem.InteractionRange / 1.4f;
|
||||
|
||||
@@ -21,32 +21,34 @@ public sealed partial class BuckleComponent : Component
|
||||
/// True if the entity is buckled, false otherwise.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[AutoNetworkedField]
|
||||
public bool Buckled;
|
||||
|
||||
[ViewVariables]
|
||||
[AutoNetworkedField]
|
||||
public EntityUid? LastEntityBuckledTo;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not collisions should be possible with the entity we are strapped to
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("dontCollide")]
|
||||
[DataField, AutoNetworkedField]
|
||||
public bool DontCollide;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not we should be allowed to pull the entity we are strapped to
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("pullStrap")]
|
||||
[DataField]
|
||||
public bool PullStrap;
|
||||
|
||||
/// <summary>
|
||||
/// The amount of time that must pass for this entity to
|
||||
/// be able to unbuckle after recently buckling.
|
||||
/// </summary>
|
||||
[DataField("delay")]
|
||||
[DataField]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public TimeSpan UnbuckleDelay = TimeSpan.FromSeconds(0.25f);
|
||||
public TimeSpan Delay = TimeSpan.FromSeconds(0.25f);
|
||||
|
||||
/// <summary>
|
||||
/// The time that this entity buckled at.
|
||||
@@ -58,39 +60,21 @@ public sealed partial class BuckleComponent : Component
|
||||
/// The strap that this component is buckled to.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[AutoNetworkedField]
|
||||
public EntityUid? BuckledTo;
|
||||
|
||||
/// <summary>
|
||||
/// The amount of space that this entity occupies in a
|
||||
/// <see cref="StrapComponent"/>.
|
||||
/// </summary>
|
||||
[DataField("size")]
|
||||
[DataField]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int Size = 100;
|
||||
|
||||
/// <summary>
|
||||
/// Used for client rendering
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public int? OriginalDrawDepth;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class BuckleComponentState : ComponentState
|
||||
{
|
||||
public BuckleComponentState(bool buckled, NetEntity? buckledTo, NetEntity? lastEntityBuckledTo,
|
||||
bool dontCollide)
|
||||
{
|
||||
Buckled = buckled;
|
||||
BuckledTo = buckledTo;
|
||||
LastEntityBuckledTo = lastEntityBuckledTo;
|
||||
DontCollide = dontCollide;
|
||||
}
|
||||
|
||||
public readonly bool Buckled;
|
||||
public readonly NetEntity? BuckledTo;
|
||||
public readonly NetEntity? LastEntityBuckledTo;
|
||||
public readonly bool DontCollide;
|
||||
[ViewVariables] public int? OriginalDrawDepth;
|
||||
}
|
||||
|
||||
[ByRefEvent]
|
||||
|
||||
@@ -8,28 +8,29 @@ using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Buckle.Components;
|
||||
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||
[Access(typeof(SharedBuckleSystem), typeof(SharedVehicleSystem))]
|
||||
public sealed partial class StrapComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The entities that are currently buckled
|
||||
/// </summary>
|
||||
[AutoNetworkedField(true)]
|
||||
[ViewVariables] // TODO serialization
|
||||
public readonly HashSet<EntityUid> BuckledEntities = new();
|
||||
public HashSet<EntityUid> BuckledEntities = new();
|
||||
|
||||
/// <summary>
|
||||
/// Entities that this strap accepts and can buckle
|
||||
/// If null it accepts any entity
|
||||
/// </summary>
|
||||
[DataField("allowedEntities")]
|
||||
[DataField]
|
||||
[ViewVariables]
|
||||
public EntityWhitelist? AllowedEntities;
|
||||
|
||||
/// <summary>
|
||||
/// The change in position to the strapped mob
|
||||
/// </summary>
|
||||
[DataField("position")]
|
||||
[DataField, AutoNetworkedField]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public StrapPosition Position = StrapPosition.None;
|
||||
|
||||
@@ -43,7 +44,7 @@ public sealed partial class StrapComponent : Component
|
||||
/// whereas the server doesnt, thus the client tries to unbuckle like 15 times because it passes the strap null check
|
||||
/// This is why this needs to be above 0.1 to make the InRange check fail in both client and server.
|
||||
/// </remarks>
|
||||
[DataField("maxBuckleDistance", required: false)]
|
||||
[DataField, AutoNetworkedField]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float MaxBuckleDistance = 0.2f;
|
||||
|
||||
@@ -51,8 +52,8 @@ public sealed partial class StrapComponent : Component
|
||||
/// Gets and clamps the buckle offset to MaxBuckleDistance
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public Vector2 BuckleOffset => Vector2.Clamp(
|
||||
BuckleOffsetUnclamped,
|
||||
public Vector2 BuckleOffsetClamped => Vector2.Clamp(
|
||||
BuckleOffset,
|
||||
Vector2.One * -MaxBuckleDistance,
|
||||
Vector2.One * MaxBuckleDistance);
|
||||
|
||||
@@ -60,21 +61,21 @@ public sealed partial class StrapComponent : Component
|
||||
/// The buckled entity will be offset by this amount from the center of the strap object.
|
||||
/// If this offset it too big, it will be clamped to <see cref="MaxBuckleDistance"/>
|
||||
/// </summary>
|
||||
[DataField("buckleOffset", required: false)]
|
||||
[DataField, AutoNetworkedField]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public Vector2 BuckleOffsetUnclamped = Vector2.Zero;
|
||||
public Vector2 BuckleOffset = Vector2.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// The angle in degrees to rotate the player by when they get strapped
|
||||
/// </summary>
|
||||
[DataField("rotation")]
|
||||
[DataField]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int Rotation;
|
||||
|
||||
/// <summary>
|
||||
/// The size of the strap which is compared against when buckling entities
|
||||
/// </summary>
|
||||
[DataField("size")]
|
||||
[DataField]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public int Size = 100;
|
||||
|
||||
@@ -87,58 +88,39 @@ public sealed partial class StrapComponent : Component
|
||||
/// <summary>
|
||||
/// You can specify the offset the entity will have after unbuckling.
|
||||
/// </summary>
|
||||
[DataField("unbuckleOffset", required: false)]
|
||||
[DataField]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public Vector2 UnbuckleOffset = Vector2.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// The sound to be played when a mob is buckled
|
||||
/// </summary>
|
||||
[DataField("buckleSound")]
|
||||
[DataField]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public SoundSpecifier BuckleSound = new SoundPathSpecifier("/Audio/Effects/buckle.ogg");
|
||||
|
||||
/// <summary>
|
||||
/// The sound to be played when a mob is unbuckled
|
||||
/// </summary>
|
||||
[DataField("unbuckleSound")]
|
||||
[DataField]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public SoundSpecifier UnbuckleSound = new SoundPathSpecifier("/Audio/Effects/unbuckle.ogg");
|
||||
|
||||
/// <summary>
|
||||
/// ID of the alert to show when buckled
|
||||
/// </summary>
|
||||
[DataField("buckledAlertType")]
|
||||
[DataField]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public AlertType BuckledAlertType = AlertType.Buckled;
|
||||
|
||||
/// <summary>
|
||||
/// The sum of the sizes of all the buckled entities in this strap
|
||||
/// </summary>
|
||||
[AutoNetworkedField]
|
||||
[ViewVariables]
|
||||
public int OccupiedSize;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class StrapComponentState : ComponentState
|
||||
{
|
||||
public readonly StrapPosition Position;
|
||||
public readonly float MaxBuckleDistance;
|
||||
public readonly Vector2 BuckleOffsetClamped;
|
||||
public readonly HashSet<NetEntity> BuckledEntities;
|
||||
public readonly int OccupiedSize;
|
||||
|
||||
public StrapComponentState(StrapPosition position, Vector2 offset, HashSet<NetEntity> buckled,
|
||||
float maxBuckleDistance, int occupiedSize)
|
||||
{
|
||||
Position = position;
|
||||
BuckleOffsetClamped = offset;
|
||||
BuckledEntities = buckled;
|
||||
MaxBuckleDistance = maxBuckleDistance;
|
||||
OccupiedSize = occupiedSize;
|
||||
}
|
||||
}
|
||||
|
||||
public enum StrapPosition
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@@ -12,14 +12,12 @@ using Content.Shared.Mobs.Components;
|
||||
using Content.Shared.Movement.Events;
|
||||
using Content.Shared.Popups;
|
||||
using Content.Shared.Pulling.Components;
|
||||
using Content.Shared.Pulling.Events;
|
||||
using Content.Shared.Standing;
|
||||
using Content.Shared.Storage.Components;
|
||||
using Content.Shared.Stunnable;
|
||||
using Content.Shared.Throwing;
|
||||
using Content.Shared.Vehicle.Components;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Events;
|
||||
using Robust.Shared.Utility;
|
||||
@@ -32,7 +30,6 @@ public abstract partial class SharedBuckleSystem
|
||||
{
|
||||
SubscribeLocalEvent<BuckleComponent, ComponentStartup>(OnBuckleComponentStartup);
|
||||
SubscribeLocalEvent<BuckleComponent, ComponentShutdown>(OnBuckleComponentShutdown);
|
||||
SubscribeLocalEvent<BuckleComponent, ComponentGetState>(OnBuckleComponentGetState);
|
||||
SubscribeLocalEvent<BuckleComponent, MoveEvent>(OnBuckleMove);
|
||||
SubscribeLocalEvent<BuckleComponent, InteractHandEvent>(OnBuckleInteractHand);
|
||||
SubscribeLocalEvent<BuckleComponent, GetVerbsEvent<InteractionVerb>>(AddUnbuckleVerb);
|
||||
@@ -58,11 +55,6 @@ public abstract partial class SharedBuckleSystem
|
||||
component.BuckleTime = default;
|
||||
}
|
||||
|
||||
private void OnBuckleComponentGetState(EntityUid uid, BuckleComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new BuckleComponentState(component.Buckled, GetNetEntity(component.BuckledTo), GetNetEntity(component.LastEntityBuckledTo), component.DontCollide);
|
||||
}
|
||||
|
||||
private void OnBuckleMove(EntityUid uid, BuckleComponent component, ref MoveEvent ev)
|
||||
{
|
||||
if (component.BuckledTo is not {} strapUid)
|
||||
@@ -434,7 +426,7 @@ public abstract partial class SharedBuckleSystem
|
||||
if (attemptEvent.Cancelled)
|
||||
return false;
|
||||
|
||||
if (_gameTiming.CurTime < buckleComp.BuckleTime + buckleComp.UnbuckleDelay)
|
||||
if (_gameTiming.CurTime < buckleComp.BuckleTime + buckleComp.Delay)
|
||||
return false;
|
||||
|
||||
if (!_interaction.InRangeUnobstructed(userUid, strapUid, buckleComp.Range, popup: true))
|
||||
|
||||
@@ -7,7 +7,6 @@ using Content.Shared.Interaction;
|
||||
using Content.Shared.Storage;
|
||||
using Content.Shared.Verbs;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Buckle;
|
||||
|
||||
@@ -19,9 +18,6 @@ public abstract partial class SharedBuckleSystem
|
||||
SubscribeLocalEvent<StrapComponent, ComponentShutdown>(OnStrapShutdown);
|
||||
SubscribeLocalEvent<StrapComponent, ComponentRemove>((_, c, _) => StrapRemoveAll(c));
|
||||
|
||||
SubscribeLocalEvent<StrapComponent, ComponentGetState>(OnStrapGetState);
|
||||
SubscribeLocalEvent<StrapComponent, ComponentHandleState>(OnStrapHandleState);
|
||||
|
||||
SubscribeLocalEvent<StrapComponent, EntInsertedIntoContainerMessage>(OnStrapEntModifiedFromContainer);
|
||||
SubscribeLocalEvent<StrapComponent, EntRemovedFromContainerMessage>(OnStrapEntModifiedFromContainer);
|
||||
SubscribeLocalEvent<StrapComponent, GetVerbsEvent<InteractionVerb>>(AddStrapVerbs);
|
||||
@@ -50,24 +46,6 @@ public abstract partial class SharedBuckleSystem
|
||||
StrapRemoveAll(component);
|
||||
}
|
||||
|
||||
private void OnStrapGetState(EntityUid uid, StrapComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new StrapComponentState(component.Position, component.BuckleOffset, GetNetEntitySet(component.BuckledEntities), component.MaxBuckleDistance, component.OccupiedSize);
|
||||
}
|
||||
|
||||
private void OnStrapHandleState(EntityUid uid, StrapComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not StrapComponentState state)
|
||||
return;
|
||||
|
||||
component.Position = state.Position;
|
||||
component.BuckleOffsetUnclamped = state.BuckleOffsetClamped;
|
||||
component.BuckledEntities.Clear();
|
||||
component.BuckledEntities.UnionWith(EnsureEntitySet<StrapComponent>(state.BuckledEntities, uid));
|
||||
component.MaxBuckleDistance = state.MaxBuckleDistance;
|
||||
component.OccupiedSize = state.OccupiedSize;
|
||||
}
|
||||
|
||||
private void OnStrapEntModifiedFromContainer(EntityUid uid, StrapComponent component, ContainerModifiedMessage message)
|
||||
{
|
||||
if (_gameTiming.ApplyingState)
|
||||
|
||||
@@ -65,7 +65,7 @@ public abstract partial class SharedBuckleSystem : EntitySystem
|
||||
|| !Resolve(buckleUid, ref buckleComp, false))
|
||||
return;
|
||||
|
||||
_transform.SetCoordinates(buckleUid, new EntityCoordinates(strapUid, strapComp.BuckleOffset));
|
||||
_transform.SetCoordinates(buckleUid, new EntityCoordinates(strapUid, strapComp.BuckleOffsetClamped));
|
||||
|
||||
var buckleTransform = Transform(buckleUid);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user