From 2ff7fc2c12e43263e1e4529547d255fc5bde1911 Mon Sep 17 00:00:00 2001 From: dhain Date: Thu, 19 May 2022 16:03:20 +0200 Subject: [PATCH] diesmal wirklich --- Assets/InventorySlot.prefab | 2 +- Assets/Scenes/MainScene.unity | 171 ++++++++++++++++++++--- Assets/Scripts/Inventory.cs | 56 ++++++++ Assets/Scripts/InventorySlot.cs | 27 ++-- Assets/Scripts/InventoryUI.cs | 21 +-- Assets/Scripts/Item.cs | 13 +- Assets/Scripts/Items/FishingRod.cs | 7 - Assets/Scripts/Items/FishingRod.cs.meta | 11 -- Assets/Scripts/Items/Hoe.cs | 9 -- Assets/Scripts/Items/Hoe.cs.meta | 11 -- Assets/Scripts/Items/Scythe.cs | 9 -- Assets/Scripts/Items/Scythe.cs.meta | 11 -- Assets/Scripts/Items/WateringCan.cs | 9 -- Assets/Scripts/Items/WateringCan.cs.meta | 11 -- Assets/Scripts/Items/Wheat.cs | 9 -- Assets/Scripts/Items/Wheat.cs.meta | 11 -- Assets/Scripts/Items/WheatSeed.cs | 9 -- Assets/Scripts/Items/WheatSeed.cs.meta | 11 -- Assets/Scripts/PlayerController.cs | 31 +--- Assets/Scripts/UsableItem.cs | 2 +- 20 files changed, 247 insertions(+), 194 deletions(-) create mode 100644 Assets/Scripts/Inventory.cs delete mode 100644 Assets/Scripts/Items/FishingRod.cs delete mode 100644 Assets/Scripts/Items/FishingRod.cs.meta delete mode 100644 Assets/Scripts/Items/Hoe.cs delete mode 100644 Assets/Scripts/Items/Hoe.cs.meta delete mode 100644 Assets/Scripts/Items/Scythe.cs delete mode 100644 Assets/Scripts/Items/Scythe.cs.meta delete mode 100644 Assets/Scripts/Items/WateringCan.cs delete mode 100644 Assets/Scripts/Items/WateringCan.cs.meta delete mode 100644 Assets/Scripts/Items/Wheat.cs delete mode 100644 Assets/Scripts/Items/Wheat.cs.meta delete mode 100644 Assets/Scripts/Items/WheatSeed.cs delete mode 100644 Assets/Scripts/Items/WheatSeed.cs.meta diff --git a/Assets/InventorySlot.prefab b/Assets/InventorySlot.prefab index 0bbedc9..238aa03 100644 --- a/Assets/InventorySlot.prefab +++ b/Assets/InventorySlot.prefab @@ -201,7 +201,7 @@ MonoBehaviour: m_Calls: - m_Target: {fileID: 8059809276634721085} m_TargetAssemblyTypeName: InventorySlot, Assembly-CSharp - m_MethodName: useItem + m_MethodName: UseItem m_Mode: 1 m_Arguments: m_ObjectArgument: {fileID: 0} diff --git a/Assets/Scenes/MainScene.unity b/Assets/Scenes/MainScene.unity index e5ebf4e..ee412db 100644 --- a/Assets/Scenes/MainScene.unity +++ b/Assets/Scenes/MainScene.unity @@ -1499,7 +1499,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: -537.5, y: 251} + m_AnchoredPosition: {x: -268, y: 152} m_SizeDelta: {x: 100, y: 100} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &857317350 @@ -1546,12 +1546,12 @@ MonoBehaviour: m_OnClick: m_PersistentCalls: m_Calls: - - m_Target: {fileID: 888561712} - m_TargetAssemblyTypeName: InventorySlot, Assembly-CSharp - m_MethodName: addItem + - m_Target: {fileID: 1179703187} + m_TargetAssemblyTypeName: Inventory, Assembly-CSharp + m_MethodName: tempAddItem m_Mode: 2 m_Arguments: - m_ObjectArgument: {fileID: 990796751} + m_ObjectArgument: {fileID: 11400000, guid: 55fbb48b3a41c1049af9b40f3fd35db1, type: 2} m_ObjectArgumentAssemblyTypeName: Item, Assembly-CSharp m_IntArgument: 0 m_FloatArgument: 0 @@ -1703,17 +1703,6 @@ RectTransform: m_CorrespondingSourceObject: {fileID: 3510585822996971025, guid: 44dae5fbdb6f7df4f93a10807f66956f, type: 3} m_PrefabInstance: {fileID: 3510585823742910013} m_PrefabAsset: {fileID: 0} ---- !u!114 &888561712 stripped -MonoBehaviour: - m_CorrespondingSourceObject: {fileID: 8059809276634721085, guid: 44dae5fbdb6f7df4f93a10807f66956f, type: 3} - m_PrefabInstance: {fileID: 3510585823742910013} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 92863b15e86b5b94e9a331f3c97dddca, type: 3} - m_Name: - m_EditorClassIdentifier: --- !u!1 &897590124 GameObject: m_ObjectHideFlags: 0 @@ -1750,7 +1739,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 1, y: 0} m_AnchorMax: {x: 1, y: 0} - m_AnchoredPosition: {x: -587.5, y: 215.38048} + m_AnchoredPosition: {x: -348, y: 107} m_SizeDelta: {x: 720, y: 430} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &897590126 @@ -2065,6 +2054,139 @@ PrefabInstance: objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 44dae5fbdb6f7df4f93a10807f66956f, type: 3} +--- !u!1 &1031413640 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1031413641} + - component: {fileID: 1031413644} + - component: {fileID: 1031413643} + - component: {fileID: 1031413642} + m_Layer: 5 + m_Name: tempButton (1) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1031413641 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1031413640} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 1940090458} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: -156, y: 144} + m_SizeDelta: {x: 100, y: 100} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1031413642 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1031413640} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 4e29b1a8efbd4b44bb3f3716e73f07ff, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Navigation: + m_Mode: 0 + m_WrapAround: 0 + m_SelectOnUp: {fileID: 0} + m_SelectOnDown: {fileID: 0} + m_SelectOnLeft: {fileID: 0} + m_SelectOnRight: {fileID: 0} + m_Transition: 1 + m_Colors: + m_NormalColor: {r: 1, g: 1, b: 1, a: 1} + m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} + m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} + m_ColorMultiplier: 1 + m_FadeDuration: 0.1 + m_SpriteState: + m_HighlightedSprite: {fileID: 0} + m_PressedSprite: {fileID: 0} + m_SelectedSprite: {fileID: 0} + m_DisabledSprite: {fileID: 0} + m_AnimationTriggers: + m_NormalTrigger: Normal + m_HighlightedTrigger: Highlighted + m_PressedTrigger: Pressed + m_SelectedTrigger: Selected + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 1031413643} + m_OnClick: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 1179703187} + m_TargetAssemblyTypeName: Inventory, Assembly-CSharp + m_MethodName: tempAddItem + m_Mode: 2 + m_Arguments: + m_ObjectArgument: {fileID: 11400000, guid: 03bae48711a435b4bb9c1892438a3b3a, type: 2} + m_ObjectArgumentAssemblyTypeName: Item, Assembly-CSharp + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 +--- !u!114 &1031413643 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1031413640} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} + m_Maskable: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_Sprite: {fileID: 21300008, guid: 377d0838804322045b60e51d883c3c1c, type: 3} + m_Type: 0 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!222 &1031413644 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1031413640} + m_CullTransparentMesh: 1 --- !u!224 &1048061199 stripped RectTransform: m_CorrespondingSourceObject: {fileID: 3510585822996971025, guid: 44dae5fbdb6f7df4f93a10807f66956f, type: 3} @@ -2565,6 +2687,7 @@ GameObject: m_Component: - component: {fileID: 1179703186} - component: {fileID: 1179703185} + - component: {fileID: 1179703187} m_Layer: 0 m_Name: PlayerController m_TagString: Untagged @@ -2584,6 +2707,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: b18feac5270242d4a85c78ce72972d56, type: 3} m_Name: m_EditorClassIdentifier: + inventory: {fileID: 1179703187} startMoney: 100 --- !u!4 &1179703186 Transform: @@ -2600,6 +2724,18 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &1179703187 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1179703184} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 938a668a83530b74a97d7a3f7eadbc33, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!224 &1278879686 stripped RectTransform: m_CorrespondingSourceObject: {fileID: 3510585822996971025, guid: 44dae5fbdb6f7df4f93a10807f66956f, type: 3} @@ -3609,6 +3745,7 @@ RectTransform: m_Children: - {fileID: 897590125} - {fileID: 857317349} + - {fileID: 1031413641} m_Father: {fileID: 0} m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/Scripts/Inventory.cs b/Assets/Scripts/Inventory.cs new file mode 100644 index 0000000..af84800 --- /dev/null +++ b/Assets/Scripts/Inventory.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Inventory : MonoBehaviour { + #region Singleton + + public static Inventory instance; + + private void Awake() { + if(instance != null) { + Debug.LogWarning("More than one instance of Inventory found"); + } + + instance = this; + } + + #endregion + + public Dictionary items; + public const int inventorySpace = 28; + + public delegate void onItemChanged(); + public onItemChanged onItemChangedCallback; + + private void Start() { + items ??= new Dictionary(); + } + + public void tempAddItem(Item item) { + AddItem(item, 1); + } + + public void AddItem(Item item, int amount) { + if(items.Count >= inventorySpace) { + Debug.Log("Not enough inventory space!"); + return; + } + + if(!items.ContainsKey(item)) { + items.Add(item, amount); + } else { + items[item] += amount; + } + + + onItemChangedCallback?.Invoke(); + } + + public void removeItem(Item item, int amount) { + items.Add(item, -amount); + + onItemChangedCallback?.Invoke(); + } +} diff --git a/Assets/Scripts/InventorySlot.cs b/Assets/Scripts/InventorySlot.cs index f6289db..1949b7d 100644 --- a/Assets/Scripts/InventorySlot.cs +++ b/Assets/Scripts/InventorySlot.cs @@ -4,27 +4,32 @@ using UnityEngine.UI; public class InventorySlot : MonoBehaviour { public Image icon; - private Item item; + private Item _item; - public void addItem(Item newItem) { - item = newItem; + public void AddItem(Item newItem) { + _item = newItem; - icon.sprite = item.defaultSprite; + icon.sprite = _item.defaultSprite; icon.enabled = true; } - public void clearSlot() { - item = null; + public void ClearSlot() { + _item = null; icon.sprite = null; icon.enabled = false; } - public void removeItem() { - PlayerController.instance.inventory.Remove(item); + public void RemoveItem() { + Inventory.instance.items.Remove(_item); } - public void useItem() { - //TODO: use item - Debug.Log("using " + item.displayName); + public void UseItem() { + if(_item.GetType() == typeof(UsableItem)) { + ((UsableItem) _item).select(); + Debug.Log("using " + _item.displayName); + } else { + Debug.Log("Item not usable " + _item.displayName); + } + } } \ No newline at end of file diff --git a/Assets/Scripts/InventoryUI.cs b/Assets/Scripts/InventoryUI.cs index b57d098..8911c74 100644 --- a/Assets/Scripts/InventoryUI.cs +++ b/Assets/Scripts/InventoryUI.cs @@ -1,18 +1,19 @@ +using System.Linq; using UnityEngine; public class InventoryUI : MonoBehaviour { public Transform itemsParent; public GameObject inventoryUI; - private PlayerController playerController; - private InventorySlot[] slots; + private Inventory _inventory; + private InventorySlot[] _slots; // Start is called before the first frame update void Start() { - playerController = PlayerController.instance; - playerController.onItemChangedCallback += updateUI; + _inventory = Inventory.instance; + _inventory.onItemChangedCallback += UpdateUI; - slots = itemsParent.GetComponentsInChildren(); + _slots = itemsParent.GetComponentsInChildren(); } // Update is called once per frame @@ -22,12 +23,12 @@ public class InventoryUI : MonoBehaviour { } } - private void updateUI() { - for(int i = 0; i < slots.Length; i++) { - if(i < playerController.inventory.Count) { - // slots[i].addItem(playerController.inventory[i]); //TODO: dictionary "letztes" Item finden, Wie?!?!?! + private void UpdateUI() { + for(int i = 0; i < _slots.Length; i++) { + if(i < _inventory.items.Count) { + _slots[i].AddItem(_inventory.items.ElementAt(i).Key); } else { - slots[i].clearSlot(); + _slots[i].ClearSlot(); } } } diff --git a/Assets/Scripts/Item.cs b/Assets/Scripts/Item.cs index 6e15215..46327d7 100644 --- a/Assets/Scripts/Item.cs +++ b/Assets/Scripts/Item.cs @@ -1,14 +1,10 @@ using System; using UnityEngine; -//TODO: Auf ScriptableItem umschreiben!!!!!!!!!! -// -//https://www.youtube.com/watch?v=YLhj7SfaxSE -public class Item : MonoBehaviour, IComparable { - public readonly string displayName; - public readonly string description; - public readonly int id; //TODO: create an actual ID System that makes snens - public SpriteRenderer spriteRenderer; +public class Item : ScriptableObject, IComparable { + public string displayName; + public string description; + public int id; //TODO: create an actual ID System that makes snens public Sprite selectedSprite; public Sprite defaultSprite; @@ -16,7 +12,6 @@ public class Item : MonoBehaviour, IComparable { this.displayName = displayName; this.description = description; this.id = id; - spriteRenderer.sprite ??= defaultSprite; // defaultSprite is set in UnityEditor } public int CompareTo(Item other) { diff --git a/Assets/Scripts/Items/FishingRod.cs b/Assets/Scripts/Items/FishingRod.cs deleted file mode 100644 index 3797b64..0000000 --- a/Assets/Scripts/Items/FishingRod.cs +++ /dev/null @@ -1,7 +0,0 @@ -using UnityEngine; - -namespace Items { - public class FishingRod : UsableItem { - public FishingRod() : base("Fishing Rod", "Can be used to fish fishy fish.", 1) { } - } -} diff --git a/Assets/Scripts/Items/FishingRod.cs.meta b/Assets/Scripts/Items/FishingRod.cs.meta deleted file mode 100644 index 078bb3a..0000000 --- a/Assets/Scripts/Items/FishingRod.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: b08796f3a5662aa43a460c7ddd6796b3 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Items/Hoe.cs b/Assets/Scripts/Items/Hoe.cs deleted file mode 100644 index b7db958..0000000 --- a/Assets/Scripts/Items/Hoe.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -namespace Items { - public class Hoe : UsableItem { - public Hoe() : base("Hoe", "Used to hoe the ground into farmland.", 2){} - } -} diff --git a/Assets/Scripts/Items/Hoe.cs.meta b/Assets/Scripts/Items/Hoe.cs.meta deleted file mode 100644 index 72830f0..0000000 --- a/Assets/Scripts/Items/Hoe.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: aa6ceecfb09ac614997702b2caf66e33 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Items/Scythe.cs b/Assets/Scripts/Items/Scythe.cs deleted file mode 100644 index a5b4189..0000000 --- a/Assets/Scripts/Items/Scythe.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -namespace Items { - public class Scythe : UsableItem { - public Scythe() : base("Scythe", "Used to cut down crops.", 3){} - } -} diff --git a/Assets/Scripts/Items/Scythe.cs.meta b/Assets/Scripts/Items/Scythe.cs.meta deleted file mode 100644 index 379260d..0000000 --- a/Assets/Scripts/Items/Scythe.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 641048df0d7668f48a857c454e2bd320 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Items/WateringCan.cs b/Assets/Scripts/Items/WateringCan.cs deleted file mode 100644 index 3bd37a1..0000000 --- a/Assets/Scripts/Items/WateringCan.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -namespace Items { - public class WateringCan : UsableItem { - public WateringCan():base("Watering Can", "Used to water planted crops.", 4){} - } -} diff --git a/Assets/Scripts/Items/WateringCan.cs.meta b/Assets/Scripts/Items/WateringCan.cs.meta deleted file mode 100644 index abafa18..0000000 --- a/Assets/Scripts/Items/WateringCan.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 7e19228f49932534e8af0218c51e5c63 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Items/Wheat.cs b/Assets/Scripts/Items/Wheat.cs deleted file mode 100644 index 6eda1d7..0000000 --- a/Assets/Scripts/Items/Wheat.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -namespace Items { - public class Wheat : Item { - public Wheat() : base("Wheat", "Wheat is a grass widely cultivated for its seed, a cereal grain which is a worldwide staple food.", 5){} - } -} diff --git a/Assets/Scripts/Items/Wheat.cs.meta b/Assets/Scripts/Items/Wheat.cs.meta deleted file mode 100644 index 72e7ccd..0000000 --- a/Assets/Scripts/Items/Wheat.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 207be0ed7f8f5714c97b7ac5deb8956d -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/Items/WheatSeed.cs b/Assets/Scripts/Items/WheatSeed.cs deleted file mode 100644 index 8d90cfb..0000000 --- a/Assets/Scripts/Items/WheatSeed.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -namespace Items { - public class WheatSeed : UsableItem { - public WheatSeed() : base("Wheat Seeds", "When planted on farmland, wheat will grow.", 6){} - } -} diff --git a/Assets/Scripts/Items/WheatSeed.cs.meta b/Assets/Scripts/Items/WheatSeed.cs.meta deleted file mode 100644 index c343e6e..0000000 --- a/Assets/Scripts/Items/WheatSeed.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 0808be748388ede4ba57db7d74401617 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index f2a8b9c..786f978 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -8,7 +8,7 @@ public class PlayerController : MonoBehaviour { private void Awake() { if(instance != null) { - Debug.LogWarning("More than one instance of PlayeController found"); + Debug.LogWarning("More than one instance of PlayerController found"); } instance = this; @@ -16,8 +16,7 @@ public class PlayerController : MonoBehaviour { #endregion - public Dictionary inventory; - public readonly int inventorySpace = 28; + public Inventory inventory; private int money; private UsableItem selectedItem; @@ -25,40 +24,18 @@ public class PlayerController : MonoBehaviour { // Start is called before the first frame update void Start() { - inventory ??= new Dictionary(); money = startMoney; } // Update is called once per frame void Update() { } - public void setSelectedItem(UsableItem item) { - if(inventory.ContainsKey(item)) { + public void SetSelectedItem(UsableItem item) { + if(inventory.items.ContainsKey(item)) { selectedItem = item; Cursor.SetCursor(item.defaultSprite.texture, Vector2.zero, CursorMode.Auto); } else { Debug.Log("An item requested to select isn't in the inventory" + item); } } - - public delegate void onItemChanged(); - - public onItemChanged onItemChangedCallback; - - public void addItem(Item item, int amount) { - if(inventory.Count >= inventorySpace) { - Debug.Log("Not enough inventory space!"); - return; - } - - inventory.Add(item, amount); - - onItemChangedCallback?.Invoke(); - } - - public void removeItem(Item item, int amount) { - inventory.Add(item, -amount); - - onItemChangedCallback?.Invoke(); - } } \ No newline at end of file diff --git a/Assets/Scripts/UsableItem.cs b/Assets/Scripts/UsableItem.cs index 22f9401..5b9a0b2 100644 --- a/Assets/Scripts/UsableItem.cs +++ b/Assets/Scripts/UsableItem.cs @@ -15,6 +15,6 @@ public class UsableItem : Item, IUsable { } public void select() { - PlayerController.instance.setSelectedItem(this); + PlayerController.instance.SetSelectedItem(this); } } \ No newline at end of file