Merge remote-tracking branch 'origin/develop' into develop

# Conflicts:
#	Assets/BaseTile.prefab.meta
#	Assets/Scenes/MainScene.unity
#	Assets/Scripts/PlayerController.cs
#	Assets/Scripts/TileBehaviour.cs
#	Assets/Scripts/Tiles/GrassTile.cs.meta
This commit is contained in:
s-prechtl 2022-05-20 08:19:17 +02:00
commit 45fd8aed5e
122 changed files with 17495 additions and 788 deletions

View file

@ -0,0 +1,59 @@
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<Item, int> items;
public const int inventorySpace = 28;
public delegate void onItemChanged();
public onItemChanged onItemChangedCallback;
private void Start() {
items ??= new Dictionary<Item, int>();
}
public void tempAddItem(Item item) {
Debug.Log("AWSD");
AddItem(item, 1);
}
public void AddItem(Item item, int amount) {
if(items.Count >= inventorySpace) {
Debug.Log("Not enough inventory space!");
return;
}
Debug.Log("ASDADADWDASDWD");
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();
}
}

View file

@ -0,0 +1,35 @@
using UnityEngine;
using UnityEngine.UI;
public class InventorySlot : MonoBehaviour {
public Image icon;
private Item _item;
public void AddItem(Item newItem) {
_item = newItem;
icon.sprite = _item.defaultSprite;
icon.enabled = true;
}
public void ClearSlot() {
_item = null;
icon.sprite = null;
icon.enabled = false;
}
public void RemoveItem() {
Inventory.instance.items.Remove(_item);
}
public void UseItem() {
if(_item.GetType() == typeof(UsableItem)) {
((UsableItem) _item).select();
Debug.Log("using " + _item.displayName);
} else {
Debug.Log("Item not usable " + _item.displayName);
}
}
}

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 641048df0d7668f48a857c454e2bd320
guid: 92863b15e86b5b94e9a331f3c97dddca
MonoImporter:
externalObjects: {}
serializedVersion: 2

View file

@ -0,0 +1,41 @@
using System.Linq;
using UnityEngine;
public class InventoryUI : MonoBehaviour {
public Transform itemsParent;
public GameObject inventoryUI;
private Inventory _inventory;
private InventorySlot[] _slots;
// Start is called before the first frame update
void Start() {
_inventory = Inventory.instance;
_inventory.onItemChangedCallback += UpdateUI;
_slots = itemsParent.GetComponentsInChildren<InventorySlot>();
toggleInventory();
}
// Update is called once per frame
void Update() {
if(Input.GetButtonDown("Inventory")) {
toggleInventory();
}
}
private void toggleInventory() {
inventoryUI.SetActive(!inventoryUI.activeSelf);
}
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();
}
}
}
}

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: b08796f3a5662aa43a460c7ddd6796b3
guid: 07c8392e636669644a90cebd609eaf5a
MonoImporter:
externalObjects: {}
serializedVersion: 2

View file

@ -1,11 +1,11 @@
using System;
using UnityEngine;
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;
[CreateAssetMenu(fileName = "New Item", menuName = "Inventory/Item")]
public class Item : ScriptableObject, IComparable<Item> {
public string displayName;
public string description;
public int id; //TODO: create an actual ID System that makes snens
public Sprite selectedSprite;
public Sprite defaultSprite;
@ -13,7 +13,6 @@ public class Item : MonoBehaviour, IComparable<Item> {
this.displayName = displayName;
this.description = description;
this.id = id;
spriteRenderer.sprite ??= defaultSprite; // defaultSprite is set in UnityEditor
}
public int CompareTo(Item other) {

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: bd6385a1b78fe80479618d50cf5ff510
guid: 254b144606ebc994589f639e82f06591
folderAsset: yes
DefaultImporter:
externalObjects: {}

View file

@ -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) { }
}
}

View file

@ -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){}
}
}

View file

@ -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){}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3e2b622f17cf8c54c96818c5850d4c76
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,10 @@
using Tiles;
namespace Items.TerraformingTools
{
public class GrassTool : TerraformingTool
{
public GrassTool(int id) :
base(typeof(GrassTile), "Grass Tool", "Sets clicked Tile to Grass", id) { }
}
}

View file

@ -0,0 +1,17 @@
using System;
namespace Items.TerraformingTools
{
public abstract class TerraformingTool : UsableItem
{
public readonly Type TileType;
protected TerraformingTool(Type tileType, string displayName, string description, int id) :
base(displayName, description, id)
{
this.TileType = tileType;
}
}
}

View file

@ -0,0 +1,10 @@
using Tiles;
namespace Items.TerraformingTools
{
public class WaterTool : TerraformingTool
{
public WaterTool(int id) :
base(typeof(WaterTile), "Water Tool", "Sets clicked Tile to water", id) { }
}
}

View file

@ -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){}
}
}

View file

@ -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){}
}
}

View file

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 207be0ed7f8f5714c97b7ac5deb8956d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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){}
}
}

View file

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 0808be748388ede4ba57db7d74401617
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -2,44 +2,49 @@ using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UIElements;
using Cursor = UnityEngine.Cursor;
public class PlayerController : MonoBehaviour {
private Dictionary<Item, int> inventory;
private int money;
private UsableItem selectedItem;
#region Singleton
public UsableItem SelectedItem => selectedItem;
public static PlayerController instance;
private static PlayerController instance;
public int startMoney = 100;
private void Awake() {
if(instance != null) {
Debug.LogWarning("More than one instance of PlayerController found");
}
public static PlayerController getInstance() {
return instance;
}
// Start is called before the first frame update
void Start()
{
inventory ??= new Dictionary<Item, int>();
money = startMoney;
instance = this;
}
// Update is called once per frame
void Update()
{
#endregion
private Inventory _inventory;
private int money;
private UsableItem selectedItem;
public int startMoney = 100;
// Start is called before the first frame update
void Start() {
money = startMoney;
_inventory = Inventory.instance;
}
public void setSelectedItem(UsableItem item) {
if (inventory.ContainsKey(item)) {
// Update is called once per frame
void Update() { }
public void SetSelectedItem(UsableItem item) {
if(_inventory.items.ContainsKey(item)) {
selectedItem = item;
Cursor.SetCursor(item.defaultSprite.texture, Vector2.zero, CursorMode.Auto);
Cursor.SetCursor(item.selectedSprite.texture, Vector2.zero, CursorMode.Auto);
} else {
Debug.Log("An item requested to select isn't in the inventory" + item);
Debug.Log("An item requested to select isn't in the inventory" + item);
}
}
}
public UsableItem GetSelectedItem() {
return selectedItem;
}
}

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 7e19228f49932534e8af0218c51e5c63
guid: b18feac5270242d4a85c78ce72972d56
MonoImporter:
externalObjects: {}
serializedVersion: 2

View file

@ -27,16 +27,27 @@ public class TileBehaviour : MonoBehaviour
{
Debug.Log("Clicked");
// SelectedItem always null for now
//BaseTile temp = tile.Clicked(PlayerController.getInstance().SelectedItem);
//if (temp != null)
//{
// SetTile(temp);
//}
UsableItem usable = PlayerController.instance.GetSelectedItem();
BaseTile tileToSetTo = null;
if (usable.GetType() == typeof(TerraformingTool))
{
TerraformingTool terraformingTool = (TerraformingTool) usable;
Type tileTypeToSetTo = terraformingTool.TileType;
tileToSetTo = (BaseTile) Activator.CreateInstance(tileTypeToSetTo);
}
else
{
tile.Clicked(usable);
}
if (tileToSetTo != null)
{
SetTile(tileToSetTo);
}
}
void SetTile(BaseTile tileToSet)
{
Debug.Log("Set tile to " + tileToSet.ToString());
tile = tileToSet;
GetComponent<SpriteRenderer>().color = tile.getColor; // TODO: Change to Sprite
}

View file

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: aa6ceecfb09ac614997702b2caf66e33
guid: 3fd8bc1d313319d4f89f11548ccb1b6a
MonoImporter:
externalObjects: {}
serializedVersion: 2

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5e750377f5419b7409015c1dac98c88e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,5 +1,5 @@
using System.Collections;
using System.Collections.Generic;
using System;
using Items.TerraformingTools;
using UnityEngine;

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2619a266d1f1c0c468e81e5bfda1cd78
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5b78d95148d53bd4aa70e3d0d595ab93
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -14,10 +14,10 @@ namespace Tiles
/// </summary>
/// <param name="usable">the UsableItem that the Tile was clicked on with</param>
/// <returns>a subclass of BaseTile if the Tile has to change, null if it stays the same type</returns>
new public BaseTile Clicked(UsableItem usable) {
public new BaseTile Clicked(UsableItem usable) {
base.Clicked(usable);
BaseTile rv = null;
if (usable.GetType() == typeof(Items.Hoe))
if (usable.displayName == "Hoe")
{
rv = new FarmlandTile();
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: af8926946929c0644a4fbbe9d92b2729
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e1921bfec5aa63e44a32c0492c021809
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -2,26 +2,20 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UsableItem : Item, IUsable
{
[CreateAssetMenu(fileName = "New UsableItem", menuName = "Inventory/UsableItem")]
public class UsableItem : Item, IUsable {
// Start is called before the first frame update
void Start()
{
void Start() {
}
// Update is called once per frame
void Update()
{
void Update() {
}
public UsableItem(string displayName, string description, int id) : base(displayName, description, id)
{
}
public void select()
{
PlayerController.getInstance().setSelectedItem(this);
}
public UsableItem(string displayName, string description, int id) : base(displayName, description, id) {
}
public void select() {
PlayerController.instance.SetSelectedItem(this);
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 761f645f009328845bc7851753024e92
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: