From b45acb97d8c545b98eb76234b298c52730a7910a Mon Sep 17 00:00:00 2001 From: Devin Braune Date: Thu, 4 Feb 2021 23:23:22 +0100 Subject: [PATCH] Refactor inventory to be in a unity component for shared inventory --- Assets/Resources/Inventories.meta | 8 +++++ .../Inventories/PlayerInventory.asset | 16 ++++++++++ .../Inventories/PlayerInventory.asset.meta | 8 +++++ .../Resources/Inventories/ShopInventory.asset | 16 ++++++++++ .../Inventories/ShopInventory.asset.meta | 8 +++++ Assets/Scenes/NewShop.unity | 29 ++++++++++++++----- .../Shop/Components/InventoryComponent.cs | 18 ++++++++++++ .../Components/InventoryComponent.cs.meta | 11 +++++++ .../Components/InventoryModelComponent.cs | 2 +- .../InventoryModelComponent.cs.meta | 2 +- .../Components/ShopModelComponent.cs.meta | 2 +- Assets/Scripts/Shop/Model/BuyModel.cs | 4 ++- .../Scripts/Shop/Model/IInventoryContainer.cs | 10 +++++++ .../Shop/Model/IInventoryContainer.cs.meta | 11 +++++++ Assets/Scripts/Shop/Model/Inventory.cs | 6 +++- Assets/Scripts/Shop/Model/ModelComponent.cs | 8 +++-- Assets/Scripts/Shop/Model/SellModel.cs | 4 ++- Assets/Scripts/Shop/Model/ShopModel.cs | 6 +++- .../Shop/Scriptable Objects/InventoryInit.cs | 14 +++++++++ .../Scriptable Objects/InventoryInit.cs.meta | 11 +++++++ .../Shop/Scriptable Objects/ItemFactory.cs | 2 +- .../Scriptable Objects/MultiItemFactory.cs | 4 +-- .../ProceduralArmorFactory.cs | 4 +-- .../ProceduralPotionFactory.cs | 4 +-- .../ProceduralWeaponFactory.cs | 4 +-- .../Scriptable Objects/ScriptedItemFactory.cs | 4 +-- .../Shop/Scriptable Objects/ShopObject.cs | 6 ++-- Assets/Scripts/Shop/View/ShopView.cs | 2 ++ 28 files changed, 191 insertions(+), 33 deletions(-) create mode 100644 Assets/Resources/Inventories.meta create mode 100644 Assets/Resources/Inventories/PlayerInventory.asset create mode 100644 Assets/Resources/Inventories/PlayerInventory.asset.meta create mode 100644 Assets/Resources/Inventories/ShopInventory.asset create mode 100644 Assets/Resources/Inventories/ShopInventory.asset.meta create mode 100644 Assets/Scripts/Shop/Components/InventoryComponent.cs create mode 100644 Assets/Scripts/Shop/Components/InventoryComponent.cs.meta create mode 100644 Assets/Scripts/Shop/Model/IInventoryContainer.cs create mode 100644 Assets/Scripts/Shop/Model/IInventoryContainer.cs.meta create mode 100644 Assets/Scripts/Shop/Scriptable Objects/InventoryInit.cs create mode 100644 Assets/Scripts/Shop/Scriptable Objects/InventoryInit.cs.meta diff --git a/Assets/Resources/Inventories.meta b/Assets/Resources/Inventories.meta new file mode 100644 index 0000000..8e0adde --- /dev/null +++ b/Assets/Resources/Inventories.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 3cb5ba7bdedc6a84c8e0964a07f63beb +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Inventories/PlayerInventory.asset b/Assets/Resources/Inventories/PlayerInventory.asset new file mode 100644 index 0000000..6a4a00f --- /dev/null +++ b/Assets/Resources/Inventories/PlayerInventory.asset @@ -0,0 +1,16 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 0} + m_Name: PlayerInventory + m_EditorClassIdentifier: SAShop::InventoryInitVals + Money: 5500 + Items: {fileID: 11400000, guid: aed79a62cfb941741bd92ea0a643b752, type: 2} diff --git a/Assets/Resources/Inventories/PlayerInventory.asset.meta b/Assets/Resources/Inventories/PlayerInventory.asset.meta new file mode 100644 index 0000000..2214a36 --- /dev/null +++ b/Assets/Resources/Inventories/PlayerInventory.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4ba20449d16e86b4eabf0b524c759f07 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Inventories/ShopInventory.asset b/Assets/Resources/Inventories/ShopInventory.asset new file mode 100644 index 0000000..f0e0f2b --- /dev/null +++ b/Assets/Resources/Inventories/ShopInventory.asset @@ -0,0 +1,16 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 0} + m_Name: ShopInventory + m_EditorClassIdentifier: SAShop::InventoryInitVals + Money: 8000 + Items: {fileID: 11400000, guid: b75166a8b7cdac24d9a9d1cd0edf4a15, type: 2} diff --git a/Assets/Resources/Inventories/ShopInventory.asset.meta b/Assets/Resources/Inventories/ShopInventory.asset.meta new file mode 100644 index 0000000..4fe1149 --- /dev/null +++ b/Assets/Resources/Inventories/ShopInventory.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e64d01fbae5b7cb41966afe48bf87dc9 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/NewShop.unity b/Assets/Scenes/NewShop.unity index d518e72..edc06bb 100644 --- a/Assets/Scenes/NewShop.unity +++ b/Assets/Scenes/NewShop.unity @@ -787,6 +787,7 @@ GameObject: m_Component: - component: {fileID: 132445006} - component: {fileID: 132445007} + - component: {fileID: 132445008} m_Layer: 5 m_Name: Shop m_TagString: Untagged @@ -827,8 +828,21 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: be8c4b332c72a3c4b85013b334ebde3a, type: 3} m_Name: m_EditorClassIdentifier: - factory: {fileID: 11400000, guid: b75166a8b7cdac24d9a9d1cd0edf4a15, type: 2} + inventory: {fileID: 132445008} shop: {fileID: 11400000, guid: 366ca79a0c4a2df4fac53ddd28f65f1a, type: 2} +--- !u!114 &132445008 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 132445005} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c83375c3d017aee4c9db24976f6a6ba4, type: 3} + m_Name: + m_EditorClassIdentifier: + factory: {fileID: 11400000, guid: e64d01fbae5b7cb41966afe48bf87dc9, type: 2} --- !u!1 &169548028 GameObject: m_ObjectHideFlags: 0 @@ -2704,7 +2718,7 @@ MonoBehaviour: buyButton: {fileID: 1424786402} instructionText: {fileID: 360948192} layoutGroup: {fileID: 2049417198} - ownModel: {fileID: 1237921497} + ownModel: {fileID: 1237921498} --- !u!114 &336428457 MonoBehaviour: m_ObjectHideFlags: 0 @@ -9796,8 +9810,8 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 1237921496} - - component: {fileID: 1237921497} - component: {fileID: 1237921498} + - component: {fileID: 1237921497} m_Layer: 5 m_Name: Inventory m_TagString: Untagged @@ -9835,11 +9849,10 @@ MonoBehaviour: m_GameObject: {fileID: 1237921495} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: be8c4b332c72a3c4b85013b334ebde3a, type: 3} + m_Script: {fileID: 11500000, guid: c83375c3d017aee4c9db24976f6a6ba4, type: 3} m_Name: m_EditorClassIdentifier: - factory: {fileID: 11400000, guid: aed79a62cfb941741bd92ea0a643b752, type: 2} - shop: {fileID: 11400000, guid: 366ca79a0c4a2df4fac53ddd28f65f1a, type: 2} + factory: {fileID: 11400000, guid: 4ba20449d16e86b4eabf0b524c759f07, type: 2} --- !u!114 &1237921498 MonoBehaviour: m_ObjectHideFlags: 0 @@ -9852,7 +9865,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 8e211938370fd3d43a99aae3848bdd1c, type: 3} m_Name: m_EditorClassIdentifier: - factory: {fileID: 11400000, guid: aed79a62cfb941741bd92ea0a643b752, type: 2} + inventory: {fileID: 1237921497} shop: {fileID: 11400000, guid: 5832c828db6d00c42a09217f7b743233, type: 2} --- !u!1 &1287258904 GameObject: @@ -10084,7 +10097,7 @@ MonoBehaviour: buyButton: {fileID: 1835603779} instructionText: {fileID: 403716179} layoutGroup: {fileID: 981903572} - ownModel: {fileID: 1237921497} + ownModel: {fileID: 1237921498} infoPanel: {fileID: 1800161527} --- !u!114 &1296916391 MonoBehaviour: diff --git a/Assets/Scripts/Shop/Components/InventoryComponent.cs b/Assets/Scripts/Shop/Components/InventoryComponent.cs new file mode 100644 index 0000000..3c61d17 --- /dev/null +++ b/Assets/Scripts/Shop/Components/InventoryComponent.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class InventoryComponent : MonoBehaviour, IInventoryContainer +{ + [SerializeField] private InventoryInitVals factory; + //[SerializeField] private ShopObject inventoryStart; + // Start is called before the first frame update + void Awake() + { + Debug.Assert(factory != null,"Item factory not assigned!",this); + Inventory = new Inventory(factory.Money); + factory.Items.PopulateInventory(Inventory); + } + + public Inventory Inventory { get; private set; } +} diff --git a/Assets/Scripts/Shop/Components/InventoryComponent.cs.meta b/Assets/Scripts/Shop/Components/InventoryComponent.cs.meta new file mode 100644 index 0000000..dc341c7 --- /dev/null +++ b/Assets/Scripts/Shop/Components/InventoryComponent.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c83375c3d017aee4c9db24976f6a6ba4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: -50 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Shop/Components/InventoryModelComponent.cs b/Assets/Scripts/Shop/Components/InventoryModelComponent.cs index f121d98..38ae63b 100644 --- a/Assets/Scripts/Shop/Components/InventoryModelComponent.cs +++ b/Assets/Scripts/Shop/Components/InventoryModelComponent.cs @@ -8,6 +8,6 @@ public class InventoryModelComponent : ModelComponent protected override void CreateModel() { Debug.Assert(shop != null,"Shop model initial object never assigned!",this); - model = new SellModel(shop); + model = new SellModel(shop,inventory.Inventory); } } diff --git a/Assets/Scripts/Shop/Components/InventoryModelComponent.cs.meta b/Assets/Scripts/Shop/Components/InventoryModelComponent.cs.meta index 912ad01..0faed8e 100644 --- a/Assets/Scripts/Shop/Components/InventoryModelComponent.cs.meta +++ b/Assets/Scripts/Shop/Components/InventoryModelComponent.cs.meta @@ -4,7 +4,7 @@ MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] - executionOrder: 0 + executionOrder: -20 icon: {instanceID: 0} userData: assetBundleName: diff --git a/Assets/Scripts/Shop/Components/ShopModelComponent.cs.meta b/Assets/Scripts/Shop/Components/ShopModelComponent.cs.meta index 5964caf..ec08554 100644 --- a/Assets/Scripts/Shop/Components/ShopModelComponent.cs.meta +++ b/Assets/Scripts/Shop/Components/ShopModelComponent.cs.meta @@ -4,7 +4,7 @@ MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] - executionOrder: 0 + executionOrder: -10 icon: {instanceID: 0} userData: assetBundleName: diff --git a/Assets/Scripts/Shop/Model/BuyModel.cs b/Assets/Scripts/Shop/Model/BuyModel.cs index 32914b4..69ffcf6 100644 --- a/Assets/Scripts/Shop/Model/BuyModel.cs +++ b/Assets/Scripts/Shop/Model/BuyModel.cs @@ -14,8 +14,10 @@ public class BuyModel : ShopModel // Rather than modifying the whole class, we just reuse the existing stuff but don't make it create any items. // This makes it less work to make proper functionality, without having to break any potential old functionality. // Additionally, saves us work having to rip out the inventory's own ability to generate items. - public BuyModel(ShopObject pShopInitials) : this(pShopInitials.PriceModifier, 0, pShopInitials.Money) + // Edit: Nevermind, let's just allow setting the inventory in the constructor, for shared inventories between models! + public BuyModel(ShopObject pShopInitials, Inventory inventory = null) : this(pShopInitials.PriceModifier, 0, 0) { + if (inventory != null) this.inventory = inventory; } //------------------------------------------------------------------------------------------------------------------------ diff --git a/Assets/Scripts/Shop/Model/IInventoryContainer.cs b/Assets/Scripts/Shop/Model/IInventoryContainer.cs new file mode 100644 index 0000000..51240e7 --- /dev/null +++ b/Assets/Scripts/Shop/Model/IInventoryContainer.cs @@ -0,0 +1,10 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +/// +/// Defines a class that contains an inventory +/// +public interface IInventoryContainer +{ + Inventory Inventory { get; } +} diff --git a/Assets/Scripts/Shop/Model/IInventoryContainer.cs.meta b/Assets/Scripts/Shop/Model/IInventoryContainer.cs.meta new file mode 100644 index 0000000..8ca81af --- /dev/null +++ b/Assets/Scripts/Shop/Model/IInventoryContainer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0ada16e429f65e945bfc92b2e6f91cd7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Shop/Model/Inventory.cs b/Assets/Scripts/Shop/Model/Inventory.cs index 550ebcb..df3235d 100644 --- a/Assets/Scripts/Shop/Model/Inventory.cs +++ b/Assets/Scripts/Shop/Model/Inventory.cs @@ -11,9 +11,13 @@ public class Inventory private List itemList = new List(); //Items in the inventory //Set up the inventory with item count and money - public Inventory(int pItemCount, int pMoney) + public Inventory(int pItemCount, int pMoney) : this(pMoney) { PopulateInventory(pItemCount); + } + + public Inventory(int pMoney) + { Money = pMoney; } diff --git a/Assets/Scripts/Shop/Model/ModelComponent.cs b/Assets/Scripts/Shop/Model/ModelComponent.cs index 670e412..7699d69 100644 --- a/Assets/Scripts/Shop/Model/ModelComponent.cs +++ b/Assets/Scripts/Shop/Model/ModelComponent.cs @@ -10,15 +10,17 @@ using UnityEngine; public abstract class ModelComponent : MonoBehaviour, IModelContainer { public ShopModel Model { get => model; } - [SerializeField] private ItemFactory factory; + //[SerializeField] private ItemFactory factory; + [SerializeField] protected InventoryComponent inventory; protected ShopModel model; private void Awake() { - Debug.Assert(factory != null,"Item factory not assigned!",this); + Debug.Assert(inventory != null,"Inventory not assigned!",this); CreateModel(); // Of course, a generic model component can't select which type of model to use. So we use polymorphism! - factory.PopulateModel(model); + model.inventory = inventory.Inventory; + //factory.PopulateInventory(model.inventory); } protected abstract void CreateModel(); diff --git a/Assets/Scripts/Shop/Model/SellModel.cs b/Assets/Scripts/Shop/Model/SellModel.cs index 27b091e..99d2778 100644 --- a/Assets/Scripts/Shop/Model/SellModel.cs +++ b/Assets/Scripts/Shop/Model/SellModel.cs @@ -14,8 +14,10 @@ public class SellModel : ShopModel // Rather than modifying the whole class, we just reuse the existing stuff but don't make it create any items. // This makes it less work to make proper functionality, without having to break any potential old functionality. // Additionally, saves us work having to rip out the inventory's own ability to generate items. - public SellModel(ShopObject pShopInitials) : this(pShopInitials.PriceModifier, 0, pShopInitials.Money) + // Edit: Nevermind, let's just allow setting the inventory in the constructor, for shared inventories between models! + public SellModel(ShopObject pShopInitials, Inventory inventory = null) : this(pShopInitials.PriceModifier, 0, 0) { + if (inventory != null) this.inventory = inventory; } //------------------------------------------------------------------------------------------------------------------------ diff --git a/Assets/Scripts/Shop/Model/ShopModel.cs b/Assets/Scripts/Shop/Model/ShopModel.cs index 42b2a5e..4959b02 100644 --- a/Assets/Scripts/Shop/Model/ShopModel.cs +++ b/Assets/Scripts/Shop/Model/ShopModel.cs @@ -8,7 +8,11 @@ using System.Collections.Generic; /// public abstract class ShopModel : IModelObservable { - public Inventory inventory { get; } // Getter of the inventory, the views might need this to set up the display. + public Inventory inventory + { + get; + set; + } // Getter of the inventory, the views might need this to set up the display. protected float priceModifier; //Modifies the item's price based on its base price protected int selectedItemIndex = 0; //selected item index diff --git a/Assets/Scripts/Shop/Scriptable Objects/InventoryInit.cs b/Assets/Scripts/Shop/Scriptable Objects/InventoryInit.cs new file mode 100644 index 0000000..395ff86 --- /dev/null +++ b/Assets/Scripts/Shop/Scriptable Objects/InventoryInit.cs @@ -0,0 +1,14 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +/// +/// This object allows us to script which kind of stuff an inventory starts out with. Inventory are meant to be created +/// by using the inventory unity component, which requires InventoryInitVals to be able to know which kind of money and other +/// things specific to a inventory they start with. +/// +[CreateAssetMenu]//Allows creating ViewConfig objects in Assets -> Create menu in the Unity Editor +public class InventoryInitVals : ScriptableObject +{ + public int Money; + public ItemFactory Items; +} diff --git a/Assets/Scripts/Shop/Scriptable Objects/InventoryInit.cs.meta b/Assets/Scripts/Shop/Scriptable Objects/InventoryInit.cs.meta new file mode 100644 index 0000000..8872267 --- /dev/null +++ b/Assets/Scripts/Shop/Scriptable Objects/InventoryInit.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6b56b3d0165a9714ab2efbdf15c22d0d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Shop/Scriptable Objects/ItemFactory.cs b/Assets/Scripts/Shop/Scriptable Objects/ItemFactory.cs index 96b79f2..54db56b 100644 --- a/Assets/Scripts/Shop/Scriptable Objects/ItemFactory.cs +++ b/Assets/Scripts/Shop/Scriptable Objects/ItemFactory.cs @@ -8,7 +8,7 @@ using UnityEngine.Serialization; /// public abstract class ItemFactory : ScriptableObject { - public abstract void PopulateModel(ShopModel model); + public abstract void PopulateInventory(Inventory inv); } // This has the sole purpose of associating a sprite with a name for the factory. Not making it a scriptable object because doing this in the factory editor view is faster diff --git a/Assets/Scripts/Shop/Scriptable Objects/MultiItemFactory.cs b/Assets/Scripts/Shop/Scriptable Objects/MultiItemFactory.cs index 71bfbb7..b17315d 100644 --- a/Assets/Scripts/Shop/Scriptable Objects/MultiItemFactory.cs +++ b/Assets/Scripts/Shop/Scriptable Objects/MultiItemFactory.cs @@ -9,11 +9,11 @@ using UnityEngine; public class MultiItemFactory : ItemFactory { public ItemFactory[] ItemFactories; - public override void PopulateModel(ShopModel model) + public override void PopulateInventory(Inventory model) { foreach (var factory in ItemFactories) { - factory.PopulateModel(model); + factory.PopulateInventory(model); } } } diff --git a/Assets/Scripts/Shop/Scriptable Objects/ProceduralArmorFactory.cs b/Assets/Scripts/Shop/Scriptable Objects/ProceduralArmorFactory.cs index 104a54d..8261496 100644 --- a/Assets/Scripts/Shop/Scriptable Objects/ProceduralArmorFactory.cs +++ b/Assets/Scripts/Shop/Scriptable Objects/ProceduralArmorFactory.cs @@ -18,12 +18,12 @@ public class ProceduralArmorFactory : ItemFactory public ItemPrototype[] Items; public int Amount; - public override void PopulateModel(ShopModel model) + public override void PopulateInventory(Inventory model) { for (int i = 0; i < Amount; i++) { var item = Items[Random.Range(0, Items.Length)]; - model.inventory.AddItem(new ItemArmor(item.Name,item.Sprite.name,Random.Range(PriceMin,PriceMax),Random.Range(DefenseMax,DefenseMax) + item.Bonus,Random.Range(DefenseMin,DefenseMax) + item.Bonus + 3,item.Description, Rarity)); + model.AddItem(new ItemArmor(item.Name,item.Sprite.name,Random.Range(PriceMin,PriceMax),Random.Range(DefenseMax,DefenseMax) + item.Bonus,Random.Range(DefenseMin,DefenseMax) + item.Bonus + 3,item.Description, Rarity)); } } } \ No newline at end of file diff --git a/Assets/Scripts/Shop/Scriptable Objects/ProceduralPotionFactory.cs b/Assets/Scripts/Shop/Scriptable Objects/ProceduralPotionFactory.cs index 3d64c04..cc97031 100644 --- a/Assets/Scripts/Shop/Scriptable Objects/ProceduralPotionFactory.cs +++ b/Assets/Scripts/Shop/Scriptable Objects/ProceduralPotionFactory.cs @@ -18,12 +18,12 @@ public class ProceduralPotionFactory : ItemFactory public PotionPrototype[] Items; public int Amount; - public override void PopulateModel(ShopModel model) + public override void PopulateInventory(Inventory model) { for (int i = 0; i < Amount; i++) { var item = Items[Random.Range(0, Items.Length)]; - model.inventory.AddItem(new ItemPotion(item.Name,item.Sprite.name,Random.Range(PriceMin,PriceMax),item.EffectTime,item.Type,Random.Range(EffectMin,EffectMax) + item.Bonus + 3,item.Description, Rarity)); + model.AddItem(new ItemPotion(item.Name,item.Sprite.name,Random.Range(PriceMin,PriceMax),item.EffectTime,item.Type,Random.Range(EffectMin,EffectMax) + item.Bonus + 3,item.Description, Rarity)); } } } diff --git a/Assets/Scripts/Shop/Scriptable Objects/ProceduralWeaponFactory.cs b/Assets/Scripts/Shop/Scriptable Objects/ProceduralWeaponFactory.cs index 7d898b6..002ad38 100644 --- a/Assets/Scripts/Shop/Scriptable Objects/ProceduralWeaponFactory.cs +++ b/Assets/Scripts/Shop/Scriptable Objects/ProceduralWeaponFactory.cs @@ -18,12 +18,12 @@ public class ProceduralWeaponFactory : ItemFactory public ItemPrototype[] Items; public int Amount; - public override void PopulateModel(ShopModel model) + public override void PopulateInventory(Inventory model) { for (int i = 0; i < Amount; i++) { var item = Items[Random.Range(0, Items.Length)]; - model.inventory.AddItem(new ItemWeapon(item.Name,item.Sprite.name,Random.Range(PriceMin,PriceMax),Random.Range(DamageMin,DamageMax) + item.Bonus,Random.Range(DamageMin,DamageMax) + item.Bonus + 3,item.Description, Rarity)); + model.AddItem(new ItemWeapon(item.Name,item.Sprite.name,Random.Range(PriceMin,PriceMax),Random.Range(DamageMin,DamageMax) + item.Bonus,Random.Range(DamageMin,DamageMax) + item.Bonus + 3,item.Description, Rarity)); } } } \ No newline at end of file diff --git a/Assets/Scripts/Shop/Scriptable Objects/ScriptedItemFactory.cs b/Assets/Scripts/Shop/Scriptable Objects/ScriptedItemFactory.cs index db89e37..0ae126e 100644 --- a/Assets/Scripts/Shop/Scriptable Objects/ScriptedItemFactory.cs +++ b/Assets/Scripts/Shop/Scriptable Objects/ScriptedItemFactory.cs @@ -8,11 +8,11 @@ using UnityEngine; public class ScriptedItemFactory : ItemFactory { public List Items; - public override void PopulateModel(ShopModel model) + public override void PopulateInventory(Inventory model) { foreach (var item in Items) { - model.inventory.AddItem(item.GenerateItem()); + model.AddItem(item.GenerateItem()); } } } diff --git a/Assets/Scripts/Shop/Scriptable Objects/ShopObject.cs b/Assets/Scripts/Shop/Scriptable Objects/ShopObject.cs index 05ff1b1..79b54cc 100644 --- a/Assets/Scripts/Shop/Scriptable Objects/ShopObject.cs +++ b/Assets/Scripts/Shop/Scriptable Objects/ShopObject.cs @@ -2,13 +2,11 @@ using System.Collections.Generic; using UnityEngine; /// -/// This shop object allows us to script which kind of stuff a shop starts out with. Models are meant to be created -/// by using the appropriate unity component, which requires a shopobject to be able to which kind of money and other -/// things specific to a shop they start with. +/// Currently only contains shop specific stuff, such as a price modifier /// [CreateAssetMenu]//Allows creating ViewConfig objects in Assets -> Create menu in the Unity Editor public class ShopObject : ScriptableObject { - public int Money; + //public int Money; public float PriceModifier; // How much more expensive than retail price does this shop sell stuff? } diff --git a/Assets/Scripts/Shop/View/ShopView.cs b/Assets/Scripts/Shop/View/ShopView.cs index c9d10b8..4a8eb91 100644 --- a/Assets/Scripts/Shop/View/ShopView.cs +++ b/Assets/Scripts/Shop/View/ShopView.cs @@ -49,6 +49,8 @@ public abstract class ShopView : MonoBehaviour private void OnEnable() { + // sanity check + if (model == null) model = ownModel.Model; PopulateItemIconView(); //Display items }