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

Move PlaceableSurfaceComponent usages to PlaceableSurfaceSystem #28384

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
29 changes: 25 additions & 4 deletions Content.Shared/Placeable/PlaceableSurfaceSystem.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
using System.Numerics;
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Storage;
using Content.Shared.Storage.Components;

namespace Content.Shared.Placeable;

public sealed class PlaceableSurfaceSystem : EntitySystem
{
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<PlaceableSurfaceComponent, AfterInteractUsingEvent>(OnAfterInteractUsing);
SubscribeLocalEvent<PlaceableSurfaceComponent, StorageInteractUsingAttemptEvent>(OnStorageInteractUsingAttempt);
SubscribeLocalEvent<PlaceableSurfaceComponent, StorageAfterOpenEvent>(OnStorageAfterOpen);
SubscribeLocalEvent<PlaceableSurfaceComponent, StorageAfterCloseEvent>(OnStorageAfterClose);
}

public void SetPlaceable(EntityUid uid, bool isPlaceable, PlaceableSurfaceComponent? surface = null)
{
if (!Resolve(uid, ref surface, false))
return;

if (surface.IsPlaceable == isPlaceable)
return;

surface.IsPlaceable = isPlaceable;
Dirty(uid, surface);
}
Expand Down Expand Up @@ -59,11 +67,24 @@ private void OnAfterInteractUsing(EntityUid uid, PlaceableSurfaceComponent surfa
if (!_handsSystem.TryDrop(args.User, args.Used))
return;

if (surface.PlaceCentered)
Transform(args.Used).LocalPosition = Transform(uid).LocalPosition + surface.PositionOffset;
else
Transform(args.Used).Coordinates = args.ClickLocation;
_transformSystem.SetCoordinates(args.Used,
surface.PlaceCentered ? Transform(uid).Coordinates.Offset(surface.PositionOffset) : args.ClickLocation);

args.Handled = true;
}

private void OnStorageInteractUsingAttempt(Entity<PlaceableSurfaceComponent> ent, ref StorageInteractUsingAttemptEvent args)
{
args.Cancelled = true;
}

private void OnStorageAfterOpen(Entity<PlaceableSurfaceComponent> ent, ref StorageAfterOpenEvent args)
{
SetPlaceable(ent.Owner, true, ent.Comp);
metalgearsloth marked this conversation as resolved.
Show resolved Hide resolved
}

private void OnStorageAfterClose(Entity<PlaceableSurfaceComponent> ent, ref StorageAfterCloseEvent args)
{
SetPlaceable(ent.Owner, false, ent.Comp);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,6 @@ private void ModifyComponents(EntityUid uid, SharedEntityStorageComponent? compo
}
}

if (TryComp<PlaceableSurfaceComponent>(uid, out var surface))
_placeableSurface.SetPlaceable(uid, component.Open, surface);

_appearance.SetData(uid, StorageVisuals.Open, component.Open);
_appearance.SetData(uid, StorageVisuals.HasContents, component.Contents.ContainedEntities.Count > 0);
}
Expand Down
4 changes: 3 additions & 1 deletion Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,9 @@ private void OnInteractUsing(EntityUid uid, StorageComponent storageComp, Intera
if (args.Handled || !CanInteract(args.User, (uid, storageComp), storageComp.ClickInsert, false))
return;

if (HasComp<PlaceableSurfaceComponent>(uid))
var attemptEv = new StorageInteractUsingAttemptEvent();
RaiseLocalEvent(uid, ref attemptEv);
if (attemptEv.Cancelled)
return;

PlayerInsertHeldEntity((uid, storageComp), args.User);
Expand Down
3 changes: 3 additions & 0 deletions Content.Shared/Storage/StorageComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ public AnimateInsertingEntitiesEvent(NetEntity storage, List<NetEntity> storedEn
[ByRefEvent]
public record struct StorageInteractAttemptEvent(bool Silent, bool Cancelled = false);

[ByRefEvent]
public record struct StorageInteractUsingAttemptEvent(bool Cancelled = false);

[NetSerializable]
[Serializable]
public enum StorageVisuals : byte
Expand Down
Loading