literally half of the game

This commit is contained in:
Sylvia 2026-08-27 04:07:01 -07:00
parent 1590b5faa6
commit b842289076
77 changed files with 11904 additions and 72 deletions

View file

@ -1,20 +1,56 @@
using System;
using System.Collections.Generic;
using TMPro;
using Unity.Mathematics;
using UnityEngine;
public class InventoryManager : MonoBehaviour
{
#region Statication
public static InventoryManager instance;
private void Awake()
{
if (instance != null && instance != this)
{
Destroy(gameObject);
return;
}
DontDestroyOnLoad(this);
instance = this;
}
#endregion
[Serializable]
public class ItemAmount
{
public Item item;
public int amount;
}
public Item[] itemList; //list of all items in the game
public int maxCapacity;
public int currentlyStored;
public Dictionary<Item, int> storedItems = new();
public Item[] itemList;
public int money;
[Header("UI")]
public TextMeshProUGUI moneyUI;
public GameObject inventoryUI;
public InventoryUIObject templateUIObject;
public Transform inventoryGrid;
public Dictionary<Item, InventoryUIObject> allInventoryUIObjects = new();
private void Start()
{
UpdateMoneyUI();
}
public bool RemoveMoney(int change)
{
if (money - change >= 0)
{
money -= change;
UpdateMoneyUI();
return true;
}
return false;
@ -22,6 +58,12 @@ public class InventoryManager : MonoBehaviour
public void AddMoney(int change)
{
money += change;
UpdateMoneyUI();
}
public void UpdateMoneyUI()
{
moneyUI.text = $"Money: {money}";
}
public int AddItem(Item itemToAdd, int amount = 1)
@ -36,6 +78,8 @@ public class InventoryManager : MonoBehaviour
{
storedItems[itemToAdd] += amount;
currentlyStored += amount;
UpdateTaskTracker();
Debug.Log($"ADDED ALL {itemToAdd.itemName}");
return 0;
}
//return the amount that wasn't able to be stored.
@ -43,11 +87,21 @@ public class InventoryManager : MonoBehaviour
storedItems[itemToAdd] += stored;
currentlyStored += stored;
amount -= stored;
UpdateTaskTracker();
Debug.Log($"ADDED {stored} OF {itemToAdd.itemName} AND DROPPED {amount}");
return amount;
}
Debug.Log($"COULD NOT ADD {itemToAdd.itemName}; INVENTORY FULL");
return -1;
}
public void UpdateTaskTracker()
{
if (TaskManager.instance.activeTasks.Count > 0)
{
TaskManager.instance.CheckInventory();
}
}
public bool RemoveItem(Item itemToRemove, int amount = 1)
{
if (!storedItems.ContainsKey(itemToRemove) || storedItems[itemToRemove] < amount)
@ -57,4 +111,34 @@ public class InventoryManager : MonoBehaviour
storedItems[itemToRemove] -= amount;
return true;
}
public int CheckItemAmount(Item itemToCheck)
{
return storedItems[itemToCheck];
}
public void UpdateInventoryUI()
{
foreach (var item in storedItems)
{
if (allInventoryUIObjects.ContainsKey(item.Key))
{
if (item.Value == 0)
{
Destroy(allInventoryUIObjects[item.Key]);
allInventoryUIObjects.Remove(item.Key);
}
else
{
allInventoryUIObjects[item.Key].SetObject(item.Key);
}
}
else
{
InventoryUIObject newUIObject = Instantiate(templateUIObject, inventoryGrid);
newUIObject.gameObject.SetActive(true);
newUIObject.SetObject(item.Key);
allInventoryUIObjects[item.Key] = newUIObject;
}
}
}
}