Skip to content

Commit

Permalink
add storage condition in can contain on attached containers
Browse files Browse the repository at this point in the history
  • Loading branch information
stilnat committed Nov 24, 2023
1 parent ac9d788 commit d78e9bb
Showing 1 changed file with 9 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using SS3D.Logging;
using System.Drawing;
using UnityEditor;
using UnityEditorInternal.Profiling.Memory.Experimental;

namespace SS3D.Systems.Inventory.Containers
{
Expand Down Expand Up @@ -442,8 +443,6 @@ private void AddItemUnchecked(Item item, Vector2Int position)
/// <param name="newItem"> the item to store.</param>
private void AddStoredItem(StoredItem newItem)
{
if ((bool)GetComponents<IStorageCondition>()?.Any(x => !x.CanStore(this, newItem.Item))) return;

_storedItems.Add(newItem);
}

Expand Down Expand Up @@ -474,16 +473,6 @@ private void RemoveStoredItem(int index)
}
}


/// <summary>
/// Adds a stored item without checking any validity
/// <param name="storedItem">The item to store</param>
/// </summary>
public void AddItemUnchecked(StoredItem storedItem)
{
AddItemUnchecked(storedItem.Item, storedItem.Position);
}

/// <summary>
/// Removes an item from the container
/// </summary>
Expand Down Expand Up @@ -635,14 +624,15 @@ private bool CanHoldItem(Item item)
return Items.Count() < Size.x * Size.y;
}

/// <summary>
/// Checks if this item can be stored and fits inside the container
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public bool CanContainItem(Item item)
/// <summary>
/// Checks if this item can be stored and fits inside the container
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public bool CanContainItem(Item item)
{
return CanStoreItem(item) && CanHoldItem(item);
if ((bool)GetComponents<IStorageCondition>()?.Any(x => !x.CanStore(this, item))) return false;
return CanStoreItem(item) && CanHoldItem(item);
}

/// <summary>
Expand Down

0 comments on commit d78e9bb

Please sign in to comment.