Make item slot containers nullable (#6198)
This commit is contained in:
@@ -43,7 +43,7 @@ namespace Content.Server.Cabinet
|
|||||||
private void OnComponentStartup(EntityUid uid, ItemCabinetComponent cabinet, ComponentStartup args)
|
private void OnComponentStartup(EntityUid uid, ItemCabinetComponent cabinet, ComponentStartup args)
|
||||||
{
|
{
|
||||||
UpdateAppearance(uid, cabinet);
|
UpdateAppearance(uid, cabinet);
|
||||||
_itemSlotsSystem.SetLock(uid, cabinet.CabinetSlot.ID, !cabinet.Opened);
|
_itemSlotsSystem.SetLock(uid, cabinet.CabinetSlot, !cabinet.Opened);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateAppearance(EntityUid uid,
|
private void UpdateAppearance(EntityUid uid,
|
||||||
@@ -105,7 +105,7 @@ namespace Content.Server.Cabinet
|
|||||||
|
|
||||||
cabinet.Opened = !cabinet.Opened;
|
cabinet.Opened = !cabinet.Opened;
|
||||||
SoundSystem.Play(Filter.Pvs(uid), cabinet.DoorSound.GetSound(), uid, AudioHelpers.WithVariation(0.15f));
|
SoundSystem.Play(Filter.Pvs(uid), cabinet.DoorSound.GetSound(), uid, AudioHelpers.WithVariation(0.15f));
|
||||||
_itemSlotsSystem.SetLock(uid, cabinet.CabinetSlot.ID, !cabinet.Opened);
|
_itemSlotsSystem.SetLock(uid, cabinet.CabinetSlot, !cabinet.Opened);
|
||||||
|
|
||||||
UpdateAppearance(uid, cabinet);
|
UpdateAppearance(uid, cabinet);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace Content.Server.Containers
|
|||||||
foreach (var slot in component.Slots.Values)
|
foreach (var slot in component.Slots.Values)
|
||||||
{
|
{
|
||||||
if (slot.EjectOnDeconstruct && slot.Item != null)
|
if (slot.EjectOnDeconstruct && slot.Item != null)
|
||||||
slot.ContainerSlot.Remove(slot.Item.Value);
|
slot.ContainerSlot?.Remove(slot.Item.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ namespace Content.Shared.Containers.ItemSlots
|
|||||||
public string? EjectVerbText;
|
public string? EjectVerbText;
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public ContainerSlot ContainerSlot = default!;
|
public ContainerSlot? ContainerSlot = default!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// If this slot belongs to some de-constructible component, should the item inside the slot be ejected upon
|
/// If this slot belongs to some de-constructible component, should the item inside the slot be ejected upon
|
||||||
@@ -192,10 +192,10 @@ namespace Content.Shared.Containers.ItemSlots
|
|||||||
[DataField("swap")]
|
[DataField("swap")]
|
||||||
public bool Swap = true;
|
public bool Swap = true;
|
||||||
|
|
||||||
public string ID => ContainerSlot.ID;
|
public string? ID => ContainerSlot?.ID;
|
||||||
|
|
||||||
// Convenience properties
|
// Convenience properties
|
||||||
public bool HasItem => ContainerSlot.ContainedEntity != null;
|
public bool HasItem => ContainerSlot?.ContainedEntity != null;
|
||||||
public EntityUid? Item => ContainerSlot.ContainedEntity;
|
public EntityUid? Item => ContainerSlot?.ContainedEntity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ namespace Content.Shared.Containers.ItemSlots
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
var item = EntityManager.SpawnEntity(slot.StartingItem, EntityManager.GetComponent<TransformComponent>(itemSlots.Owner).Coordinates);
|
var item = EntityManager.SpawnEntity(slot.StartingItem, EntityManager.GetComponent<TransformComponent>(itemSlots.Owner).Coordinates);
|
||||||
slot.ContainerSlot.Insert(item);
|
slot.ContainerSlot?.Insert(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,6 +95,9 @@ namespace Content.Shared.Containers.ItemSlots
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void RemoveItemSlot(EntityUid uid, ItemSlot slot, ItemSlotsComponent? itemSlots = null)
|
public void RemoveItemSlot(EntityUid uid, ItemSlot slot, ItemSlotsComponent? itemSlots = null)
|
||||||
{
|
{
|
||||||
|
if (slot.ContainerSlot == null)
|
||||||
|
return;
|
||||||
|
|
||||||
slot.ContainerSlot.Shutdown();
|
slot.ContainerSlot.Shutdown();
|
||||||
|
|
||||||
// Don't log missing resolves. when an entity has all of its components removed, the ItemSlotsComponent may
|
// Don't log missing resolves. when an entity has all of its components removed, the ItemSlotsComponent may
|
||||||
@@ -102,7 +105,7 @@ namespace Content.Shared.Containers.ItemSlots
|
|||||||
if (!Resolve(uid, ref itemSlots, logMissing: false))
|
if (!Resolve(uid, ref itemSlots, logMissing: false))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
itemSlots.Slots.Remove(slot.ID);
|
itemSlots.Slots.Remove(slot.ContainerSlot.ID);
|
||||||
|
|
||||||
if (itemSlots.Slots.Count == 0)
|
if (itemSlots.Slots.Count == 0)
|
||||||
EntityManager.RemoveComponent(uid, itemSlots);
|
EntityManager.RemoveComponent(uid, itemSlots);
|
||||||
@@ -193,7 +196,7 @@ namespace Content.Shared.Containers.ItemSlots
|
|||||||
/// Useful for predicted interactions</param>
|
/// Useful for predicted interactions</param>
|
||||||
private void Insert(EntityUid uid, ItemSlot slot, EntityUid item, EntityUid? user, bool excludeUserAudio = false)
|
private void Insert(EntityUid uid, ItemSlot slot, EntityUid item, EntityUid? user, bool excludeUserAudio = false)
|
||||||
{
|
{
|
||||||
slot.ContainerSlot.Insert(item);
|
slot.ContainerSlot?.Insert(item);
|
||||||
// ContainerSlot automatically raises a directed EntInsertedIntoContainerMessage
|
// ContainerSlot automatically raises a directed EntInsertedIntoContainerMessage
|
||||||
|
|
||||||
PlaySound(uid, slot.InsertSound, slot.SoundOptions, excludeUserAudio ? user : null);
|
PlaySound(uid, slot.InsertSound, slot.SoundOptions, excludeUserAudio ? user : null);
|
||||||
@@ -242,7 +245,7 @@ namespace Content.Shared.Containers.ItemSlots
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return slot.ContainerSlot.CanInsertIfEmpty(usedUid, EntityManager);
|
return slot.ContainerSlot?.CanInsertIfEmpty(usedUid, EntityManager) ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -305,7 +308,7 @@ namespace Content.Shared.Containers.ItemSlots
|
|||||||
if (slot.Locked || slot.Item == null)
|
if (slot.Locked || slot.Item == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return slot.ContainerSlot.CanRemove(slot.Item.Value, EntityManager);
|
return slot.ContainerSlot?.CanRemove(slot.Item.Value, EntityManager) ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -316,7 +319,7 @@ namespace Content.Shared.Containers.ItemSlots
|
|||||||
/// Useful for predicted interactions</param>
|
/// Useful for predicted interactions</param>
|
||||||
private void Eject(EntityUid uid, ItemSlot slot, EntityUid item, EntityUid? user, bool excludeUserAudio = false)
|
private void Eject(EntityUid uid, ItemSlot slot, EntityUid item, EntityUid? user, bool excludeUserAudio = false)
|
||||||
{
|
{
|
||||||
slot.ContainerSlot.Remove(item);
|
slot.ContainerSlot?.Remove(item);
|
||||||
// ContainerSlot automatically raises a directed EntRemovedFromContainerMessage
|
// ContainerSlot automatically raises a directed EntRemovedFromContainerMessage
|
||||||
|
|
||||||
PlaySound(uid, slot.EjectSound, slot.SoundOptions, excludeUserAudio ? user : null);
|
PlaySound(uid, slot.EjectSound, slot.SoundOptions, excludeUserAudio ? user : null);
|
||||||
@@ -520,14 +523,17 @@ namespace Content.Shared.Containers.ItemSlots
|
|||||||
if (!itemSlots.Slots.TryGetValue(id, out var slot))
|
if (!itemSlots.Slots.TryGetValue(id, out var slot))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
SetLock(itemSlots, slot, locked);
|
SetLock(uid, slot, locked, itemSlots);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Lock an item slot. This stops items from being inserted into or ejected from this slot.
|
/// Lock an item slot. This stops items from being inserted into or ejected from this slot.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SetLock(ItemSlotsComponent itemSlots, ItemSlot slot, bool locked)
|
public void SetLock(EntityUid uid, ItemSlot slot, bool locked, ItemSlotsComponent? itemSlots = null)
|
||||||
{
|
{
|
||||||
|
if (!Resolve(uid, ref itemSlots))
|
||||||
|
return;
|
||||||
|
|
||||||
slot.Locked = locked;
|
slot.Locked = locked;
|
||||||
itemSlots.Dirty();
|
itemSlots.Dirty();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user