improved Tiles, added Split Sprites

This commit is contained in:
j-weissen 2022-06-03 08:19:02 +02:00
parent d28a1947eb
commit 71fc280d2e
9 changed files with 72 additions and 32 deletions

View file

@ -1,13 +1,9 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Items.TerraformingTools;
using Tiles;
using UnityEngine;
public class TileBehaviour : MonoBehaviour
{
private BaseTile tile;
private BaseTile _tile;
// Start is called before the first frame update
void Start()
@ -15,7 +11,7 @@ public class TileBehaviour : MonoBehaviour
Debug.Log("Created");
SetTile(new GrassTile());
HouseController.NewDayEvent.AddListener(tile.DayLightStep);
HouseController.NewDayEvent.AddListener(_tile.DayLightStep);
}
// Update is called once per frame
@ -27,20 +23,17 @@ public class TileBehaviour : MonoBehaviour
void OnMouseDown()
{
Debug.Log("Clicked");
UsableItem usable = PlayerController.instance.GetSelectedItem();
UsableItem usable = null;
BaseTile tileToSetTo = null;
if (usable.GetType() == typeof(TerraformingTool))
if (PlayerController.instance.GetSelectedItem() != null)
{
TerraformingTool terraformingTool = (TerraformingTool) usable;
Type tileTypeToSetTo = terraformingTool.TileType;
tileToSetTo = (BaseTile) Activator.CreateInstance(tileTypeToSetTo);
}
else
{
tileToSetTo = tile.Clicked(usable);
Debug.Log("AMOGUS " + tileToSetTo.ToString());
usable = PlayerController.instance.GetSelectedItem();
}
tileToSetTo = _tile.Clicked(usable);
if (tileToSetTo != null)
{
SetTile(tileToSetTo);
@ -50,7 +43,8 @@ public class TileBehaviour : MonoBehaviour
void SetTile(BaseTile tileToSet)
{
Debug.Log("Set tile to " + tileToSet.ToString());
tile = tileToSet;
GetComponent<SpriteRenderer>().color = tile.getColor; // TODO: Change to Sprite
_tile = tileToSet;
Debug.Log(_tile.Sprite);
GetComponent<SpriteRenderer>().sprite = _tile.Sprite; // TODO: Change to Sprite
}
}

View file

@ -0,0 +1,12 @@
using System;
using UnityEngine;
namespace DefaultNamespace
{
public class TileSpriteContainer : MonoBehaviour
{
public static Sprite GrassTileSprite;
public static Sprite FarmlandTileSprite;
public static Sprite WheatSprite;
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ae14b865b73e45c5b15efb9484f9cae2
timeCreated: 1654172944

View file

@ -26,7 +26,7 @@ namespace Tiles
public void DayLightStep()
{
Debug.Log("I evolve");
}
public virtual BaseTile Clicked(UsableItem usable)
@ -34,5 +34,11 @@ namespace Tiles
Debug.Log(usable.ToString() + " used on " + this.ToString());
return null;
}
/*
static protected Sprite GenerateSpriteFromFile()
{
}
*/
}
}

View file

@ -1,4 +1,5 @@
using UnityEngine;
using DefaultNamespace;
using UnityEngine;
namespace Tiles
{
@ -7,7 +8,7 @@ namespace Tiles
private Crop _crop;
private bool _hydrated;
public FarmlandTile() : base(Color.black)
public FarmlandTile() : base(TileSpriteContainer.FarmlandTileSprite)
{
_crop = null;
_hydrated = false;

View file

@ -1,12 +1,13 @@
using UnityEngine;
using DefaultNamespace;
using UnityEngine;
namespace Tiles
{
public class GrassTile : BaseTile
{
public GrassTile() : base(Color.green)
public GrassTile() : base(TileSpriteContainer.GrassTileSprite)
{
}
/// <summary>
@ -15,11 +16,14 @@ namespace Tiles
/// <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>
public override BaseTile Clicked(UsableItem usable) {
base.Clicked(usable);
BaseTile rv = null;
if (usable.id == ItemContainer.Instance.GetItemIdByName("Hoe"))
if (usable != null)
{
rv = new FarmlandTile();
base.Clicked(usable);
if (usable.id == ItemContainer.Instance.GetItemIdByName(new string("Hoe")))
{
rv = new FarmlandTile();
}
}
return rv;
}

View file

@ -4,7 +4,7 @@ namespace Tiles
{
public class WaterTile : BaseTile
{
public WaterTile() : base(Color.blue)
public WaterTile() : base(null)
{
}