Power Cell Refactor (#5943)
Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
This commit is contained in:
@@ -75,12 +75,10 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
public EntityWhitelist? Whitelist;
|
||||
|
||||
[DataField("insertSound")]
|
||||
public SoundSpecifier? InsertSound;
|
||||
// maybe default to /Audio/Weapons/Guns/MagIn/batrifle_magin.ogg ??
|
||||
public SoundSpecifier InsertSound = new SoundPathSpecifier("/Audio/Weapons/Guns/MagIn/revolver_magin.ogg");
|
||||
|
||||
[DataField("ejectSound")]
|
||||
public SoundSpecifier? EjectSound;
|
||||
// maybe default to /Audio/Machines/id_swipe.ogg?
|
||||
public SoundSpecifier EjectSound = new SoundPathSpecifier("/Audio/Weapons/Guns/MagOut/revolver_magout.ogg");
|
||||
|
||||
/// <summary>
|
||||
/// Options used for playing the insert/eject sounds.
|
||||
@@ -98,6 +96,9 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
[DataField("name")]
|
||||
public string Name = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The entity prototype that is spawned into this slot on map init.
|
||||
/// </summary>
|
||||
[DataField("startingItem", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string? StartingItem;
|
||||
|
||||
@@ -136,15 +137,15 @@ namespace Content.Shared.Containers.ItemSlots
|
||||
public bool EjectOnUse = false;
|
||||
|
||||
/// <summary>
|
||||
/// Override the insert verb text. Defaults to [insert category] -> [item-name]. If not null, the verb will
|
||||
/// not be given a category.
|
||||
/// Override the insert verb text. Defaults to using the slot's name (if specified) or the name of the
|
||||
/// targeted item. If specified, the verb will not be added to the default insert verb category.
|
||||
/// </summary>
|
||||
[DataField("insertVerbText")]
|
||||
public string? InsertVerbText;
|
||||
|
||||
/// <summary>
|
||||
/// Override the insert verb text. Defaults to [eject category] -> [item-name]. If not null, the verb will
|
||||
/// not be given a category.
|
||||
/// Override the eject verb text. Defaults to using the slot's name (if specified) or the name of the
|
||||
/// targeted item. If specified, the verb will not be added to the default eject verb category
|
||||
/// </summary>
|
||||
[DataField("ejectVerbText")]
|
||||
public string? EjectVerbText;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user