diff --git a/Assets/Resources/ScriptedItems/BetterSword.asset b/Assets/Resources/ScriptedItems/BetterSword.asset index 5791cc4..2dfadfe 100644 --- a/Assets/Resources/ScriptedItems/BetterSword.asset +++ b/Assets/Resources/ScriptedItems/BetterSword.asset @@ -14,4 +14,5 @@ MonoBehaviour: m_EditorClassIdentifier: Name: Good Sword Description: Better than the Noob Sword - sprite: {fileID: -4063295180217184869, guid: b00993d063fbc4a87983115070f6145c, type: 3} + Sprite: {fileID: -4063295180217184869, guid: b00993d063fbc4a87983115070f6145c, type: 3} + Price: 600 diff --git a/Assets/Resources/ScriptedItems/SomeSword.asset b/Assets/Resources/ScriptedItems/SomeSword.asset index 186e576..b7ceb88 100644 --- a/Assets/Resources/ScriptedItems/SomeSword.asset +++ b/Assets/Resources/ScriptedItems/SomeSword.asset @@ -14,4 +14,5 @@ MonoBehaviour: m_EditorClassIdentifier: Name: Noob Sword Description: This sword is for noobs - sprite: {fileID: -6229739577819397656, guid: b00993d063fbc4a87983115070f6145c, type: 3} + Sprite: {fileID: -6229739577819397656, guid: b00993d063fbc4a87983115070f6145c, type: 3} + Price: 150 diff --git a/Assets/Scenes/NewShop.unity b/Assets/Scenes/NewShop.unity index 9673871..bba3ac9 100644 --- a/Assets/Scenes/NewShop.unity +++ b/Assets/Scenes/NewShop.unity @@ -2959,6 +2959,7 @@ MonoBehaviour: buyButton: {fileID: 1510759987} instructionText: {fileID: 1416129356} layoutGroup: {fileID: 1865708447} + ownModel: {fileID: 132445007} --- !u!1 &849412832 GameObject: m_ObjectHideFlags: 0 @@ -9404,3 +9405,4 @@ MonoBehaviour: buyButton: {fileID: 889320678} instructionText: {fileID: 1352417142} layoutGroup: {fileID: 180905780} + ownModel: {fileID: 132445007} diff --git a/Assets/Scripts/Shop/Scriptable Objects/ScriptedItem.cs b/Assets/Scripts/Shop/Scriptable Objects/ScriptedItem.cs index aeaa128..c285601 100644 --- a/Assets/Scripts/Shop/Scriptable Objects/ScriptedItem.cs +++ b/Assets/Scripts/Shop/Scriptable Objects/ScriptedItem.cs @@ -9,5 +9,6 @@ public class ScriptedItem : ScriptableObject { public string Name; public string Description; - public Sprite sprite; + public Sprite Sprite; + public int Price; } diff --git a/Assets/Scripts/Shop/Scriptable Objects/ScriptedItemFactory.cs b/Assets/Scripts/Shop/Scriptable Objects/ScriptedItemFactory.cs index 1e07da9..1df56d4 100644 --- a/Assets/Scripts/Shop/Scriptable Objects/ScriptedItemFactory.cs +++ b/Assets/Scripts/Shop/Scriptable Objects/ScriptedItemFactory.cs @@ -10,6 +10,9 @@ public class ScriptedItemFactory : ItemFactory public List Items; public override void PopulateModel(ShopModel model) { - + foreach (var item in Items) + { + model.inventory.AddItem(new Item(item.name,item.Sprite.name,item.Price)); + } } } diff --git a/Assets/Scripts/Shop/View/ShopView.cs b/Assets/Scripts/Shop/View/ShopView.cs index 3ee1061..782af3a 100644 --- a/Assets/Scripts/Shop/View/ShopView.cs +++ b/Assets/Scripts/Shop/View/ShopView.cs @@ -14,7 +14,7 @@ using TMPro; /// public abstract class ShopView : MonoBehaviour, IShopModelObserver { - public ShopModel ShopModel => model; //A getter to access shopModel. + public ShopModel ShopModel => model; //A getter to access shopModel. Will access inventory of trade partner in sell mode! [SerializeField] protected GameObject itemPrefab; //A prefab to display an item in the view @@ -27,6 +27,8 @@ public abstract class ShopView : MonoBehaviour, IShopModelObserver [SerializeField] protected LayoutGroup layoutGroup; // The layout group that represents this view visually + [SerializeField] private ModelComponent ownModel; // Reference to the model this view technically belongs to + protected ShopModel model; // Model in MVC pattern protected ShopModel other; // Other model in MVC pattern (our own inventory) private ShopController shopController; //Controller in MVC pattern @@ -34,7 +36,9 @@ public abstract class ShopView : MonoBehaviour, IShopModelObserver // Set up the view's necessary stuff before the view is enabled protected virtual void Awake() { - model = new BuyModel(2f, 16, 500); //Right now use magic values to set up the shop + //model = new BuyModel(2f, 16, 500); //Right now use magic values to set up the shop + Debug.Assert(ownModel != null,"No shop model assigned!",this); + model = ownModel.Model; shopController = gameObject.AddComponent().Initialize(model);//Set the default controller to be the mouse controller SetupItemIconView(); //Setup the grid view's properties InitializeButtons(); //Connect the buttons to the controller