extended usable Items with UsableItem

This commit is contained in:
dhain 2022-05-10 00:01:57 +02:00
parent fb9aa4e349
commit 0d49c92c15
8 changed files with 21 additions and 26 deletions

View file

@ -1,9 +1,10 @@
using System;
using UnityEngine;
public class Item : MonoBehaviour {
private string displayName;
private string description;
private int id; //TODO: create an actual ID System that makes snens
public class Item : MonoBehaviour, IComparable<Item> {
private readonly string displayName;
private readonly string description;
private readonly int id; //TODO: create an actual ID System that makes snens
public SpriteRenderer spriteRenderer;
public Sprite selectedSprite;
public Sprite defaultSprite;
@ -14,4 +15,8 @@ public class Item : MonoBehaviour {
this.id = id;
spriteRenderer.sprite ??= defaultSprite; // defaultSprite is set in UnityEditor
}
public int CompareTo(Item other) {
return this.id - other.id;
}
}

View file

@ -1,12 +1,7 @@
using UnityEngine;
namespace Items {
public class FishingRod : Item, IUsable {
public class FishingRod : UsableItem {
public FishingRod() : base("Fishing Rod", "Can be used to fish fishy fish.", 1) { }
public void select() {
}
}
}

View file

@ -3,7 +3,7 @@ using System.Collections.Generic;
using UnityEngine;
namespace Items {
public class Hoe : Item {
public class Hoe : UsableItem {
public Hoe() : base("Hoe", "Used to hoe the ground into farmland.", 2){}
}
}

View file

@ -3,7 +3,7 @@ using System.Collections.Generic;
using UnityEngine;
namespace Items {
public class Scythe : Item {
public class Scythe : UsableItem {
public Scythe() : base("Scythe", "Used to cut down crops.", 3){}
}
}

View file

@ -3,7 +3,7 @@ using System.Collections.Generic;
using UnityEngine;
namespace Items {
public class WateringCan : Item {
public class WateringCan : UsableItem {
public WateringCan():base("Watering Can", "Used to water planted crops.", 4){}
}
}

View file

@ -3,7 +3,7 @@ using System.Collections.Generic;
using UnityEngine;
namespace Items {
public class WheatSeed : Item {
public class WheatSeed : UsableItem {
public WheatSeed() : base("Wheat Seeds", "When planted on farmland, wheat will grow.", 6){}
}
}

View file

@ -17,22 +17,17 @@ public class PlayerController : MonoBehaviour {
// Start is called before the first frame update
void Start()
{
void Start() {
inventory ??= new List<Item>();
money = startMoney;
instance = this;
}
// Update is called once per frame
void Update()
{
void Update() {
}
public void setSelectedItem(UsableItem item) {
selectedItem = item;
}
}

View file

@ -20,6 +20,6 @@ public class UsableItem : Item, IUsable
}
public void select() {
throw new System.NotImplementedException();
PlayerController.getInstance().setSelectedItem(this);
}
}