Make buckle mint (#32370)
- Fix the unbuckle mispredicts. - Fix unbuckle offset existing. - Fix interaction range not aligning with interactionoutline system.
This commit is contained in:
@@ -15,7 +15,6 @@ internal sealed class BuckleSystem : SharedBuckleSystem
|
|||||||
{
|
{
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
|
|
||||||
SubscribeLocalEvent<BuckleComponent, ComponentHandleState>(OnHandleState);
|
|
||||||
SubscribeLocalEvent<BuckleComponent, AppearanceChangeEvent>(OnAppearanceChange);
|
SubscribeLocalEvent<BuckleComponent, AppearanceChangeEvent>(OnAppearanceChange);
|
||||||
SubscribeLocalEvent<StrapComponent, MoveEvent>(OnStrapMoveEvent);
|
SubscribeLocalEvent<StrapComponent, MoveEvent>(OnStrapMoveEvent);
|
||||||
}
|
}
|
||||||
@@ -57,21 +56,6 @@ internal sealed class BuckleSystem : SharedBuckleSystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnHandleState(Entity<BuckleComponent> ent, ref ComponentHandleState args)
|
|
||||||
{
|
|
||||||
if (args.Current is not BuckleState state)
|
|
||||||
return;
|
|
||||||
|
|
||||||
ent.Comp.DontCollide = state.DontCollide;
|
|
||||||
ent.Comp.BuckleTime = state.BuckleTime;
|
|
||||||
var strapUid = EnsureEntity<BuckleComponent>(state.BuckledTo, ent);
|
|
||||||
|
|
||||||
SetBuckledTo(ent, strapUid == null ? null : new (strapUid.Value, null));
|
|
||||||
|
|
||||||
var (uid, component) = ent;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnAppearanceChange(EntityUid uid, BuckleComponent component, ref AppearanceChangeEvent args)
|
private void OnAppearanceChange(EntityUid uid, BuckleComponent component, ref AppearanceChangeEvent args)
|
||||||
{
|
{
|
||||||
if (!TryComp<RotationVisualsComponent>(uid, out var rotVisuals))
|
if (!TryComp<RotationVisualsComponent>(uid, out var rotVisuals))
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace Content.Shared.Buckle.Components;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// This component allows an entity to be buckled to an entity with a <see cref="StrapComponent"/>.
|
/// This component allows an entity to be buckled to an entity with a <see cref="StrapComponent"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[RegisterComponent, NetworkedComponent]
|
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, AutoGenerateComponentPause]
|
||||||
[Access(typeof(SharedBuckleSystem))]
|
[Access(typeof(SharedBuckleSystem))]
|
||||||
public sealed partial class BuckleComponent : Component
|
public sealed partial class BuckleComponent : Component
|
||||||
{
|
{
|
||||||
@@ -20,7 +20,7 @@ public sealed partial class BuckleComponent : Component
|
|||||||
/// across a table two tiles away" problem.
|
/// across a table two tiles away" problem.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField]
|
[DataField]
|
||||||
public float Range = SharedInteractionSystem.InteractionRange / 1.4f;
|
public float Range = SharedInteractionSystem.InteractionRange;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// True if the entity is buckled, false otherwise.
|
/// True if the entity is buckled, false otherwise.
|
||||||
@@ -31,7 +31,7 @@ public sealed partial class BuckleComponent : Component
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether or not collisions should be possible with the entity we are strapped to
|
/// Whether or not collisions should be possible with the entity we are strapped to
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField]
|
[DataField, AutoNetworkedField]
|
||||||
public bool DontCollide;
|
public bool DontCollide;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -50,13 +50,13 @@ public sealed partial class BuckleComponent : Component
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The time that this entity buckled at.
|
/// The time that this entity buckled at.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
|
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoPausedField, AutoNetworkedField]
|
||||||
public TimeSpan? BuckleTime;
|
public TimeSpan? BuckleTime;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The strap that this component is buckled to.
|
/// The strap that this component is buckled to.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField]
|
[DataField, AutoNetworkedField]
|
||||||
public EntityUid? BuckledTo;
|
public EntityUid? BuckledTo;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -72,14 +72,6 @@ public sealed partial class BuckleComponent : Component
|
|||||||
[ViewVariables] public int? OriginalDrawDepth;
|
[ViewVariables] public int? OriginalDrawDepth;
|
||||||
}
|
}
|
||||||
|
|
||||||
[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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public sealed partial class UnbuckleAlertEvent : BaseAlertEvent;
|
public sealed partial class UnbuckleAlertEvent : BaseAlertEvent;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public sealed partial class StrapComponent : Component
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The entities that are currently buckled to this strap.
|
/// The entities that are currently buckled to this strap.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables]
|
[DataField, AutoNetworkedField]
|
||||||
public HashSet<EntityUid> BuckledEntities = new();
|
public HashSet<EntityUid> BuckledEntities = new();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -61,12 +61,6 @@ public sealed partial class StrapComponent : Component
|
|||||||
[DataField, AutoNetworkedField]
|
[DataField, AutoNetworkedField]
|
||||||
public bool Enabled = true;
|
public bool Enabled = true;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// You can specify the offset the entity will have after unbuckling.
|
|
||||||
/// </summary>
|
|
||||||
[DataField]
|
|
||||||
public Vector2 UnbuckleOffset = Vector2.Zero;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The sound to be played when a mob is buckled
|
/// The sound to be played when a mob is buckled
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -58,13 +58,6 @@ public abstract partial class SharedBuckleSystem
|
|||||||
{
|
{
|
||||||
BuckleDoafterEarly((uid, comp), ev.Event, ev);
|
BuckleDoafterEarly((uid, comp), ev.Event, ev);
|
||||||
});
|
});
|
||||||
|
|
||||||
SubscribeLocalEvent<BuckleComponent, ComponentGetState>(OnGetState);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnGetState(Entity<BuckleComponent> ent, ref ComponentGetState args)
|
|
||||||
{
|
|
||||||
args.State = new BuckleState(GetNetEntity(ent.Comp.BuckledTo), ent.Comp.DontCollide, ent.Comp.BuckleTime);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnBuckleComponentShutdown(Entity<BuckleComponent> ent, ref ComponentShutdown args)
|
private void OnBuckleComponentShutdown(Entity<BuckleComponent> ent, ref ComponentShutdown args)
|
||||||
@@ -196,11 +189,15 @@ public abstract partial class SharedBuckleSystem
|
|||||||
protected void SetBuckledTo(Entity<BuckleComponent> buckle, Entity<StrapComponent?>? strap)
|
protected void SetBuckledTo(Entity<BuckleComponent> buckle, Entity<StrapComponent?>? strap)
|
||||||
{
|
{
|
||||||
if (TryComp(buckle.Comp.BuckledTo, out StrapComponent? old))
|
if (TryComp(buckle.Comp.BuckledTo, out StrapComponent? old))
|
||||||
|
{
|
||||||
old.BuckledEntities.Remove(buckle);
|
old.BuckledEntities.Remove(buckle);
|
||||||
|
Dirty(buckle.Comp.BuckledTo.Value, old);
|
||||||
|
}
|
||||||
|
|
||||||
if (strap is {} strapEnt && Resolve(strapEnt.Owner, ref strapEnt.Comp))
|
if (strap is {} strapEnt && Resolve(strapEnt.Owner, ref strapEnt.Comp))
|
||||||
{
|
{
|
||||||
strapEnt.Comp.BuckledEntities.Add(buckle);
|
strapEnt.Comp.BuckledEntities.Add(buckle);
|
||||||
|
Dirty(strapEnt);
|
||||||
_alerts.ShowAlert(buckle, strapEnt.Comp.BuckledAlertType);
|
_alerts.ShowAlert(buckle, strapEnt.Comp.BuckledAlertType);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -463,13 +460,17 @@ public abstract partial class SharedBuckleSystem
|
|||||||
|
|
||||||
if (buckleXform.ParentUid == strap.Owner && !Terminating(buckleXform.ParentUid))
|
if (buckleXform.ParentUid == strap.Owner && !Terminating(buckleXform.ParentUid))
|
||||||
{
|
{
|
||||||
_container.AttachParentToContainerOrGrid((buckle, buckleXform));
|
_transform.PlaceNextTo((buckle, buckleXform), (strap.Owner, oldBuckledXform));
|
||||||
|
buckleXform.ActivelyLerping = false;
|
||||||
|
|
||||||
var oldBuckledToWorldRot = _transform.GetWorldRotation(strap);
|
var oldBuckledToWorldRot = _transform.GetWorldRotation(strap);
|
||||||
_transform.SetWorldRotation(buckleXform, oldBuckledToWorldRot);
|
_transform.SetWorldRotationNoLerp((buckle, buckleXform), oldBuckledToWorldRot);
|
||||||
|
|
||||||
if (strap.Comp.UnbuckleOffset != Vector2.Zero)
|
// TODO: This is doing 4 moveevents this is why I left the warning in, if you're going to remove it make it only do 1 moveevent.
|
||||||
buckleXform.Coordinates = oldBuckledXform.Coordinates.Offset(strap.Comp.UnbuckleOffset);
|
if (strap.Comp.BuckleOffset != Vector2.Zero)
|
||||||
|
{
|
||||||
|
buckleXform.Coordinates = oldBuckledXform.Coordinates.Offset(strap.Comp.BuckleOffset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_rotationVisuals.ResetHorizontalAngle(buckle.Owner);
|
_rotationVisuals.ResetHorizontalAngle(buckle.Owner);
|
||||||
|
|||||||
@@ -54,7 +54,6 @@
|
|||||||
position: Down
|
position: Down
|
||||||
rotation: -90
|
rotation: -90
|
||||||
buckleOffset: "0,0.15"
|
buckleOffset: "0,0.15"
|
||||||
unbuckleOffset: "0,0.15"
|
|
||||||
buckleOnInteractHand: False
|
buckleOnInteractHand: False
|
||||||
- type: Appearance
|
- type: Appearance
|
||||||
- type: GenericVisualizer
|
- type: GenericVisualizer
|
||||||
|
|||||||
Reference in New Issue
Block a user