Skip to content

Commit

Permalink
Storage CanInsert() tweaks (space-wizards#21623)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElectroJr authored Nov 13, 2023
1 parent dc5739a commit eb0c86f
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 155 deletions.
6 changes: 3 additions & 3 deletions Content.Client/Storage/Systems/StorageSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public override void Initialize()
SubscribeNetworkEvent<AnimateInsertingEntitiesEvent>(HandleAnimatingInsertingEntities);
}

public override void UpdateUI(EntityUid uid, StorageComponent component)
public override void UpdateUI(Entity<StorageComponent?> entity)
{
// Should we wrap this in some prediction call maybe?
StorageUpdated?.Invoke(uid, component);
if (Resolve(entity.Owner, ref entity.Comp))
StorageUpdated?.Invoke(entity.Owner, entity.Comp);
}

/// <inheritdoc />
Expand Down
19 changes: 1 addition & 18 deletions Content.Server/Item/ItemSystem.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
using Content.Server.Storage.Components;
using Content.Server.Storage.EntitySystems;
using Content.Shared.Item;
using Content.Shared.Stacks;
using Content.Shared.Storage;
using Content.Shared.Item;

namespace Content.Server.Item;

public sealed class ItemSystem : SharedItemSystem
{
[Dependency] private readonly StorageSystem _storage = default!;

protected override void OnStackCountChanged(EntityUid uid, ItemComponent component, StackCountChangedEvent args)
{
base.OnStackCountChanged(uid, component, args);

if (!Container.TryGetContainingContainer(uid, out var container) ||
!TryComp<StorageComponent>(container.Owner, out var storage))
return;

_storage.RecalculateStorageUsed(container.Owner, storage);
_storage.UpdateUI(container.Owner, storage);
}
}
11 changes: 0 additions & 11 deletions Content.Server/Stack/StackSystem.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using Content.Server.Storage.EntitySystems;
using Content.Shared.Popups;
using Content.Shared.Stacks;
using Content.Shared.Storage;
using Content.Shared.Verbs;
using JetBrains.Annotations;
using Robust.Server.Containers;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;

Expand All @@ -17,8 +14,6 @@ namespace Content.Server.Stack
[UsedImplicitly]
public sealed class StackSystem : SharedStackSystem
{
[Dependency] private readonly ContainerSystem _container = default!;
[Dependency] private readonly StorageSystem _storage = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;

public static readonly int[] DefaultSplitAmounts = { 1, 5, 10, 20, 30, 50 };
Expand Down Expand Up @@ -165,12 +160,6 @@ private void UserSplit(EntityUid uid, EntityUid userUid, int amount,
if (Split(uid, amount, userTransform.Coordinates, stack) is not {} split)
return;

if (_container.TryGetContainingContainer(uid, out var container) &&
TryComp<StorageComponent>(container.Owner, out var storage))
{
_storage.UpdateUI(container.Owner, storage);
}

Hands.PickupOrDrop(userUid, split);

Popup.PopupCursor(Loc.GetString("comp-stack-split"), userUid);
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Storage/EntitySystems/StorageSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private void OnBoundUIClosed(EntityUid uid, StorageComponent storageComp, BoundU
if (!_uiSystem.IsUiOpen(uid, args.UiKey))
{
storageComp.IsUiOpen = false;
UpdateStorageVisualization(uid, storageComp);
UpdateAppearance((uid, storageComp, null));

if (storageComp.StorageCloseSound is not null)
Audio.Play(storageComp.StorageCloseSound, Filter.Pvs(uid, entityManager: EntityManager), uid, true, storageComp.StorageCloseSound.Params);
Expand Down
14 changes: 14 additions & 0 deletions Content.Shared/Hands/EntitySystems/SharedHandsSystem.Drop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ protected virtual void HandleEntityRemoved(EntityUid uid, HandsComponent hands,
RaiseLocalEvent(uid, didUnequip);
}

/// <summary>
/// Checks whether an entity can drop a given entity. Will return false if they are not holding the entity.
/// </summary>
public bool CanDrop(EntityUid uid, EntityUid entity, HandsComponent? handsComp = null, bool checkActionBlocker = true)
{
if (!Resolve(uid, ref handsComp))
return false;

if (!IsHolding(uid, entity, out var hand, handsComp))
return false;

return CanDropHeld(uid, hand, checkActionBlocker);
}

/// <summary>
/// Checks if the contents of a hand is able to be removed from its container.
/// </summary>
Expand Down
7 changes: 0 additions & 7 deletions Content.Shared/Item/SharedItemSystem.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Content.Shared.Hands.EntitySystems;
using Content.Shared.Interaction;
using Content.Shared.Stacks;
using Content.Shared.Verbs;
using Content.Shared.Examine;
using JetBrains.Annotations;
Expand All @@ -22,7 +21,6 @@ public override void Initialize()
base.Initialize();
SubscribeLocalEvent<ItemComponent, GetVerbsEvent<InteractionVerb>>(AddPickupVerb);
SubscribeLocalEvent<ItemComponent, InteractHandEvent>(OnHandInteract, before: new []{typeof(SharedItemSystem)});
SubscribeLocalEvent<ItemComponent, StackCountChangedEvent>(OnStackCountChanged);

SubscribeLocalEvent<ItemComponent, ComponentGetState>(OnGetState);
SubscribeLocalEvent<ItemComponent, ComponentHandleState>(OnHandleState);
Expand Down Expand Up @@ -80,11 +78,6 @@ private void OnHandInteract(EntityUid uid, ItemComponent component, InteractHand
args.Handled = _handsSystem.TryPickup(args.User, uid, animateUser: false);
}

protected virtual void OnStackCountChanged(EntityUid uid, ItemComponent component, StackCountChangedEvent args)
{

}

private void OnHandleState(EntityUid uid, ItemComponent component, ref ComponentHandleState args)
{
if (args.Current is not ItemComponentState state)
Expand Down
Loading

0 comments on commit eb0c86f

Please sign in to comment.