Refactored to ActionInvoker.cs
This commit is contained in:
parent
c06d161006
commit
afaddd940c
11 changed files with 189 additions and 214 deletions
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using DefaultNamespace;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Tiles {
|
||||
|
|
@ -7,20 +8,13 @@ namespace Tiles {
|
|||
private Sprite _sprite;
|
||||
public Sprite Sprite => _sprite;
|
||||
|
||||
protected GameObject _gameObject;
|
||||
|
||||
protected BaseTile(String pathToImageFile, GameObject gameObject) {
|
||||
_gameObject = gameObject;
|
||||
protected BaseTile(String pathToImageFile) {
|
||||
_sprite = GenerateSpriteFromFile(pathToImageFile);
|
||||
HouseController.NewDayEvent.AddListener(DayLightStep);
|
||||
}
|
||||
|
||||
public virtual void DayLightStep() { }
|
||||
|
||||
public virtual BaseTile Clicked(UsableItem usable) {
|
||||
return null;
|
||||
}
|
||||
|
||||
static public Sprite GenerateSpriteFromFile(String pathToImageFile) {
|
||||
byte[] data = File.ReadAllBytes(pathToImageFile);
|
||||
Texture2D texture = new Texture2D(32, 32, TextureFormat.ARGB32, false);
|
||||
|
|
|
|||
|
|
@ -3,30 +3,11 @@
|
|||
namespace Tiles {
|
||||
public class FarmlandTile : BaseTile {
|
||||
private Crop _crop;
|
||||
|
||||
public FarmlandTile(GameObject gameObject) : base("Assets/Farming Asset Pack/Split Assets/farming_tileset_008.png",
|
||||
gameObject) {
|
||||
_crop = new Crop(gameObject.transform.GetChild(1).GetComponent<SpriteRenderer>(),
|
||||
gameObject.transform.GetChild(0).GetComponent<SpriteRenderer>());
|
||||
}
|
||||
|
||||
public override void DayLightStep() {
|
||||
_crop.DayLightStep();
|
||||
}
|
||||
|
||||
public override BaseTile Clicked(UsableItem usable) {
|
||||
BaseTile rv = null;
|
||||
if (usable != null) {
|
||||
base.Clicked(usable);
|
||||
_crop.Clicked(usable);
|
||||
|
||||
if (ItemContainer.Instance.GetItemIdByName("Shovel") == usable.ID) {
|
||||
rv = new GrassTile(_gameObject);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return rv;
|
||||
public Crop Crop => _crop;
|
||||
|
||||
public FarmlandTile() : base("Assets/Farming Asset Pack/Split Assets/farming_tileset_008.png") {
|
||||
_crop = new Crop();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -4,29 +4,9 @@ namespace Tiles
|
|||
{
|
||||
public class GrassTile : BaseTile
|
||||
{
|
||||
public GrassTile(GameObject gameObject) : base("Assets/Farming Asset Pack/Split Assets/farming_tileset_000.png", gameObject)
|
||||
public GrassTile() : base("Assets/Farming Asset Pack/Split Assets/farming_tileset_000.png")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// to be invoked when the Tile is clicked, handles the actions following on the click
|
||||
/// </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>
|
||||
public override BaseTile Clicked(UsableItem usable) {
|
||||
BaseTile rv = null;
|
||||
ItemContainer ic = ItemContainer.Instance;
|
||||
if (usable != null)
|
||||
{
|
||||
base.Clicked(usable);
|
||||
if (usable.ID == ic.GetItemIdByName("Hoe")) {
|
||||
rv = new FarmlandTile(_gameObject);
|
||||
} else if (usable.ID == ic.GetItemIdByName("Shovel")) {
|
||||
rv = new WaterTile(_gameObject);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3,27 +3,7 @@ using UnityEngine;
|
|||
|
||||
namespace Tiles {
|
||||
public class WaterTile : BaseTile {
|
||||
public WaterTile(GameObject gameObject) : base("Assets/Farming Asset Pack/Split Assets/water_sprite_00.png", gameObject) {
|
||||
}
|
||||
|
||||
public override BaseTile Clicked(UsableItem usable) {
|
||||
base.Clicked(usable);
|
||||
BaseTile rv = null;
|
||||
|
||||
ItemContainer ic = ItemContainer.Instance;
|
||||
|
||||
if (usable.ID == ic.GetItemIdByName("Fishing Rod")) {
|
||||
FishingController fc = FishingController.instance;
|
||||
if (!fc.Fishing) {
|
||||
fc.StartFishing();
|
||||
} else {
|
||||
fc.TryCatch();
|
||||
}
|
||||
} else if (usable.ID == ic.GetItemIdByName("Shovel")) {
|
||||
rv = new GrassTile(_gameObject);
|
||||
}
|
||||
|
||||
return rv;
|
||||
public WaterTile() : base("Assets/Farming Asset Pack/Split Assets/water_sprite_00.png") {
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue