diff --git a/Assets/Script/InventoryManager.cs b/Assets/Script/InventoryManager.cs index 236e805..5a9daa0 100644 --- a/Assets/Script/InventoryManager.cs +++ b/Assets/Script/InventoryManager.cs @@ -23,6 +23,9 @@ public class InventoryManager : MonoBehaviour private Vector3 defaultPos; private Vector2Int selectorPos; + private Dictionary preSpawnedTree = new Dictionary(); + private int[] savedItems = new int[15]; + private void Start() { @@ -63,6 +66,8 @@ public class InventoryManager : MonoBehaviour if (Input.GetKeyDown(KeyCode.R)) { ClearBoard(); + PlacePreSpawnedTrees(); + GiveItemsBack(); GetComponent().WinUI.SetActive(false); GetComponent().UpdateMissionText(); turnCount.text = "Turn: 01"; @@ -131,7 +136,6 @@ public class InventoryManager : MonoBehaviour private void PlaceTree(TreeItem item, int index) { - print("Index: " + index); Vector2Int plotPos = GetPlotPositionByIndex(index); plots[index].treePlaced = item.type; @@ -162,12 +166,23 @@ public class InventoryManager : MonoBehaviour } if (index != plots.Length) + { PlaceTree(tree, index); + preSpawnedTree.Add(index, tree.type); + } else i--; } } + private void PlacePreSpawnedTrees() + { + foreach (KeyValuePair item in preSpawnedTree) + { + PlaceTree(items[(int)item.Value - 1], item.Key); + } + } + private void DeleteTreeAt(int index) { Vector2Int plotPos = GetPlotPositionByIndex(index); @@ -519,6 +534,23 @@ public class InventoryManager : MonoBehaviour return false; } + public void SaveUserItems() + { + for (int i = 0; i < 15; i++) + { + savedItems[i] = items[i].count; + } + } + + private void GiveItemsBack() + { + for (int i = 0; i < 15; i++) + { + items[i].count = savedItems[i]; + } + UpdateUI(); + } + public void ClearBoard() { for (int i = 0; i < 25; i++) diff --git a/Assets/Script/Mission.cs b/Assets/Script/Mission.cs index f879932..90cd8ce 100644 --- a/Assets/Script/Mission.cs +++ b/Assets/Script/Mission.cs @@ -88,6 +88,7 @@ public class Mission : MonoBehaviour { } } manager.UpdateUI(); + manager.SaveUserItems(); } public string GetMissionText()