Power Cell Refactor (#5943)

Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
This commit is contained in:
Leon Friedrich
2022-01-05 17:20:25 +13:00
committed by GitHub
parent 4eddefdda1
commit 0aa4f9efbe
37 changed files with 673 additions and 987 deletions

View File

@@ -242,10 +242,7 @@ namespace Content.Shared.Containers.ItemSlots
return false;
}
// We should also check ContainerSlot.CanInsert, but that prevents swapping interactions. Given that
// ContainerSlot.CanInsert gets called when the item is actually inserted anyways, we can just get away with
// fudging CanInsert and not performing those checks.
return true;
return slot.ContainerSlot.CanInsertIfEmpty(usedUid, EntityManager);
}
/// <summary>
@@ -302,6 +299,15 @@ namespace Content.Shared.Containers.ItemSlots
#endregion
#region Eject
public bool CanEject(ItemSlot slot)
{
if (slot.Locked || slot.Item == null)
return false;
return slot.ContainerSlot.CanRemove(slot.Item.Value, EntityManager);
}
/// <summary>
/// Eject an item into a slot. This does not perform checks (e.g., is the slot locked?), so you should
/// probably just use <see cref="TryEject"/> instead.
@@ -324,11 +330,11 @@ namespace Content.Shared.Containers.ItemSlots
{
item = null;
if (slot.Locked || slot.Item == null)
if (!CanEject(slot))
return false;
item = slot.Item;
Eject(uid, slot, item.Value, user, excludeUserAudio);
Eject(uid, slot, item!.Value, user, excludeUserAudio);
return true;
}
@@ -381,7 +387,7 @@ namespace Content.Shared.Containers.ItemSlots
foreach (var slot in itemSlots.Slots.Values)
{
if (slot.Locked || !slot.HasItem)
if (!CanEject(slot))
continue;
if (slot.EjectOnInteract)
@@ -421,7 +427,7 @@ namespace Content.Shared.Containers.ItemSlots
{
foreach (var slot in itemSlots.Slots.Values)
{
if (!slot.EjectOnInteract || slot.Locked || !slot.HasItem)
if (!slot.EjectOnInteract || !CanEject(slot))
continue;
var verbSubject = slot.Name != string.Empty