Merge branch 'jweissen' into develop
# Conflicts: # Assets/Scripts/Actions/ActionManager.cs
This commit is contained in:
commit
d3a06effc5
10 changed files with 98 additions and 19 deletions
|
|
@ -3,6 +3,10 @@ using Assets.Scripts.Actions;
|
|||
using UnityEngine;
|
||||
|
||||
namespace Actions {
|
||||
/// <summary>
|
||||
/// AcrionManagaer managing Actions.
|
||||
/// ActionHandler implement either NextDayActionHandler or ClickActionHandler and have to be added to the matching list in the instatiationmethod
|
||||
/// </summary>
|
||||
public class ActionManager {
|
||||
#region Singleton
|
||||
private static ActionManager _instance;
|
||||
|
|
@ -23,17 +27,22 @@ namespace Actions {
|
|||
private ActionManager() {
|
||||
_clickActionHandlers = new List<ClickActionHandler>();
|
||||
_nextDayActionHandlers = new List<NextDayActionHandler>();
|
||||
InstantiateClickActionHandlers();
|
||||
InstantiateNextDayActionHandlers();
|
||||
instantiateClickActionHandlers();
|
||||
instantiateNextDayActionHandlers();
|
||||
}
|
||||
|
||||
private void InstantiateNextDayActionHandlers() {
|
||||
/// <summary>
|
||||
/// NextDayActionHandlers to be instatiated and added to the corresponding List
|
||||
/// </summary>
|
||||
private void instantiateNextDayActionHandlers() {
|
||||
_nextDayActionHandlers.Add(new FarmlandTileNextDayActionHandler());
|
||||
|
||||
_nextDayActionHandlers.Add(new ChickenAnimalNextDayActionHandler());
|
||||
}
|
||||
|
||||
private void InstantiateClickActionHandlers() {
|
||||
|
||||
/// <summary>
|
||||
/// ClickActionHandlers to be instatiated and added to the corresponding List
|
||||
/// </summary>
|
||||
private void instantiateClickActionHandlers() {
|
||||
_clickActionHandlers.Add(new GrassTileClickHoeActionHandler());
|
||||
_clickActionHandlers.Add(new GrassTileClickShovelActionHandler());
|
||||
_clickActionHandlers.Add(new GrassTileClickFenceActionHandler());
|
||||
|
|
@ -49,19 +58,33 @@ namespace Actions {
|
|||
_clickActionHandlers.Add(new CowAnimalClickActionHandler());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to Invoke ClickActions, all ClickActionHandlers in ClickActionHandlers list are iterated through,
|
||||
/// only one will be invoked per method call
|
||||
/// </summary>
|
||||
/// <param name="gameObject">The affected gameObject</param>
|
||||
/// <param name="usableItem">the current tool</param>
|
||||
public void ClickAction(GameObject gameObject, UsableItem usableItem) {
|
||||
foreach (ClickActionHandler actionHandler in _clickActionHandlers) {
|
||||
if(actionHandler.Matches(gameObject, usableItem)) {
|
||||
actionHandler.InvokeAction(gameObject);
|
||||
break; // Ja Herr Professor, Sie sehen richtig. Voller Stolz verwende ich ein break.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to Invoke ClickActions, all ClickActionHandlers in ClickActionHandlers list are iterated through,
|
||||
/// only one will be invoked per method call
|
||||
/// </summary>
|
||||
/// <param name="gameObject">The affected gameObject</param>
|
||||
/// <param name="usableItem">the current tool</param>
|
||||
public void NextDayAction(GameObject gameObject) {
|
||||
Debug.Log("nextday action");
|
||||
foreach (NextDayActionHandler actionHandler in _nextDayActionHandlers) {
|
||||
if(actionHandler.Matches(gameObject)) {
|
||||
actionHandler.InvokeAction(gameObject);
|
||||
break; // Gleich noch einmal. Und ich kann nachts immer noch zufrieden schlafen.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ using System.Transactions;
|
|||
using UnityEngine;
|
||||
|
||||
namespace Actions {
|
||||
/// <summary>
|
||||
/// Implementing classes handle ClickActions
|
||||
/// </summary>
|
||||
public interface ClickActionHandler {
|
||||
public void InvokeAction(GameObject gameObject);
|
||||
public bool Matches(GameObject gameObject, UsableItem usableItem);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using Tiles;
|
||||
using UnityEngine;
|
||||
|
||||
/// Definitions of ClickActionHandlers here
|
||||
namespace Assets.Scripts.Actions {
|
||||
public abstract class AbstractTileClickActionHandler : ClickActionHandler {
|
||||
protected BaseTile _tile;
|
||||
|
|
@ -185,7 +186,7 @@ namespace Assets.Scripts.Actions {
|
|||
public override void InvokeAction(GameObject gameObject) {
|
||||
if(crop.FullyGrown) {
|
||||
Inventory.instance.AddElement(ItemContainer.Instance.GetItemByName("Wheat Seeds"),
|
||||
(int)(Random.Range(1, 300)));
|
||||
(int)(Random.Range(1, 3)));
|
||||
Inventory.instance.AddElement(ItemContainer.Instance.GetItemByName("Wheat"), 1);
|
||||
crop.ResetPlant();
|
||||
updateFarmlandSprites(gameObject);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
using UnityEngine;
|
||||
|
||||
namespace Actions {
|
||||
/// <summary>
|
||||
/// Implementing classes handle nextDayAction
|
||||
/// </summary>
|
||||
public interface NextDayActionHandler {
|
||||
public void InvokeAction(GameObject gameObject);
|
||||
public bool Matches(GameObject gameObject);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
using Tiles;
|
||||
using UnityEngine;
|
||||
|
||||
/// Definitions of NextDayActionHandlers here
|
||||
namespace Actions {
|
||||
public abstract class AbstractTileNextDayActionHandler : NextDayActionHandler {
|
||||
protected BaseTile _tile;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue