added when item amount is zero that item gets removed from items Dictionary
This commit is contained in:
parent
6836367207
commit
770de74fbc
2 changed files with 7 additions and 8 deletions
|
|
@ -22,8 +22,8 @@ public class Inventory : MonoBehaviour {
|
||||||
public Item[] startItems;
|
public Item[] startItems;
|
||||||
public const int inventorySpace = 28;
|
public const int inventorySpace = 28;
|
||||||
|
|
||||||
public delegate void onItemChanged();
|
public delegate void OnItemChanged();
|
||||||
public onItemChanged onItemChangedCallback;
|
public OnItemChanged onItemChangedCallback;
|
||||||
|
|
||||||
private void Start() {
|
private void Start() {
|
||||||
items ??= new Dictionary<Item, int>();
|
items ??= new Dictionary<Item, int>();
|
||||||
|
|
@ -38,8 +38,6 @@ public class Inventory : MonoBehaviour {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Log("ASDADADWDASDWD");
|
|
||||||
|
|
||||||
if(!items.ContainsKey(item)) {
|
if(!items.ContainsKey(item)) {
|
||||||
items.Add(item, amount);
|
items.Add(item, amount);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -51,7 +49,11 @@ public class Inventory : MonoBehaviour {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveItem(Item item, int amount) {
|
public void RemoveItem(Item item, int amount) {
|
||||||
|
if(items[item] <= 0) {
|
||||||
|
items.Remove(item);
|
||||||
|
} else {
|
||||||
items.Add(item, -amount);
|
items.Add(item, -amount);
|
||||||
|
}
|
||||||
|
|
||||||
onItemChangedCallback?.Invoke();
|
onItemChangedCallback?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
using System;
|
|
||||||
using Items.TerraformingTools;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
|
||||||
namespace Tiles
|
namespace Tiles
|
||||||
{
|
{
|
||||||
public abstract class BaseTile
|
public abstract class BaseTile
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue