Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make buckle mint #32370

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions Content.Client/Buckle/BuckleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<BuckleComponent, ComponentHandleState>(OnHandleState);
SubscribeLocalEvent<BuckleComponent, AppearanceChangeEvent>(OnAppearanceChange);
SubscribeLocalEvent<StrapComponent, MoveEvent>(OnStrapMoveEvent);
}
Expand Down Expand Up @@ -57,21 +56,6 @@ private void OnStrapMoveEvent(EntityUid uid, StrapComponent component, ref MoveE
}
}

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)
{
if (!TryComp<RotationVisualsComponent>(uid, out var rotVisuals))
Expand Down
18 changes: 5 additions & 13 deletions Content.Shared/Buckle/Components/BuckleComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Content.Shared.Buckle.Components;
/// <summary>
/// This component allows an entity to be buckled to an entity with a <see cref="StrapComponent"/>.
/// </summary>
[RegisterComponent, NetworkedComponent]
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState, AutoGenerateComponentPause]
[Access(typeof(SharedBuckleSystem))]
public sealed partial class BuckleComponent : Component
{
Expand All @@ -20,7 +20,7 @@ public sealed partial class BuckleComponent : Component
/// across a table two tiles away" problem.
/// </summary>
[DataField]
public float Range = SharedInteractionSystem.InteractionRange / 1.4f;
public float Range = SharedInteractionSystem.InteractionRange;

/// <summary>
/// True if the entity is buckled, false otherwise.
Expand All @@ -31,7 +31,7 @@ public sealed partial class BuckleComponent : Component
/// <summary>
/// Whether or not collisions should be possible with the entity we are strapped to
/// </summary>
[DataField]
[DataField, AutoNetworkedField]
public bool DontCollide;

/// <summary>
Expand All @@ -50,13 +50,13 @@ public sealed partial class BuckleComponent : Component
/// <summary>
/// The time that this entity buckled at.
/// </summary>
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer))]
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoPausedField, AutoNetworkedField]
public TimeSpan? BuckleTime;

/// <summary>
/// The strap that this component is buckled to.
/// </summary>
[DataField]
[DataField, AutoNetworkedField]
public EntityUid? BuckledTo;

/// <summary>
Expand All @@ -72,14 +72,6 @@ public sealed partial class BuckleComponent : Component
[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;

/// <summary>
Expand Down
8 changes: 1 addition & 7 deletions Content.Shared/Buckle/Components/StrapComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed partial class StrapComponent : Component
/// <summary>
/// The entities that are currently buckled to this strap.
/// </summary>
[ViewVariables]
[DataField, AutoNetworkedField]
public HashSet<EntityUid> BuckledEntities = new();

/// <summary>
Expand Down Expand Up @@ -61,12 +61,6 @@ public sealed partial class StrapComponent : Component
[DataField, AutoNetworkedField]
public bool Enabled = true;

/// <summary>
/// You can specify the offset the entity will have after unbuckling.
/// </summary>
[DataField]
public Vector2 UnbuckleOffset = Vector2.Zero;

/// <summary>
/// The sound to be played when a mob is buckled
/// </summary>
Expand Down
23 changes: 12 additions & 11 deletions Content.Shared/Buckle/SharedBuckleSystem.Buckle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ private void InitializeBuckle()
{
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)
Expand Down Expand Up @@ -196,11 +189,15 @@ public bool IsBuckled(EntityUid uid, BuckleComponent? component = null)
protected void SetBuckledTo(Entity<BuckleComponent> buckle, Entity<StrapComponent?>? strap)
{
if (TryComp(buckle.Comp.BuckledTo, out StrapComponent? old))
{
old.BuckledEntities.Remove(buckle);
Dirty(buckle.Comp.BuckledTo.Value, old);
}

if (strap is {} strapEnt && Resolve(strapEnt.Owner, ref strapEnt.Comp))
{
strapEnt.Comp.BuckledEntities.Add(buckle);
Dirty(strapEnt);
_alerts.ShowAlert(buckle, strapEnt.Comp.BuckledAlertType);
}
else
Expand Down Expand Up @@ -463,13 +460,17 @@ private void Unbuckle(Entity<BuckleComponent> buckle, Entity<StrapComponent> str

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);
_transform.SetWorldRotation(buckleXform, oldBuckledToWorldRot);
_transform.SetWorldRotationNoLerp((buckle, buckleXform), oldBuckledToWorldRot);

if (strap.Comp.UnbuckleOffset != Vector2.Zero)
buckleXform.Coordinates = oldBuckledXform.Coordinates.Offset(strap.Comp.UnbuckleOffset);
// 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.
if (strap.Comp.BuckleOffset != Vector2.Zero)
{
buckleXform.Coordinates = oldBuckledXform.Coordinates.Offset(strap.Comp.BuckleOffset);
}
}

_rotationVisuals.ResetHorizontalAngle(buckle.Owner);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
position: Down
rotation: -90
buckleOffset: "0,0.15"
unbuckleOffset: "0,0.15"
buckleOnInteractHand: False
- type: Appearance
- type: GenericVisualizer
Expand Down
Loading